-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
zipfile.Path.read_text
& .open
methods with a positional encoding
arg causes a TypeError
#101144
Comments
(and note that 3.10 is probably closed to bugfixes) |
Workaround for users, always pass encoding to read_text as a keyword encoding= argument rather than the first positional argument. |
zipfile.Path.read_text
with a positional encoding arg causes argument for TextIOWrapper() given by name ('encoding') and position (2)zipfile.Path
read_text and open methods with positional encoding arg causes TypeError argument given by name ('encoding') and position (2)
As was the behavior in 3.9 and earlier. The fix for python#87817 introduced an API regression in 3.10.0b1.
zipfile.Path
read_text and open methods with positional encoding arg causes TypeError argument given by name ('encoding') and position (2)zipfile.Path.read_text
& .open
methods with a positional encoding
arg causes a TypeError
One thought that I keep having - although this incompatibility was introduced unintentionally, it seems not to have affected but one reported use-case (and probably a handful that were not reported). Perhaps it makes sense to retain the more constrained form. As I consider that, I realize that these wrappers are really trying to be true to the underlying interface, so it's probably preferable to honor that and remain consistent than to offer only a more constrained interface. In other words, the proposed fix sounds good. |
Feel free to assign to me after the PR lands and I can handle the port. Or if you're interested in learning the process, I can share the process with you. |
The zipfile.Path open() and read_text() encoding parameter can be supplied as a positional argument without causing a TypeError again. 3.10.0b1 included a regression that made it keyword only. Documentation update included as users writing code to be compatible with a wide range of versions will need to consider this for some time.
…ional. (pythonGH-101145) The zipfile.Path open() and read_text() encoding parameter can be supplied as a positional argument without causing a TypeError again. 3.10.0b1 included a regression that made it keyword only. Documentation update included as users writing code to be compatible with a wide range of versions will need to consider this for some time.. (cherry picked from commit 5927013) Co-authored-by: Gregory P. Smith <greg@krypto.org>
…e positional (#101179) The zipfile.Path open() and read_text() encoding parameter can be supplied as a positional argument without causing a TypeError again. 3.10.0b1 included a regression that made it keyword only. Documentation update included as users writing code to be compatible with a wide range of versions will need to consider this for some time.. (cherry picked from commit 5927013) Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google]
…g to be positional (pythonGH-101179) The zipfile.Path open() and read_text() encoding parameter can be supplied as a positional argument without causing a TypeError again. 3.10.0b1 included a regression that made it keyword only. Documentation update included as users writing code to be compatible with a wide range of versions will need to consider this for some time.. (cherry picked from commit 5927013) (cherry picked from commit efe3a38) Co-authored-by: Gregory P. Smith <greg@krypto.org> Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google]
yep, I went through the same thought process. They're mirroring other APIs that take encoding and those accept it as a positional parameter, so fixing it rather than just declaring it keyword only made sense as a bugfix. As for your |
…e positional (GH-101179) (GH-101182) The zipfile.Path open() and read_text() encoding parameter can be supplied as a positional argument without causing a TypeError again. 3.10.0b1 included a regression that made it keyword only. Documentation update included as users writing code to be compatible with a wide range of versions will need to consider this for some time.. (cherry picked from commit 5927013) (cherry picked from commit efe3a38) Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google] Automerge-Triggered-By: GH:gpshead
…onal. (python/cpython#101145) The zipfile.Path open() and read_text() encoding parameter can be supplied as a positional argument without causing a TypeError again. 3.10.0b1 included a regression that made it keyword only. Documentation update included as users writing code to be compatible with a wide range of versions will need to consider this for some time.
…onal. (python/cpython#101145) The zipfile.Path open() and read_text() encoding parameter can be supplied as a positional argument without causing a TypeError again. 3.10.0b1 included a regression that made it keyword only. Documentation update included as users writing code to be compatible with a wide range of versions will need to consider this for some time.
The backport ended up being fairly challenging, given the lack of I plan to add |
…n 3.12.0 Gregory P. Smith (1): python/cpython#101144: Allow open and read_text encoding to be positional. (python/cpython#101145) Jason R. Coombs (13): Honor ResourceWarnings. Fixes jaraco/skeleton#73. tox 4 requires a boolean value, so use '1' to FORCE_COLOR. Fixes jaraco/skeleton#74. Remove unnecessary shebang and encoding header in docs conf. Prevent Python 3.12 from blocking checks. Build docs in CI, including sphinx-lint. Put tidelift docs dependency in its own section to limit merge conflicts. Update badge for 2023 Update changelog. Ref python/cpython#101144. Invoke test_encoding_warnings in-process, but skip when warn_default_encoding is not set. Re-use alpharep fixture for the file. Provide 'sys.flags.warn_default_encoding' for the tests to skip prior to 3.10. Due to mypy, it's not possible to patch the value, so just be lenient in access. Prefer simple asserts Replace trailing comment with a comment on a separate line.
This is a regression from 3.9 behavior seen in Python 3.10.
zipfile.Path.read_text passes *args and **kwargs to it's own
open()
method, but in 3.10+ is also blindly setskwargs["encodings"]
to a value. So code that was previously passing an encoding as a positional argument now sees:3.10's Lib/zipfile.py (and main's Lib/zipfile/_path.py) contain:
As this is a regression, we should avoid setting that value in kwargs when
"encodings" not in kwargs
to match 3.9 and earlier behavior.TODO list:
Linked PRs
The text was updated successfully, but these errors were encountered: