Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

tarfile.TarFile has several missing overloads #14168

Open
Labels
help wantedAn actionable problem of low to medium complexity where a PR would be very welcomestubs: false negativeType checkers do not report an error, but should
@sobolevn

Description

@sobolevn

Right nowTarFile.__init__ is defined as:

def__init__(
self,
name:StrOrBytesPath|None=None,
mode:Literal["r","a","w","x"]="r",
fileobj:_Fileobj|None=None,

Which is not exactly right, because there's a case whenname andfileobj are bothNone at the same time. And this will lead to runtime errors:

>>>importtarfile>>>tarfile.TarFile(None,fileobj=None)Traceback (mostrecentcalllast):File"<python-input-2>",line1,in<module>tarfile.TarFile(None,fileobj=None)~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^File"/Users/sobolev/Desktop/cpython/Lib/tarfile.py",line1729,in__init__fileobj=bltn_open(name,self._mode)TypeError:expectedstr,bytesoros.PathLikeobject,notNoneType

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 eithername 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 likeopen andtaropen, maybe others.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedAn actionable problem of low to medium complexity where a PR would be very welcomestubs: false negativeType checkers do not report an error, but should

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp