What is the type of the compiled regular expression in python?
In particular, I want to evaluate
isinstance(re.compile(\'\'), ???)
Python 3.5 introduced the typing module. Included therein is typing.Pattern, a _TypeAlias.
Starting with Python 3.6, you can simply do:
from typing import Pattern
my_re = re.compile('foo')
assert isinstance(my_re, Pattern)
In 3.5, there used to be a bug requiring you to do this:
assert issubclass(type(my_re), Pattern)
Which isn’t guaranteed to work according to the documentation and test suite.