MCPcopy Create free account
hub / github.com/bpython/bpython / LazyReCompile

Class LazyReCompile

bpython/lazyre.py:29–53  ·  view source on GitHub ↗

Compile regular expressions on first use This class allows one to store regular expressions and compiles them on first use.

Source from the content-addressed store, hash-verified

27
28
29class LazyReCompile:
30 """Compile regular expressions on first use
31
32 This class allows one to store regular expressions and compiles them on
33 first use."""
34
35 def __init__(self, regex: str, flags: int = 0) -> None:
36 self.regex = regex
37 self.flags = flags
38
39 @cached_property
40 def compiled(self) -> Pattern[str]:
41 return re.compile(self.regex, self.flags)
42
43 def finditer(self, *args, **kwargs) -> Iterator[Match[str]]:
44 return self.compiled.finditer(*args, **kwargs)
45
46 def search(self, *args, **kwargs) -> Match[str] | None:
47 return self.compiled.search(*args, **kwargs)
48
49 def match(self, *args, **kwargs) -> Match[str] | None:
50 return self.compiled.match(*args, **kwargs)
51
52 def sub(self, *args, **kwargs) -> str:
53 return self.compiled.sub(*args, **kwargs)

Callers 7

InterpreterClass · 0.85
inspection.pyFile · 0.85
line.pyFile · 0.85
AttrCompletionClass · 0.85
manual_readline.pyFile · 0.85
parse.pyFile · 0.85
preprocess.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected