Python 3.7 released
python.org
python.org
* Data classes (https://docs.python.org/3.7/library/dataclasses.html)
* New breakpoint() builtin (https://docs.python.org/3.7/library/functions.html#breakpoin...)
* Dictionaries preserve insertion order. (Implemented in 3.6, but now is part of the official spec.)
Another notable part of this release is type annotations:
I've been looking forward to trying data classes, should be nice to avoid unnecessary code.
Have you noticed any decreases in performance using core typing?
Will data classes save a ton of memory since you’re specifying the types?
These are called "type hints" because they are not enforced by the Python runtime.
"Data Classes are intentionally less powerful than attrs. There is a long list of features that were sacrificed for the sake of simplicity and while the most obvious ones are validators, converters, and __slots__, it permeates throughout all APIs."
If the simple program depends only on core Python, then they don't also have to say "oh, and also install ...".
That is a terrible decision. Call me a heretic.
Yes, I know it's a side effect of bringing in the bitmap index version from PyPy. Yes, I am aware that collections.OrderedDict is now an alias to internal dictionary type. And yes, I do understand that randomising the key traversal order could incur a performance penalty.
But a dictionary where keys come out in anything other than unspecified order is a subtle trap just waiting to blow up. I personally prefer golang's map behaviour - keys are always in unspecified order, and the order is different even between calls.
[#]: Well, usually it doesn’t matter, and when it does, you have other ways to achieve similar results.
There's also the new module-level "__getattr__(name):" function[1] which behaves as the class method does: catching undefined variable names and providing a way to easily, for example, generate objects dynamically, handle deprecated variables, and lazily load submodules. I have a feeling it's going to be (ab)used to do some really great meta-programming.
[0] https://docs.python.org/3.7/library/importlib.html#module-im... [1] https://www.python.org/dev/peps/pep-0562/
So I'm very glad to see data classes bringing this to the core language.
There are some exceptions. Like I really don't want form building to be in the standard library, and I don't want to write it myself.
It is nice when your package manager only takes a short manage to fetch and build though, and you can have more confidence that any mistakes will be your own (under your control) rather than someone else's.
breakpoint() is certainly more memorable than the current incantation.
If I tell them you just call breakpoint() they might be willing to try it out.
Oops, never mind: "It is not possible to create truly immutable Python objects. However, by passing frozen=True to the dataclass() decorator you can emulate immutability. In that case, dataclasses will add __setattr__() and __delattr__() methods to the class. These methods will raise a FrozenInstanceError when invoked."
Minor release may break code, though it should be rare. Python 3.7 reserves 'async' and 'await' as keywords so assignments like "async = 3", which worked in 3.6, will now fail.
Python has a deprecation warning system which can detect cases like this, but it must be enabled:
% python -Wall
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 05:52:31)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> async = 3
<stdin>:1: DeprecationWarning: 'async' and 'await' will become
reserved keywords in Python 3.7I don't see any pull requests yet.
3.5->3.6 python was updated in the same package, so I guess python 3.7 will replace python 3.6 too. You will get it after you run brew upgrade.
`brew install pyenv; pyenv install 3.7`
Almost correct. It requires either that the version is already on your system, or it can find an installation of pyenv configured in the standard way (and, on some quirky situations with OSX, configured but pristine--without any pre-existing Python builds). In the latter case, it'll ask you if you want it to automatically build and cache/install a Python of the specified version.
And yes, the names all suck.
Looks like it's waiting for tests to pass at present.