What’s new in 3.7?
The latest major release of the language introduces many cool new features. In case you are bored of writingself.attribute = attribute in your __init__ methods all the time, you might like Data classes, documented in PEP 557. Class definition and creation of the object, storing a bunch of data can be really easy now:
from dataclasses import dataclass
@dataclassclass C:
i: int
j: int = None
database: InitVar[DatabaseType] = None def post_init(self, database):
if self.j is None and database is not None:
self.j = database.lookup(‘j’) c = C(10, database=my_database) Note the types are just documentation. They aren’t examined at runtime. Another visible change is the new
breakpoint() built-in function, which makes debugging your code smoother. It can be put anywhere in the code instead of import pdb; pdb.set_trace() line. The main benefit of breakpoint() is that it is configurable via the PYTHONBREAKPOINT environment variable. You can simply ignore all the breakpoint() calls in your code by setting its value to zero:
$ PYTHONBREAKPOINT=0 python3.7 script.py
or switch to use a debugger of your choice instead of the default PDB:
$ PYTHONBREAKPOINT=pudb.set_trace python3.7 script.py
The asyncio standard library module has received many new features too. For example the new asyncio.run() function removes the burden of creating the event loop explicitly. Creating a trivial coroutine is now as simple as this:
PIP 18.0
The brand new pip 18.0 is coming to Platform.sh alongside new the Python release! Version number might be a bit surprising. We all remember using pip version 9 or 10 recently. Pip development team have switched to a Calendar based versioning scheme. This is not the only thing that changed. Support for packages specifying build system requirements inpyproject.toml file, aka PEP 518 was introduced in version 10 and improved in the latest release. Last two releases contains also a plenty of fixes, see the relase notes for more information.
Try it out!
Are you thrilled to try all these great features yourself? You can do so on Platform.sh! The only thing you have to do is to put following line into your.platform.app.yaml file:
type: “python:3.7”
Commit the changes, push your code and enjoy the flight!