From 509ac170a68fff47c6980327ce81ae3718cc65ed Mon Sep 17 00:00:00 2001 From: Kurt McKee Date: Mon, 25 Nov 2024 11:29:05 -0600 Subject: [PATCH] Resolve a `TypeError` lurking in the `read_text()` functional API `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 --- importlib_resources/abc.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/importlib_resources/abc.py b/importlib_resources/abc.py index 7a58dd2..71f4683 100644 --- a/importlib_resources/abc.py +++ b/importlib_resources/abc.py @@ -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