aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/re/_parser.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2022-04-22 18:35:28 +0300
committerGitHub <noreply@github.com>2022-04-22 18:35:28 +0300
commit6ccfa31421393910b52936e0447625db06f2a655 (patch)
tree825f9f3bcd6c14f5bab82ee08d55988f8748a168 /Lib/re/_parser.py
parent2f233fceae9a0c5e66e439bc0169b36547ba47c3 (diff)
downloadcpython-6ccfa31421393910b52936e0447625db06f2a655.tar.gz
cpython-6ccfa31421393910b52936e0447625db06f2a655.zip
gh-90568: Fix exception type for \N with a named sequence in RE (GH-91665)
re.error is now raised instead of TypeError.
Diffstat (limited to 'Lib/re/_parser.py')
-rw-r--r--Lib/re/_parser.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/Lib/re/_parser.py b/Lib/re/_parser.py
index f191f809a14..65888624930 100644
--- a/Lib/re/_parser.py
+++ b/Lib/re/_parser.py
@@ -333,7 +333,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{}')) from None
return LITERAL, c
@@ -393,7 +393,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{}')) from None
return LITERAL, c