-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Add typing.get_orig_bases and typing.get_orig_class #101688
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
Comments
I'd be happy to accept this enhancement to |
Aren't |
They aren't documented anywhere AFAIK, that would also be a decent solution to the problem |
No — type checkers emit errors if you try to access them, as they're not included in the stub. As discussed in python/typeshed#7811 and python/typeshed#7827, adding them to the stub would in fact be impossible. |
The main issue with defining those dunders in a stub file is they are defined for generic types but not other types. And Generic class is very special cased by type checkers/runtime that you can’t add it to the stub definition for Generic without risking type checker either ignoring it or causing buggy behavior. Would be nice to have a public recommended way to access these for runtime type reflection. Simple implementation seems fine to me. |
Co-authored-by: Alex Waygood <[email protected]>
#101827 has now been merged: Remaining issues to discuss(1) Should we add a "getter function" for the
|
So for now I think documenting Currently in a module I maintain there is an |
Okay, great. I'll close this as completed for now, in that case, as I think adding a new slot for all Python objects will require a lot more discussion, so deserves to be treated separately :) |
Feature or enhancement
typing has had
type.__orig_bases__
andtype.__orig_class__
for quite some time now, there is no stable API to access these attributes.Pitch
I would like to propose adding
typing.get_orig_bases
as something likeand
typing.get_orig_class
(side note, it might be possible to fully type
get_orig_class
ittypes.GenericAlias
was generic over the__origin__
and__args__
i.e.Foo[int] == GenericAlias[Foo, int]
)Linked PRs
The text was updated successfully, but these errors were encountered: