MCPcopy
hub / github.com/python-attrs/attrs / _MatchesReValidator

Class _MatchesReValidator

src/attr/validators.py:131–149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

129
130@attrs(repr=False, frozen=True, slots=True)
131class _MatchesReValidator:
132 pattern = attrib()
133 match_func = attrib()
134
135 def __call__(self, inst, attr, value):
136 """
137 We use a callable class to be able to change the ``__repr__``.
138 """
139 if not self.match_func(value):
140 msg = f"'{attr.name}' must match regex {self.pattern.pattern!r} ({value!r} doesn't)"
141 raise ValueError(
142 msg,
143 attr,
144 self.pattern,
145 value,
146 )
147
148 def __repr__(self):
149 return f"<matches_re validator for pattern {self.pattern!r}>"
150
151
152def matches_re(regex, flags=0, func=None):

Callers 1

matches_reFunction · 0.85

Calls 1

attribFunction · 0.85

Tested by

no test coverage detected