-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PEP 585 breaks inspect.isclass #88459
Comments
PEP-585 has the side-effect of making It also implies that By the way, there is the awkward thing of having |
The reason for this is that types.GenericAlias.getattribute delegates to the alias's origin (in the To fix this, we could make
This is not true; it is the same for e.g. |
Since these are new forms (list[int] previously was an error), does it actually matter? Especially since these are primarily used in annotations. @joseph Perez, is there a specific library or pattern that is broken by this? FWIW I did think rather carefully about which attributes to delegate or not, and delegating __class__ was intentional. |
@jelle Zijlstra Thank you for the explanation.
I agree that a "fix" could have unexpected side-effect, my issue comes quite late indeed. By the way, Python typing is so much unstable (every version breaks the previous one), it's very complicated to write code that support multiple versions, so whatever the typing internal implementation, we must adapt.
I have chosen
Because
I don't have the context of the decision, so I can quite understand that delegating But as I've written, I've already so many wrappers to maintain compatibility between Python versions of typing that I can write a new one to handle this particularity of PEP-585. So this issue is not critical to me. |
@jelle thanks for nosy-ing me too and the thorough investigation. Thanks for taking the time to raise this inconvenience on the bug tracker.
Compared to some of the more mature modules in Python, I have to agree that typing.py is mildly unstable. However, you're not supposed to be using/importing from the internal constructs - those have no guarantee of stability. If you feel some common use cases aren't met by the current introspection helpers, please please please create a new issue for that and we'll consider it. How we use typing may differ from how you use it and so there's a lot we don't see. User bug reports and feedback have helped to surface such issues and improved typing for everyone :).
This is an implementation detail. Most typing PEPs don't usually specify the runtime behavior in detail because most of them focus on static analysis. The implementation is usually up to the contributor's judgement. FWIW, to accommodate the new 3.9 GenericAlias, typing.py just added additional checks for |
Instead of introspecting types, use this library: |
Btw this reminds me I should make a PyPI release of typing_inspect (last release was May 2020), hopefully will make a release on this weekend. |
Uploaded typing_inspect 0.7.0 to PyPI (it should work with Python 3.9 hopefully) |
I think this can be closed after #93754 (though I don't see it in the 3.11 changelog): Python 3.9.14 (main, Nov 28 2022, 13:10:52)
[Clang 13.1.6 (clang-1316.0.21.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from types import GenericAlias
>>> isinstance(list[int], type)
True
>>> isinstance(list[int], GenericAlias)
True Python 3.11.0 (main, Nov 28 2022, 13:26:47)
[Clang 13.1.6 (clang-1316.0.21.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from types import GenericAlias
>>> isinstance(list[int], type)
False
>>> isinstance(list[int], GenericAlias)
True Anyone relying on |
In python 3.9 and 3.10, the `isinstance(list[...], type)` returns True, but it's not a valid class for use in issubclass
…s. (#2893) * When a Var points to a model, prefer access to model fields. When a Var points to a model, and fields of the model share the same name as Var operations, access to the model fields is now preferred to avoid having Var operation names shadow model fields. Since most Var operations do not actually work against Models, this does not really block any functionality. * Special case for ComputedVar needing to internally access fget Since fget is a "slot" on property, normal __getattribute__ access cannot find it. * Workaround python/cpython#88459 In python 3.9 and 3.10, the `isinstance(list[...], type)` returns True, but it's not a valid class for use in issubclass
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: