MCPcopy Index your code
hub / github.com/python/cpython / PatternError

Class PatternError

Lib/re/_constants.py:23–53  ·  view source on GitHub ↗

Exception raised for invalid regular expressions. Attributes: msg: The unformatted error message pattern: The regular expression pattern pos: The index in the pattern where compilation failed (may be None) lineno: The line corresponding to pos (may be None)

Source from the content-addressed store, hash-verified

21# should this really be here?
22
23class PatternError(Exception):
24 """Exception raised for invalid regular expressions.
25
26 Attributes:
27
28 msg: The unformatted error message
29 pattern: The regular expression pattern
30 pos: The index in the pattern where compilation failed (may be None)
31 lineno: The line corresponding to pos (may be None)
32 colno: The column corresponding to pos (may be None)
33 """
34
35 __module__ = 're'
36
37 def __init__(self, msg, pattern=None, pos=None):
38 self.msg = msg
39 self.pattern = pattern
40 self.pos = pos
41 if pattern is not None and pos is not None:
42 msg = '%s at position %d' % (msg, pos)
43 if isinstance(pattern, str):
44 newline = '\n'
45 else:
46 newline = b'\n'
47 self.lineno = pattern.count(newline, 0, pos) + 1
48 self.colno = pos - pattern.rfind(newline, 0, pos)
49 if newline in pattern:
50 msg = '%s (line %d, column %d)' % (msg, self.lineno, self.colno)
51 else:
52 self.lineno = self.colno = None
53 super().__init__(msg)
54
55
56# Backward compatibility after renaming in 3.13

Callers 2

_compileFunction · 0.85
_compile_charsetFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…