Skip to content

Commit

Permalink
Change error message.
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiy-storchaka committed Nov 6, 2024
1 parent 1a98b24 commit 57ad6d2
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Lib/test/test_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3196,7 +3196,7 @@ def test_multiple_args(self):

# http://bugs.python.org/issue19609
def test_codec_lookup_failure(self):
msg = "^unknown encoding: {}$".format(self.codec_name)
msg = f"^encoding '{self.codec_name}' is not registered$"
with self.assertRaisesRegex(LookupError, msg):
"str input".encode(self.codec_name)
with self.assertRaisesRegex(LookupError, msg):
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -3939,7 +3939,7 @@ def _to_memoryview(buf):

class CTextIOWrapperTest(TextIOWrapperTest):
io = io
shutdown_error = "LookupError: unknown encoding: ascii"
shutdown_error = "LookupError: encoding 'ascii' is not registered"

def test_initialization(self):
r = self.BytesIO(b"\xc3\xa9\n\n")
Expand Down Expand Up @@ -4039,7 +4039,7 @@ def write(self, data):

class PyTextIOWrapperTest(TextIOWrapperTest):
io = pyio
shutdown_error = "LookupError: unknown encoding: ascii"
shutdown_error = "LookupError: encoding 'ascii' is not registered"


class IncrementalNewlineDecoderTest(unittest.TestCase):
Expand Down
5 changes: 2 additions & 3 deletions Lib/tokenize.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,9 @@ def find_cookie(line):
except LookupError:
# This behaviour mimics the Python interpreter
if filename is None:
msg = "unknown encoding: " + encoding
msg = f"encoding '{encoding}' is not registered"
else:
msg = "unknown encoding for {!r}: {}".format(filename,
encoding)
msg = f"encoding '{encoding}' is not registered for {filename!r}"
raise SyntaxError(msg)

if bom_found:
Expand Down
2 changes: 1 addition & 1 deletion Python/codecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ PyObject *_PyCodec_Lookup(const char *encoding)
if (result == NULL) {
/* XXX Perhaps we should cache misses too ? */
PyErr_Format(PyExc_LookupError,
"unknown encoding: %s", encoding);
"encoding '%s' is not registered", encoding);
goto onError;
}

Expand Down

0 comments on commit 57ad6d2

Please sign in to comment.