-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
tarfile.TarFile
has several missing overloads
#14168
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
Labels
help wanted
An actionable problem of low to medium complexity where a PR would be very welcome
stubs: false negative
Type checkers do not report an error, but should
Comments
I can try fix this. |
ashm-dev
added a commit
to ashm-dev/typeshed
that referenced
this issue
May 27, 2025
… case Add proper overloads to TarFile.__init__, open, taropen, gzopen, bz2open, and xzopen to ensure that at least one of `name` or `fileobj` parameters is not None. This prevents mypy from accepting invalid calls like `tarfile.TarFile(None, fileobj=None)` which would cause runtime errors. Fixes python#14168
ashm-dev
added a commit
to ashm-dev/typeshed
that referenced
this issue
May 27, 2025
… case Add proper overloads to TarFile.__init__, open, taropen, gzopen, bz2open, and xzopen to ensure that at least one of `name` or `fileobj` parameters is not None. This prevents mypy from accepting invalid calls like `tarfile.TarFile(None, fileobj=None)` which would cause runtime errors. Fixes python#14168
ashm-dev
added a commit
to ashm-dev/typeshed
that referenced
this issue
May 27, 2025
… case Add proper overloads to TarFile.__init__, open, taropen, gzopen, bz2open, and xzopen to ensure that at least one of `name` or `fileobj` parameters is not None. This prevents mypy from accepting invalid calls like `tarfile.TarFile(None, fileobj=None)` which would cause runtime errors. Fixes python#14168
ashm-dev
added a commit
to ashm-dev/typeshed
that referenced
this issue
May 27, 2025
… case Add proper overloads to TarFile.__init__, open, taropen, gzopen, bz2open, and xzopen to ensure that at least one of `name` or `fileobj` parameters is not None. This prevents mypy from accepting invalid calls like `tarfile.TarFile(None, fileobj=None)` which would cause runtime errors. Fixes python#14168
I work with this in this PR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
help wanted
An actionable problem of low to medium complexity where a PR would be very welcome
stubs: false negative
Type checkers do not report an error, but should
Right now
TarFile.__init__
is defined as:typeshed/stdlib/tarfile.pyi
Lines 128 to 132 in c7e29ec
Which is not exactly right, because there's a case when
name
andfileobj
are bothNone
at the same time. And this will lead to runtime errors:Right now mypy does not raise any errors for this broken case: https://mypy-play.net/?mypy=latest&python=3.12&gist=7452d274249fafba1f8a16565d5486c6
We need either
name
orfileobj
, they can be bothNone
at the same time. So, we need to add overloads.There are several other methods that needs to be updated like
open
andtaropen
, maybe others.The text was updated successfully, but these errors were encountered: