Skip to content

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

Merged
Akuli merged 2 commits into
python:masterfrom
domdfcoding:tarfile-typevar
Jun 12, 2021
Merged

Use a TypeVar for the return types of TarFile classmethods.#5602
Akuli merged 2 commits into
python:masterfrom
domdfcoding:tarfile-typevar

Conversation

@domdfcoding
Copy link
Copy Markdown
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.

Comment thread stdlib/tarfile.pyi
@classmethod
def open(
cls,
cls: Type[_TF],
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

3 participants