Merge pull request #9145 from bluetech/compat-pattern

compat: replace REGEX_TYPE with typing.Pattern
This commit is contained in:
Ran Benita 2021-10-01 16:16:28 +03:00 committed by GitHub
commit 3a6eaa9c1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 7 deletions

View File

@ -3,7 +3,6 @@ import enum
import functools import functools
import inspect import inspect
import os import os
import re
import sys import sys
from contextlib import contextmanager from contextlib import contextmanager
from inspect import Parameter from inspect import Parameter
@ -64,10 +63,6 @@ def _format_args(func: Callable[..., Any]) -> str:
return str(signature(func)) return str(signature(func))
# The type of re.compile objects is not exposed in Python.
REGEX_TYPE = type(re.compile(""))
def is_generator(func: object) -> bool: def is_generator(func: object) -> bool:
genfunc = inspect.isgeneratorfunction(func) genfunc = inspect.isgeneratorfunction(func)
return genfunc and not iscoroutinefunction(func) return genfunc and not iscoroutinefunction(func)

View File

@ -20,6 +20,7 @@ from typing import Iterator
from typing import List from typing import List
from typing import Mapping from typing import Mapping
from typing import Optional from typing import Optional
from typing import Pattern
from typing import Sequence from typing import Sequence
from typing import Set from typing import Set
from typing import Tuple from typing import Tuple
@ -46,7 +47,6 @@ from _pytest.compat import is_generator
from _pytest.compat import LEGACY_PATH from _pytest.compat import LEGACY_PATH
from _pytest.compat import legacy_path from _pytest.compat import legacy_path
from _pytest.compat import NOTSET from _pytest.compat import NOTSET
from _pytest.compat import REGEX_TYPE
from _pytest.compat import safe_getattr from _pytest.compat import safe_getattr
from _pytest.compat import safe_isclass from _pytest.compat import safe_isclass
from _pytest.compat import STRING_TYPES from _pytest.compat import STRING_TYPES
@ -1332,7 +1332,7 @@ def _idval(
return _ascii_escaped_by_config(val, config) return _ascii_escaped_by_config(val, config)
elif val is None or isinstance(val, (float, int, bool, complex)): elif val is None or isinstance(val, (float, int, bool, complex)):
return str(val) return str(val)
elif isinstance(val, REGEX_TYPE): elif isinstance(val, Pattern):
return ascii_escaped(val.pattern) return ascii_escaped(val.pattern)
elif val is NOTSET: elif val is NOTSET:
# Fallback to default. Note that NOTSET is an enum.Enum. # Fallback to default. Note that NOTSET is an enum.Enum.