Skip to content
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

Merged
merged 2 commits into from Jun 12, 2021
Merged

Use a TypeVar for the return types of TarFile classmethods. #5602

merged 2 commits into from Jun 12, 2021

Conversation

domdfcoding
Copy link
Contributor

@domdfcoding domdfcoding commented Jun 9, 2021

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 returning TarFile, and never its subclasses.

@@ -129,7 +131,7 @@ class TarFile:
def __iter__(self) -> Iterator[TarInfo]: ...
@classmethod
def open(
cls,
cls: Type[_TF],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: type[_TF]

Copy link
Contributor Author

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

Copy link
Collaborator

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. 😕

Copy link
Contributor Author

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.

@github-actions

This comment has been minimized.

2 similar comments
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 9, 2021

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@domdfcoding domdfcoding marked this pull request as ready for review June 9, 2021 18:11
@Akuli Akuli merged commit 48a3469 into python:master Jun 12, 2021
@Akuli
Copy link
Collaborator

Akuli commented Jun 12, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants