-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Use a TypeVar for the return types of TarFile classmethods. #5602
Conversation
@@ -129,7 +131,7 @@ class TarFile: | |||
def __iter__(self) -> Iterator[TarInfo]: ... | |||
@classmethod | |||
def open( | |||
cls, | |||
cls: Type[_TF], |
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.
Nit: type[_TF]
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.
mypy doesn't like type[_TF]
because of python/mypy#10303
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.
Sorry about that. I actually tested it before this comment, but it seems that it worked in my small test for some reason, but not 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.
I have switched back to Type[_TF]
for now.
This comment has been minimized.
This comment has been minimized.
2 similar comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Nit for future reference: We generally prefer adding more commits as opposed to force-pushing. When we merge the PR, it's combined into a single commit anyway. |
The implementations of the classmethods (and
__enter__
) return the same type as the class, including for subclasses. However, the current stubs show the methods unconditionally returningTarFile
, and never its subclasses.