Hi all, yt 4.2 (current main branch) has officially dropped support for Python 3.7 While this is mainly done to reduce technical debt, it also means we can now start using Python 3.8+ syntax, so I wanted to highlight a couple things from the “What’s new in Python 3.8” page, to get everyone on the same page. FTR this isn’t me campaigning to modernise all the things, but it’s always nice to have access to a larger subset of what Python can do :) - Assignment expressions, aka “walrus operator” https://docs.python.org/3/whatsnew/3.8.html#assignment-expressions In some places, using `:=` makes for shorter code without sacrificing readability. I find it really shines when binding a variable that’s immediately going to be tested in an `if/else` block, for instance. - Positional-only parameters: https://docs.python.org/3/whatsnew/3.8.html#positional-only-parameters Though rarely useful, making arguments positional-only means we don’t have to commit to non-meaningful names forever (looking at you, `yt.load(fn=…)`) - “debug fstrings” https://docs.python.org/3/whatsnew/3.8.html#f-strings-support-for-self-docum... Python 3.8 makes fstrings even nicer and more useful ! - new features for the `typing` module https://docs.python.org/3/whatsnew/3.8.html#typing We now have easy access to `typing.Final` (declare that a variable should be considered constant and not be assigned to), and `typing.TypedDict`, which allows to mark dictionaries as having an exact set of keys with known types. These have no effect at runtime but are very useful in making sure the code is correct at type-check time with mypy (e.g, am I rebinding a varname that was suppposed to be constant ? Did I forget a key in my return dict, or does it have an unexpected type ?) Cheers ! Clément
participants (1)
-
Clément Robert