mcstatus
mcstatus copied to clipboard
Pep 585
This PR makes our codebase compliant with PEP-585. This PEP made commonly used base classes (such as those in collections.abc) or the built-in classes (list, dict, tuple, ...) generic. This means usage of generic alternatives in the typing module is no longer recommended, and is in fact deprecated.
Since this PEP only applies to python 3.9+, we can't use these generics on runtime, because our project is 3.7+, however with __future__.annotations compiler setting, runtime errors won't be produced, and type-checkers can already understand this new syntax.
To enforce these changes, flake8-585 (for 3.9+) was added as a dev dependency, and to ensure that when using these changes, we stay 3.7 compatible, this also adds flake8-future-annotations, which will produce a flake8 error when trying to use these generics without the __future__.annotations import.
Maybe than also use | instead of Union?
Maybe than also use
|instead ofUnion?
We could, however this new union syntax was not introduced as a part of PEP 585, it was only added in PEP 604 for python 3.10 (though it does work with __future__.annotations) and it didn't deprecate the use of typing.Union, it just provided an alternative.
This is different from the introduction of generics into the standard library classes directly, as that did in fact meant deprecation of the typing alternatives, and even though there is no removal date on these features yet, I'd rather avoid using deprecated utilities, which is what this PR is addressing.
I'm open to changing our union syntax to this new form though, not sure if this PR is a place for that though.