Skip to content

Commit

Permalink
GH-83162: Update _compiler and _constants to new exception name.
Browse files Browse the repository at this point in the history
  • Loading branch information
achhina committed May 28, 2023
1 parent e72dce1 commit 5274810
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 4 additions & 4 deletions Lib/re/_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def _compile(code, pattern, flags):
emit(ANY)
elif op in REPEATING_CODES:
if flags & SRE_FLAG_TEMPLATE:
raise error("internal: unsupported template operator %r" % (op,))
raise ReCompileError(f"internal: unsupported template operator {op!r}")
if _simple(av[2]):
emit(REPEATING_CODES[op][2])
skip = _len(code); emit(0)
Expand Down Expand Up @@ -150,7 +150,7 @@ def _compile(code, pattern, flags):
else:
lo, hi = av[1].getwidth()
if lo != hi:
raise error("look-behind requires fixed-width pattern")
raise ReCompileError("look-behind requires fixed-width pattern")
emit(lo) # look behind
_compile(code, av[1], flags)
emit(SUCCESS)
Expand Down Expand Up @@ -209,7 +209,7 @@ def _compile(code, pattern, flags):
else:
code[skipyes] = _len(code) - skipyes + 1
else:
raise error("internal: unsupported operand type %r" % (op,))
raise ReCompileError(f"internal: unsupported operand type {op!r}")

def _compile_charset(charset, flags, code):
# compile charset subprogram
Expand All @@ -235,7 +235,7 @@ def _compile_charset(charset, flags, code):
else:
emit(av)
else:
raise error("internal: unsupported set operator %r" % (op,))
raise ReCompileError(f"internal: unsupported set operator {op!r}")
emit(FAILURE)

def _optimize_charset(charset, iscased=None, fixup=None, fixes=None):
Expand Down
7 changes: 5 additions & 2 deletions Lib/re/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

from _sre import MAXREPEAT, MAXGROUPS

# SRE standard exception (access as sre.error)
# SRE standard exception (access as sre.ReCompileError)
# should this really be here?

class error(Exception):
class ReCompileError(Exception):
"""Exception raised for invalid regular expressions.
Attributes:
Expand Down Expand Up @@ -53,6 +53,9 @@ def __init__(self, msg, pattern=None, pos=None):
super().__init__(msg)


# Backward compatibility after renaming in 3.12
error = ReCompileError

class _NamedIntConstant(int):
def __new__(cls, value, name):
self = super(_NamedIntConstant, cls).__new__(cls, value)
Expand Down

0 comments on commit 5274810

Please sign in to comment.