diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2022-04-22 18:08:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-22 18:08:49 (GMT) |
commit | 9c18d783c38fca57a63b61aa778d8a8d18945d95 (patch) | |
tree | 159220c7d865223e90a10f44e247ac90f36438bd /Lib/sre_parse.py | |
parent | 9f8b9a3506fefeba01a18eda0e06c037393be4bf (diff) | |
download | cpython-9c18d783c38fca57a63b61aa778d8a8d18945d95.zip cpython-9c18d783c38fca57a63b61aa778d8a8d18945d95.tar.gz cpython-9c18d783c38fca57a63b61aa778d8a8d18945d95.tar.bz2 |
[3.10] gh-90568: Fix exception type for \N with a named sequence in RE (GH-91665) (GH-91830)
re.error is now raised instead of TypeError.
(cherry picked from commit 6ccfa31421393910b52936e0447625db06f2a655)
Diffstat (limited to 'Lib/sre_parse.py')
-rw-r--r-- | Lib/sre_parse.py | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py index 5370667..d3ff196 100644 --- a/Lib/sre_parse.py +++ b/Lib/sre_parse.py @@ -330,7 +330,7 @@ def _class_escape(source, escape): charname = source.getuntil('}', 'character name') try: c = ord(unicodedata.lookup(charname)) - except KeyError: + except (KeyError, TypeError): raise source.error("undefined character name %r" % charname, len(charname) + len(r'\N{}')) return LITERAL, c @@ -390,7 +390,7 @@ def _escape(source, escape, state): charname = source.getuntil('}', 'character name') try: c = ord(unicodedata.lookup(charname)) - except KeyError: + except (KeyError, TypeError): raise source.error("undefined character name %r" % charname, len(charname) + len(r'\N{}')) return LITERAL, c |