Код: Выделить всё
import re
REGEX: re.Pattern[bytes] = re.compile(b"\xab.{2}")
def check(pattern: str) -> bool:
if str == "xyz":
return REGEX.fullmatch(pattern) is not None
return True
print(check("abcd"))
Код: Выделить всё
$ mypy ~/main.py
/home/oren/main.py:5: error: Argument 1 to "fullmatch" of "Pattern" has incompatible type "str"; expected "bytes"
Found 1 error in 1 file (checked 1 source file)
Код: Выделить всё
$ python ~/main.py
Traceback (most recent call last):
File "/home/oren/main.py", line 2, in
REGEX: re.Pattern[bytes] = re.compile(b"\xab.{2}")
TypeError: 'type' object is not subscriptable
Подробнее здесь: https://stackoverflow.com/questions/708 ... re-pattern