Skip to content
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

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

Open
kbaikov opened this issue Nov 29, 2024 · 3 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@kbaikov
Copy link

kbaikov commented Nov 29, 2024

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

@kbaikov kbaikov added the type-bug An unexpected behavior, bug, or error label Nov 29, 2024
@sobolevn
Copy link
Member

I don't think that this is really a bug. It more looks like a refactoring. Can it affect existing users?

@picnixz picnixz added the stdlib Python modules in the Lib dir label Nov 29, 2024
@rruuaanng
Copy link
Contributor

I think it is initialized to None and there seems to be nothing wrong with it, after all, int and str are a class.

@picnixz
Copy link
Contributor

picnixz commented Dec 1, 2024

I think it is initialized to None and there seems to be nothing wrong with it, after all, int and str are a class.

This is not the issue. The issue concerns typing and the fact that errors must be typed str | None in this case, instead of just str. As for whether having a None value makes sense at runtime except for default-detection, the question remains and may affect existing users as Nikita hinted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
Status: No status
Development

No branches or pull requests

4 participants