Skip to content

Commit

Permalink
Resolve a TypeError lurking in the read_text() functional API
Browse files Browse the repository at this point in the history
`importlib_resources.read_text()` calls the `Traversable.read_text()`
concrete method with an `errors` argument that doesn't exist in the
method signature, resulting in an `TypeError`.

This is resolved by adding an `errors` parameter to
`Traversable.read_text()`.

Fixes python/cpython#127012
  • Loading branch information
kurtmckee committed Nov 25, 2024
1 parent ec22ea9 commit 509ac17
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions importlib_resources/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,13 @@ def read_bytes(self) -> bytes:
with self.open('rb') as strm:
return strm.read()

def read_text(self, encoding: Optional[str] = None) -> str:
def read_text(
self, encoding: Optional[str] = None, errors: Optional[str] = None
) -> str:
"""
Read contents of self as text
"""
with self.open(encoding=encoding) as strm:
with self.open(encoding=encoding, errors=errors) as strm:
return strm.read()

@abc.abstractmethod
Expand Down

0 comments on commit 509ac17

Please sign in to comment.