mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-90568: Fix exception type for \N with a named sequence in RE (GH-91665)
re.error is now raised instead of TypeError.
This commit is contained in:
parent
2f233fceae
commit
6ccfa31421
3 changed files with 9 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue