-
Notifications
You must be signed in to change notification settings - Fork 134
Description
Require Python version >=3.7.
See #1326 for a follow-up.
This is just to start some discussion, specifically what we want to drop. Surely <=Python2, but probably also <Python3.x for some x (e.g. 7). We could also say it might make more sense maybe in 6 months or so. This issue implies then to clean up the code accordingly.
The purpose is to clean up some code where Python 2 vs 3 needs extra separate logic, and also where we could make use of newer syntax. I want to collect some of these arguments (and their needed Python version) here.
Sometimes some things can also be fixed by from __future__ import ..., which is ok (but also not for all features).
Then there might be practical issues on some systems we use, in some conditions, which just doesn't provide newer Python versions, or would make it very inconvenient. E.g. for some time, RASR was linked to Python 2 by default, and also did not support Python 3. I think that is fixed now? Then Ubuntu 16 has some older Python, but maybe we can just agree to use anyway a newer Python version?
Now some arguments, or relevant features:
-
Type annotations. Like
def func(a: str) -> Dataor whatever. I think since Python 3.5.
However, there is the issue with forward declaration. E.g.:class Data: def bla(self) -> Data: ...This requires >=Python 3.10 I think.
Or it requiresfrom __future__ import annotationssince Python 3.7 (doc).
The earlier workaround was to use a string as annotation instead, i.e.def bla(...) -> "Data"(referred to as forward declaration). But I think this support was always somewhat limited (e.g. not sure if PyCharm will correctly pick this up), and will also likely go away at some point, or being deprecated, so I would argue to avoid this (because otherwise we will have a similar discussion soon again). But this means we need at least Python 3.7.
(There are ongoing discussions around this. E.g. see pydantic #2678 (HN), PEP 649 (python-dev discussion).)
I would also argue, in any case, type inference must work in PyCharm. If that doesn't work, we should not use it.
In any case, I think these type annotations are actually one of the major reasons for us to drop older support. -
dict.items()ordict.keys()returns a non-deterministic order in earlier Python versions.
Because you usually want to have this deterministic, you would usesorted(dict.items()).
Since Python 3.6, this is now deterministic (using the insertion order) (see here).
So, from Python 3.6 on, you can drop thesorted, or explicit usage ofOrderedDict.
We should still be a bit careful here though. Some issues:- When the user now runs such code with Python 3.5, there will not be any error. But it might produce strange very hard to debug issues. We always should avoid hard-to-debug issues at all cost. So If we adopt this, we should also have some
assert py_version >= (3,6)somewhere. - I can't imagine such a situation now, but maybe there could be cases where we must match the old behavior using
sorted, i.e. sorted by alphabet, or maybe to stay compatible with some old data? - I can't imagine such a situation now, but maybe there could be other cases where this would be bad? E.g. you remove some key, then add some key. Then
list(dict.keys())would be different (whereassortedwould always be the same). Not sure if this could cause any issues.
- When the user now runs such code with Python 3.5, there will not be any error. But it might produce strange very hard to debug issues. We always should avoid hard-to-debug issues at all cost. So If we adopt this, we should also have some
-
f-strings, since Python 3.6.
-
Ubuntu 16.04 (so far still the standard on many of our systems) comes with Python 3.5.
Ubuntu 20.04 comes with Python 3.8.
Ubuntu 22.04 comes with Python 3.10. -
typing.Protocolrequires Python >=3.8. -
Slash (
/) in function argument list to mark positional-only arguments (doc) requires Python >=3.8.