diff options
author | Simon Chabot <simon.chabot@logilab.fr> | 2020-06-11 09:02:31 +0200 |
---|---|---|
committer | Simon Chabot <simon.chabot@logilab.fr> | 2020-06-11 09:02:31 +0200 |
commit | 787bd229345479c9e193f2695366ff584157548e (patch) | |
tree | 4ab421c8c096f51b8d695db27386ad4136e4b0a4 /logilab/common/pytest.py | |
parent | e333b18c03f2c1b62bdf1dd481e1f2c7a19dffec (diff) | |
download | logilab-common-787bd229345479c9e193f2695366ff584157548e.tar.gz |
fix(typing): explicitly define Match and Pattern on Import Error (python < 3.7)
for python < 3.6 those two types are not defined. In case of import error, let's
define them (in the exact same way they are defined in the re module of python
>= 3.7).
Diffstat (limited to 'logilab/common/pytest.py')
-rw-r--r-- | logilab/common/pytest.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/logilab/common/pytest.py b/logilab/common/pytest.py index e0758c4..b7f2e83 100644 --- a/logilab/common/pytest.py +++ b/logilab/common/pytest.py @@ -100,7 +100,17 @@ import re import sys import os.path as osp from time import process_time, time -from re import Match # type: ignore + +try: + from re import Match # type: ignore +except ImportError: + # Match is python > 3.6 only. + # + # To be compatible with python <= 3.6, and still provide some typing, we + # manually define Match, in the same manner it is defined in the re module + # of python > 3.7 + # cf https://github.com/python/cpython/blob/3.7/Lib/re.py#L264 + Match = type(re.sre_compile.compile("", 0).match("")) # type: ignore import warnings import types import inspect |