I have a compromise idea, here is some points:

1, Create a built-in class `pattern_str` which is a subclass of `str`, it's dedicated to regex pattern string.
2, Use p"" to represent `pattern_str`.

Some advantages:

1, Since it's a subclass of `str`, we can use it as normal `str`.
2, IDE/linter/compiler can identify it as an regex pattern, something like type hint in language level.
3, We can still store compiled pattern in .pyc file *quietly*.
4, Won't introduce Perl style into Python, to avoid abusing regex in some degree.

We still using regex in the old way:

import re
re.search(p"(?i)[a-z]", s)

But if re.search() find the pattern is a `pattern_str`, it load compiled pattern from .pyc file directly.

_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to