Python 3.7: Gains that Eliminate Pains

Python 3.7: Gains that Eliminate Pains

In development for 10 months, Python 3.7 has just been released. For long time Python users, it’s a welcome addition, providing many quality of life enhancements that will make writing Python applications quicker and easier. For newcomers, Python 3.7’s optimizations and polish go a long way to justifying the fact that Python is the most popular programming language on the planet right now.
Some of the key enhancements include:
 

Data Classes

dataclass helps to simplify the creation of classes, while making them more powerful. All you need to do is declare some fields or attributes with initial values, and the system will automatically create them for you, along with a set of comparison functions (like equals, less than, greater than, etc) that would previously need to be manually implemented.
Previously:

class Point:
    def __init__(self, x, y, z=0.0):
        self.x = x
        self.y = y
        self.z = z

Python 3.7:

@dataclass
class Point:
    x: float
    y: float
    z: float = 0.0

 

Debugging

breakpoint() has been introduced as a global function just like print(), allowing you to set a breakpoint so you can easily drop into the debugger and step through your program.
Previously to run the Python debugging library (pdb) you would type:

Import pdb; pdb.set_trace()

Python 3.7:

breakpoint()

So now there’s no need to import pdb, but breakpoint is also more flexible, allowing you to take advantage of any debugging library – and even switch between them – without the need to rewrite your debugging code.
 

Polish

Two examples of the kind of polish that 3.7 brings to the table are the facts that now order of dictionaries is guaranteed, and the typing system has been stabilized.
With ordering, previously when you called an index of values, the system would return the values in random order, forcing you to add code to reorder them properly. Now items in dictionaries are iterated over in the same order they were inserted.
Similarly, type hinting and annotations have been in constant development since the first release of Python 3, but 3.7 adds better performance through core support. For example, previously using type hints was painful due to the fact that it loaded the extremely slow type module. Now hints are part of the Python core and won’t slow you down.
 

Speed

Lastly, Python has always been stigmatized as a slow running language. Python 3.7 takes giant strides toward optimizing for speed, with significant improvements across the board, such as:

  • Importing a typing module is 7x faster
  • Calling methods is 20% faster
  • Startup time is 10-30% faster

Try forking ActivePython 3.7 on the Beta version of the ActiveState Platform. Create a free account.

Create a Free Account

Recent Posts

Tech Debt Best Practices: Minimizing Opportunity Cost & Security Risk

Tech debt is an unavoidable consequence of modern application development, leading to security and performance concerns as older open-source codebases become more vulnerable and outdated. Unfortunately, the opportunity cost of an upgrade often means organizations are left to manage growing risk the best they can. But it doesn’t have to be this way.

Read More
Scroll to Top