|Python 3.7 Released
|Written by Mike James
|Friday, 29 June 2018
I've been using Python 3.7 for weeks so it was a shock to discover that it is a release candidate no more - it's officially the new Python 3.
The road from Python 2 to 3 has been a long and fairly gentle one. If you really couldn't move to Python 3 for one reason or another then you have been well served by the ongoing Python 2 development line. But now enough is enough. Python 3 is mature and this is proved by the welcome, but not major, changes and additions to Python 3.7. This is good because only bored programmers want a language that is developing so fast that the thrill is in trying to keep up. Yes, I suppose I am saying Python is getting old.
So what is new in 3.7?
The most important addition for the average programmer is the addition of data classes. Sometimes you just want to create a class so that it can be used to store data. In other languages you would call such an object a "struct" or a "record type". Java is about to get data classes and Kotlin already has them, for example. Python's data classes give you a decorator way of creating classes that are ready to work with data. You simply add @dataclass in front of a class definition and then list all the data fields you want to use. Each field is a variable name followed by a type annotation. The decorator converts this into a class definition with a suitable __init__ so you can correctly initialize the fields when you create an instance. You can also modify the way the fields are created using the field helper function. What is impressive is that this additional data type has been implemented using nothing but Python.
Talking of type annotations, 3.7 adds forward references and improves the speed of operation. I have mixed feelings about type annotations. They start out being useful, for example when you describe the signature of a function, but quickly become complex and difficult to get right. Not having to deal with generics and variance is one of the advantages of Python - adding them back in, even as an optional feature, isn't an obvious improvement.
Another big feature is the ability to work with attributes defined on modules. You can now use __getattr__ and __dir__ on modules. This logically makes modules look like "bigger" classes, which is more or less what they are.
A smaller feature, in the sense that ns is smaller than ms, is the increased precision of the timing package. You can now use functions in the time module to get nanosecond accuracy returned as an integer.
Now we get to the really small improvements:
Finally there are speedups - calling the standard library is faster; method calls are faster; and startup is faster.
Python 3.7 is out now and there are no good reasons not to use it and many of the new features work with 3.6.
or email your comment to: firstname.lastname@example.org
|Last Updated ( Wednesday, 10 October 2018 )