Fix incorrect keyword-only arguments in tarfile.open()#13814
Merged
srittau merged 2 commits intopython:mainfrom Apr 11, 2025
Merged
Fix incorrect keyword-only arguments in tarfile.open()#13814srittau merged 2 commits intopython:mainfrom
srittau merged 2 commits intopython:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
09ccf71 to
58ad5aa
Compare
This comment has been minimized.
This comment has been minimized.
723526b to
8efb781
Compare
This comment has been minimized.
This comment has been minimized.
Contributor
Author
|
Took me a while to wrap my head around the signature duplication, but I think this fixes the overly constrained pipe modes (from #13130) in the right spirit. |
Collaborator
|
Could you add a test case corresponding to the thing you'd like to pass type check to |
8efb781 to
0710b83
Compare
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: vision (https://github.com/pytorch/vision)
+ torchvision/datasets/utils.py:215: note: def open(cls, name: str | bytes | PathLike[str] | PathLike[bytes] | Buffer | None, mode: Literal['r|*', 'r|', 'r|gz', 'r|bz2', 'r|xz'], fileobj: _Fileobj | None = ..., bufsize: int = ..., *, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., dereference: bool | None = ..., ignore_zeros: bool | None = ..., encoding: str | None = ..., errors: str = ..., pax_headers: Mapping[str, str] | None = ..., debug: int | None = ..., errorlevel: int | None = ...) -> TarFile
+ torchvision/datasets/utils.py:215: note: def open(cls, name: str | bytes | PathLike[str] | PathLike[bytes] | Buffer | None, mode: Literal['w|', 'w|xz'], fileobj: _Fileobj | None = ..., bufsize: int = ..., *, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., dereference: bool | None = ..., ignore_zeros: bool | None = ..., encoding: str | None = ..., errors: str = ..., pax_headers: Mapping[str, str] | None = ..., debug: int | None = ..., errorlevel: int | None = ...) -> TarFile
+ torchvision/datasets/utils.py:215: note: def open(cls, name: str | bytes | PathLike[str] | PathLike[bytes] | Buffer | None, mode: Literal['w|gz', 'w|bz2'], fileobj: _Fileobj | None = ..., bufsize: int = ..., *, format: int | None = ..., tarinfo: type[TarInfo] | None = ..., dereference: bool | None = ..., ignore_zeros: bool | None = ..., encoding: str | None = ..., errors: str = ..., pax_headers: Mapping[str, str] | None = ..., debug: int | None = ..., errorlevel: int | None = ..., compresslevel: int = ...) -> TarFile
|
srittau
approved these changes
Apr 11, 2025
Collaborator
srittau
left a comment
There was a problem hiding this comment.
Thanks!
Unfortunately, the fact that arguments with defaults can't precede arguments without defaults makes these extra overloads necessary. This was previously discussed on the typing-sig mailing list and subsequently on the python-dev mailing list. Maybe it's time to resurrect that proposal, possibly with the support of the typing council.
mmingyu
pushed a commit
to mmingyu/typeshed
that referenced
this pull request
May 16, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Per https://docs.python.org/3/library/tarfile.html#tarfile.open all of
name,mode,fileobj, andbufsizeare permitted to be positional.