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:
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.
class Point: def __init__(self, x, y, z=0.0): self.x = x self.y = y self.z = z
@dataclass class Point: x: float y: float z: float = 0.0
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()
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.
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.
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.