[Python-ideas] Use p"" to represent `pattern_str` -- a subclass of `str`
malincns at 163.com
Sat Dec 29 06:49:41 EST 2018
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`.
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
We still using regex in the old way:
But if re.search() find the pattern is a `pattern_str`, it load compiled
pattern from .pyc file directly.
More information about the Python-ideas