Fixes#875.
This adds support for pre-compiled regular expressions to
attr.validators.matches_re(). This cannot be combined with flags since
the pre-compiled pattern already has those.
Detailed changes:
- attr.validators.matches_re() now accepts re.Pattern in addition to
strings; update type annotations accordingly.
- Convert percent-formatting into str.format() for an error message
- Simplify (private) _MatchesReValidator helper class a bit: use the
actual compiled pattern, and drop the unused .flags attribute.
- Simplify control flow a bit; add pointer about fullmatch emulation.
- Add tests
- Tweak existing test to ensure that .fullmatch() actually works
correctly by matching a pattern that also matches (but not
‘full-matches’) a shorter substring.
Co-authored-by: Hynek Schlawack <hs@ox.cx>