@@ -335,7 +335,7 @@ def _class_escape(source, escape):
335335 c = ord (unicodedata .lookup (charname ))
336336 except KeyError :
337337 raise source .error ("undefined character name %r" % charname ,
338- len (charname ) + len (r'\N{}' ))
338+ len (charname ) + len (r'\N{}' )) from None
339339 return LITERAL , c
340340 elif c in OCTDIGITS :
341341 # octal escape (up to three digits)
@@ -395,7 +395,7 @@ def _escape(source, escape, state):
395395 c = ord (unicodedata .lookup (charname ))
396396 except KeyError :
397397 raise source .error ("undefined character name %r" % charname ,
398- len (charname ) + len (r'\N{}' ))
398+ len (charname ) + len (r'\N{}' )) from None
399399 return LITERAL , c
400400 elif c == "0" :
401401 # octal escape
@@ -1014,7 +1014,7 @@ def addgroup(index, pos):
10141014 try :
10151015 index = groupindex [name ]
10161016 except KeyError :
1017- raise IndexError ("unknown group name %r" % name )
1017+ raise IndexError ("unknown group name %r" % name ) from None
10181018 else :
10191019 try :
10201020 index = int (name )
@@ -1053,7 +1053,7 @@ def addgroup(index, pos):
10531053 this = chr (ESCAPES [this ][1 ])
10541054 except KeyError :
10551055 if c in ASCIILETTERS :
1056- raise s .error ('bad escape %s' % this , len (this ))
1056+ raise s .error ('bad escape %s' % this , len (this )) from None
10571057 lappend (this )
10581058 else :
10591059 lappend (this )
@@ -1074,5 +1074,5 @@ def expand_template(template, match):
10741074 for index , group in groups :
10751075 literals [index ] = g (group ) or empty
10761076 except IndexError :
1077- raise error ("invalid group reference %d" % index )
1077+ raise error ("invalid group reference %d" % index ) from None
10781078 return empty .join (literals )
0 commit comments