Skip to content

tarfile.TarFile.errors is initialized for some reason as None even though it really only accepts str #127424

Open
@kbaikov

Description

@kbaikov

Bug report

Bug description:

See the exact line here:

errors = None # Error handler for unicode conversion.

After that the errors is used only as string in encode/decode. And is initialized in the dunder init with default errors="surrogateescape".

So perhaps it would be a good idea to use errors="" in #L1687 ? or directly with the default errors="surrogateescape" ?

This was discovered as part of the typeshed, where tarfile.TarFile.errors was added into the allowed list since mypy complained: https://github.com/python/typeshed/blob/2ccc53bb6716463680fcf1d204642c46299b7f88/stdlib/%40tests/stubtest_allowlists/common.txt#L46C1-L46C16

I will add a PR here and to the typeshed if this gets approved.

CPython versions tested on:

3.13

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions