-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
typing: Add missing test case for Protocol inheritance #132597
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
Conversation
You could also test this one? >>> from typing import *
>>> T = TypeVar("T")
>>> class Foo(Protocol, Generic[T], object):
... x: T
...
>>> get_protocol_attrs(Foo)
frozenset({"x"}) |
Done, also added a PEP 695 one |
class NewGeneric[T](Protocol, object): | ||
z: T |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
although this one fails, interestingly:
class NewGeneric[T](Protocol[T], object):
z: T
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's general PEP 695 behavior, generic classes work by injecting Generic[T]
as the last base and if object
is already there, it fails.
>>> class X[T](object): pass
...
Traceback (most recent call last):
File "<python-input-2>", line 1, in <module>
class X[T](object): pass
File "<python-input-2>", line 1, in <generic parameters of X>
class X[T](object): pass
TypeError: Cannot create a consistent method resolution order (MRO) for bases object, Generic
Somewhat unfortunate but nobody has complained about it and the workaround is simple (just don't inherit from object
there).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yeah, I understand why it is the way it is and I'm not asking for it to be changed! Happy for it to remain an untested corner case
Thanks @JelleZijlstra for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13. |
(cherry picked from commit 72da4a4) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
GH-132603 is a backport of this pull request to the 3.13 branch. |
) (#132603) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
No description provided.