-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
stubgen: fixed handling of Protocol and added testcase #12129
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
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.
Thank you!
[case testProtocol_semanal] | ||
from typing import Protocol | ||
|
||
class P(Protocol): |
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.
Let's also add a generic Protocol[T]
class here 🤔
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.
You mean like this?
T = TypeVar('T')
class PT(Protocol[T]):
def f(self, x: T) -> T:
...
That results in:
T = TypeVar('T')
class PT(Protocol):
def f(self, x: T) -> T: ...
So I guess that needs to be handled explicitly in my implementation?
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.
Yes 🙂
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.
Done ✅
This comment has been minimized.
This comment has been minimized.
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.
Thank you! 👍
@srittau do you want to double check this? I've seen multiple your PRs to |
Any updates on this? :) |
If you fix the merge conflict I can review it and hopefully merge it. |
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Description
This PR fixes #12072 by correctly handling
Protocol
definitions. Previously, theProtocol
base class was removed when generating type stubs which causes problems with other packages that want to use type definition (because they see it as a regular class, not as aProtocol
).Test Plan
Added a testcase to the stubgen testset.