Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Making the is_new_type check more robust then just checking __superty…
…pe__ existance (#78) Before this commit everthing which has an attribute called __supertype__ will be accepted as ‚NewType‘ which is wrong. Now it is additionally checked that the __qualname__ must be 'NewType.<locals>.new_type', and that the module where the symbol is defined has the name 'typing'. A user could still fullfill all those conditions in a custom class, but the probability bacame quite low. Furtheremore support for python 3.10¹, where NewType is not a function any more but a class, is added. This check is implemented by isincance() and should work always correctly. The symbol ‚NewType‘ (i.e. not the call of it) is now also cosidered as a NewType by doing a `tp is NewType` check. This is in alignment with other functions, such as `is_classvar()` which does an `tp is ClassVar` or `is_union_type()` which do a `tp is Union`. ¹ To be specific, the first RC of python 3.10, i.e. in all bata versions, NewType is still a function. Please also note that the class NewType in python 3.10.0rc has a different __qualname__ then the function NewType before.
- Loading branch information
Showing
3 changed files
with
70 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
flake8; python_version >= '3.6' | ||
flake8-bugbear; python_version >= '3.6' | ||
pytest>=2.8; python_version >= '3.3' | ||
importlib-metadata<3.0; python_version < '3.6' | ||
packaging<21.0; python_version < '3.6' | ||
pytest~=4.6; python_version < '3.6' | ||
pytest>=4.6; python_version >= '3.6' | ||
typing >= 3.7.4; python_version < '3.5' | ||
mypy_extensions >= 0.3.0 | ||
typing_extensions >= 3.7.4 | ||
typing_extensions >= 3.7.4; python_version >= '3.6' | ||
typing_extensions >= 3.7.4, < 3.10; python_version < '3.6' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters