From c999d014c136fb2964ff4ddeff682814f49330ec Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 18 Nov 2024 19:18:28 +0200 Subject: [PATCH] Revert "Change error message." This reverts commit 57ad6d2a928e821cbb42e3a9538491808e4a9925. --- Lib/test/test_codecs.py | 2 +- Lib/test/test_io.py | 4 ++-- Lib/tokenize.py | 5 +++-- Python/codecs.c | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index 6799948478aa2a..e51f7e0ee12b1f 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -3196,7 +3196,7 @@ def test_multiple_args(self): # http://bugs.python.org/issue19609 def test_codec_lookup_failure(self): - msg = f"^encoding '{self.codec_name}' is not registered$" + msg = "^unknown encoding: {}$".format(self.codec_name) with self.assertRaisesRegex(LookupError, msg): "str input".encode(self.codec_name) with self.assertRaisesRegex(LookupError, msg): diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index cb93be703ba8b2..aa1b8268592ff7 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -3939,7 +3939,7 @@ def _to_memoryview(buf): class CTextIOWrapperTest(TextIOWrapperTest): io = io - shutdown_error = "LookupError: encoding 'ascii' is not registered" + shutdown_error = "LookupError: unknown encoding: ascii" def test_initialization(self): r = self.BytesIO(b"\xc3\xa9\n\n") @@ -4039,7 +4039,7 @@ def write(self, data): class PyTextIOWrapperTest(TextIOWrapperTest): io = pyio - shutdown_error = "LookupError: encoding 'ascii' is not registered" + shutdown_error = "LookupError: unknown encoding: ascii" class IncrementalNewlineDecoderTest(unittest.TestCase): diff --git a/Lib/tokenize.py b/Lib/tokenize.py index 41ae0ed3e03915..7ece4e9b70d31b 100644 --- a/Lib/tokenize.py +++ b/Lib/tokenize.py @@ -398,9 +398,10 @@ def find_cookie(line): except LookupError: # This behaviour mimics the Python interpreter if filename is None: - msg = f"encoding '{encoding}' is not registered" + msg = "unknown encoding: " + encoding else: - msg = f"encoding '{encoding}' is not registered for {filename!r}" + msg = "unknown encoding for {!r}: {}".format(filename, + encoding) raise SyntaxError(msg) if bom_found: diff --git a/Python/codecs.c b/Python/codecs.c index fbc6a1996ee530..2cb3875db35058 100644 --- a/Python/codecs.c +++ b/Python/codecs.c @@ -204,7 +204,7 @@ PyObject *_PyCodec_Lookup(const char *encoding) if (result == NULL) { /* XXX Perhaps we should cache misses too ? */ PyErr_Format(PyExc_LookupError, - "encoding '%s' is not registered", encoding); + "unknown encoding: %s", encoding); goto onError; }