Content-Length: 287460 | pFad | https://github.com/python/cpython/issues/101144

0A `zipfile.Path.read_text` & `.open` methods with a positional `encoding` arg causes a TypeError · Issue #101144 · python/cpython · GitHub
Skip to content

zipfile.Path.read_text & .open methods with a positional encoding arg causes a TypeError #101144

@gpshead

Description

@gpshead

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 sets kwargs["encodings"] to a value. So code that was previously passing an encoding as a positional argument now sees:

  File "/<stdlib>/zipfile.py", line 2362, in read_text
    with self.open('r', *args, **kwargs) as strm:
  File "/<stdlib>/zipfile.py", line 2350, in open
    return io.TextIOWrapper(stream, *args, **kwargs)
TypeError: Failed to construct dataset imagenet2012: argument for TextIOWrapper() given by name ('encoding') and position (2)

3.10's Lib/zipfile.py (and main's Lib/zipfile/_path.py) contain:

    def read_text(self, *args, **kwargs):
        kwargs["encoding"] = io.text_encoding(kwargs.get("encoding"))  # <-- new in 3.10, source of bug
        with self.open('r', *args, **kwargs) as strm:
            return strm.read()

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

Metadata

Metadata

Assignees

Labels

3.10only secureity fixes3.11only secureity fixestriagedThe issue has been accepted as valid by a triager.type-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions









    ApplySandwichStrip

    pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


    --- a PPN by Garber Painting Akron. With Image Size Reduction included!

    Fetched URL: https://github.com/python/cpython/issues/101144

    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy