From bfadd4060e83a7c8dc6233643ad9fa4af7368806 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Fri, 2 Oct 2020 13:02:22 -0700 Subject: [PATCH] py36+: from typing import Type: no longer need guard --- src/_pytest/_code/code.py | 12 ++++++------ src/_pytest/compat.py | 6 +++--- src/_pytest/config/__init__.py | 10 ++++------ src/_pytest/debugging.py | 3 +-- src/_pytest/doctest.py | 8 ++++---- src/_pytest/fixtures.py | 4 ++-- src/_pytest/main.py | 2 +- src/_pytest/mark/structures.py | 7 ++----- src/_pytest/nodes.py | 5 ++--- src/_pytest/outcomes.py | 4 ++-- src/_pytest/pytester.py | 4 ++-- src/_pytest/python.py | 2 +- src/_pytest/python_api.py | 21 +++++++-------------- src/_pytest/recwarn.py | 19 ++++++++----------- src/_pytest/reports.py | 6 +++--- src/_pytest/runner.py | 6 ++++-- src/_pytest/skipping.py | 7 ++----- src/_pytest/unittest.py | 2 +- src/_pytest/warning_types.py | 7 ++----- testing/test_config.py | 7 ++----- testing/test_monkeypatch.py | 7 ++----- testing/test_runner.py | 7 ++----- 22 files changed, 63 insertions(+), 93 deletions(-) diff --git a/src/_pytest/_code/code.py b/src/_pytest/_code/code.py index 65b2bd63823..ce63b4b16bf 100644 --- a/src/_pytest/_code/code.py +++ b/src/_pytest/_code/code.py @@ -21,6 +21,7 @@ from typing import Sequence from typing import Set from typing import Tuple +from typing import Type from typing import TYPE_CHECKING from typing import TypeVar from typing import Union @@ -44,7 +45,6 @@ from _pytest.pathlib import Path if TYPE_CHECKING: - from typing import Type from typing_extensions import Literal from weakref import ReferenceType @@ -421,14 +421,14 @@ class ExceptionInfo(Generic[_E]): _assert_start_repr = "AssertionError('assert " - _excinfo = attr.ib(type=Optional[Tuple["Type[_E]", "_E", TracebackType]]) + _excinfo = attr.ib(type=Optional[Tuple[Type["_E"], "_E", TracebackType]]) _striptext = attr.ib(type=str, default="") _traceback = attr.ib(type=Optional[Traceback], default=None) @classmethod def from_exc_info( cls, - exc_info: Tuple["Type[_E]", "_E", TracebackType], + exc_info: Tuple[Type[_E], _E, TracebackType], exprinfo: Optional[str] = None, ) -> "ExceptionInfo[_E]": """Return an ExceptionInfo for an existing exc_info tuple. @@ -479,13 +479,13 @@ def for_later(cls) -> "ExceptionInfo[_E]": """Return an unfilled ExceptionInfo.""" return cls(None) - def fill_unfilled(self, exc_info: Tuple["Type[_E]", _E, TracebackType]) -> None: + def fill_unfilled(self, exc_info: Tuple[Type[_E], _E, TracebackType]) -> None: """Fill an unfilled ExceptionInfo created with ``for_later()``.""" assert self._excinfo is None, "ExceptionInfo was already filled" self._excinfo = exc_info @property - def type(self) -> "Type[_E]": + def type(self) -> Type[_E]: """The exception class.""" assert ( self._excinfo is not None @@ -551,7 +551,7 @@ def exconly(self, tryshort: bool = False) -> str: return text def errisinstance( - self, exc: Union["Type[BaseException]", Tuple["Type[BaseException]", ...]] + self, exc: Union[Type[BaseException], Tuple[Type[BaseException], ...]] ) -> bool: """Return True if the exception is an instance of exc. diff --git a/src/_pytest/compat.py b/src/_pytest/compat.py index 49b00c58e3b..c5de190e3d6 100644 --- a/src/_pytest/compat.py +++ b/src/_pytest/compat.py @@ -25,7 +25,6 @@ if TYPE_CHECKING: from typing import NoReturn - from typing import Type from typing_extensions import Final @@ -362,6 +361,7 @@ def final(f): # noqa: F811 if sys.version_info >= (3, 8): from functools import cached_property as cached_property else: + from typing import Type class cached_property(Generic[_S, _T]): __slots__ = ("func", "__doc__") @@ -372,13 +372,13 @@ def __init__(self, func: Callable[[_S], _T]) -> None: @overload def __get__( - self, instance: None, owner: Optional["Type[_S]"] = ... + self, instance: None, owner: Optional[Type[_S]] = ... ) -> "cached_property[_S, _T]": ... @overload # noqa: F811 def __get__( # noqa: F811 - self, instance: _S, owner: Optional["Type[_S]"] = ... + self, instance: _S, owner: Optional[Type[_S]] = ... ) -> _T: ... diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index 9df2a355d63..799cc19c613 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -26,6 +26,7 @@ from typing import Set from typing import TextIO from typing import Tuple +from typing import Type from typing import TYPE_CHECKING from typing import Union @@ -56,7 +57,6 @@ from _pytest.warning_types import PytestConfigWarning if TYPE_CHECKING: - from typing import Type from _pytest._code.code import _TracebackStyle from _pytest.terminal import TerminalReporter @@ -104,7 +104,7 @@ class ConftestImportFailure(Exception): def __init__( self, path: py.path.local, - excinfo: Tuple["Type[Exception]", Exception, TracebackType], + excinfo: Tuple[Type[Exception], Exception, TracebackType], ) -> None: super().__init__(path, excinfo) self.path = path @@ -1560,7 +1560,7 @@ def _strtobool(val: str) -> bool: @lru_cache(maxsize=50) def parse_warning_filter( arg: str, *, escape: bool -) -> "Tuple[str, str, Type[Warning], str, int]": +) -> Tuple[str, str, Type[Warning], str, int]: """Parse a warnings filter string. This is copied from warnings._setoption, but does not apply the filter, @@ -1573,9 +1573,7 @@ def parse_warning_filter( parts.append("") action_, message, category_, module, lineno_ = [s.strip() for s in parts] action = warnings._getaction(action_) # type: str # type: ignore[attr-defined] - category = warnings._getcategory( - category_ - ) # type: Type[Warning] # type: ignore[attr-defined] + category: Type[Warning] = warnings._getcategory(category_) # type: ignore[attr-defined] if message and escape: message = re.escape(message) if module and escape: diff --git a/src/_pytest/debugging.py b/src/_pytest/debugging.py index 0fec6d817e3..2b3faf8dc6c 100644 --- a/src/_pytest/debugging.py +++ b/src/_pytest/debugging.py @@ -9,6 +9,7 @@ from typing import List from typing import Optional from typing import Tuple +from typing import Type from typing import TYPE_CHECKING from typing import Union @@ -24,8 +25,6 @@ from _pytest.reports import BaseReport if TYPE_CHECKING: - from typing import Type - from _pytest.capture import CaptureManager from _pytest.runner import CallInfo diff --git a/src/_pytest/doctest.py b/src/_pytest/doctest.py index 304d3d9047b..817c9f9a841 100644 --- a/src/_pytest/doctest.py +++ b/src/_pytest/doctest.py @@ -17,6 +17,7 @@ from typing import Pattern from typing import Sequence from typing import Tuple +from typing import Type from typing import TYPE_CHECKING from typing import Union @@ -40,7 +41,6 @@ if TYPE_CHECKING: import doctest - from typing import Type DOCTEST_REPORT_CHOICE_NONE = "none" DOCTEST_REPORT_CHOICE_CDIFF = "cdiff" @@ -168,7 +168,7 @@ def __init__(self, failures: "Sequence[doctest.DocTestFailure]") -> None: self.failures = failures -def _init_runner_class() -> "Type[doctest.DocTestRunner]": +def _init_runner_class() -> Type["doctest.DocTestRunner"]: import doctest class PytestDoctestRunner(doctest.DebugRunner): @@ -204,7 +204,7 @@ def report_unexpected_exception( out, test: "doctest.DocTest", example: "doctest.Example", - exc_info: "Tuple[Type[BaseException], BaseException, types.TracebackType]", + exc_info: Tuple[Type[BaseException], BaseException, types.TracebackType], ) -> None: if isinstance(exc_info[1], OutcomeException): raise exc_info[1] @@ -568,7 +568,7 @@ def func() -> None: return fixture_request -def _init_checker_class() -> "Type[doctest.OutputChecker]": +def _init_checker_class() -> Type["doctest.OutputChecker"]: import doctest import re diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index 62def5a3319..d793ea37f1e 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -19,6 +19,7 @@ from typing import Sequence from typing import Set from typing import Tuple +from typing import Type from typing import TYPE_CHECKING from typing import TypeVar from typing import Union @@ -57,7 +58,6 @@ if TYPE_CHECKING: from typing import Deque from typing import NoReturn - from typing import Type from typing_extensions import Literal from _pytest import nodes @@ -91,7 +91,7 @@ # Cache key. object, # Exc info if raised. - Tuple["Type[BaseException]", BaseException, TracebackType], + Tuple[Type[BaseException], BaseException, TracebackType], ], ] diff --git a/src/_pytest/main.py b/src/_pytest/main.py index a8eaf02592f..31dc28e5d0e 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -14,6 +14,7 @@ from typing import Sequence from typing import Set from typing import Tuple +from typing import Type from typing import TYPE_CHECKING from typing import Union @@ -44,7 +45,6 @@ if TYPE_CHECKING: - from typing import Type from typing_extensions import Literal diff --git a/src/_pytest/mark/structures.py b/src/_pytest/mark/structures.py index 6be4725d68d..d5ea2a99ee9 100644 --- a/src/_pytest/mark/structures.py +++ b/src/_pytest/mark/structures.py @@ -13,6 +13,7 @@ from typing import Sequence from typing import Set from typing import Tuple +from typing import Type from typing import TYPE_CHECKING from typing import TypeVar from typing import Union @@ -30,8 +31,6 @@ from _pytest.warning_types import PytestUnknownMarkWarning if TYPE_CHECKING: - from typing import Type - from ..nodes import Node @@ -417,9 +416,7 @@ def __call__( # noqa: F811 *conditions: Union[str, bool], reason: str = ..., run: bool = ..., - raises: Union[ - "Type[BaseException]", Tuple["Type[BaseException]", ...] - ] = ..., + raises: Union[Type[BaseException], Tuple[Type[BaseException], ...]] = ..., strict: bool = ... ) -> MarkDecorator: ... diff --git a/src/_pytest/nodes.py b/src/_pytest/nodes.py index f8dbf826373..c8375e7cdb8 100644 --- a/src/_pytest/nodes.py +++ b/src/_pytest/nodes.py @@ -10,6 +10,7 @@ from typing import Optional from typing import Set from typing import Tuple +from typing import Type from typing import TYPE_CHECKING from typing import TypeVar from typing import Union @@ -36,8 +37,6 @@ from _pytest.store import Store if TYPE_CHECKING: - from typing import Type - # Imported here due to circular import. from _pytest.main import Session from _pytest.warning_types import PytestWarning @@ -350,7 +349,7 @@ def addfinalizer(self, fin: Callable[[], object]) -> None: """ self.session._setupstate.addfinalizer(fin, self) - def getparent(self, cls: "Type[_NodeType]") -> Optional[_NodeType]: + def getparent(self, cls: Type[_NodeType]) -> Optional[_NodeType]: """Get the next parent node (including self) which is an instance of the given class.""" current = self # type: Optional[Node] diff --git a/src/_pytest/outcomes.py b/src/_pytest/outcomes.py index a2ddc3a1f1a..cc70e72d4b1 100644 --- a/src/_pytest/outcomes.py +++ b/src/_pytest/outcomes.py @@ -5,13 +5,13 @@ from typing import Callable from typing import cast from typing import Optional +from typing import Type from typing import TypeVar TYPE_CHECKING = False # Avoid circular import through compat. if TYPE_CHECKING: from typing import NoReturn - from typing import Type # noqa: F401 (used in type string) from typing_extensions import Protocol else: # typing.Protocol is only available starting from Python 3.8. It is also @@ -84,7 +84,7 @@ def __init__( # Ideally would just be `exit.Exception = Exit` etc. _F = TypeVar("_F", bound=Callable[..., object]) -_ET = TypeVar("_ET", bound="Type[BaseException]") +_ET = TypeVar("_ET", bound=Type[BaseException]) class _WithException(Protocol[_F, _ET]): diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index 7c7ac9348d6..29690f0f011 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -18,6 +18,7 @@ from typing import Optional from typing import Sequence from typing import Tuple +from typing import Type from typing import TYPE_CHECKING from typing import Union from weakref import WeakKeyDictionary @@ -49,7 +50,6 @@ from _pytest.tmpdir import TempdirFactory if TYPE_CHECKING: - from typing import Type from typing_extensions import Literal import pexpect @@ -420,7 +420,7 @@ def linecomp() -> "LineComp": @pytest.fixture(name="LineMatcher") -def LineMatcher_fixture(request: FixtureRequest) -> "Type[LineMatcher]": +def LineMatcher_fixture(request: FixtureRequest) -> Type["LineMatcher"]: """A reference to the :class: `LineMatcher`. This is instantiable with a list of lines (without their trailing newlines). diff --git a/src/_pytest/python.py b/src/_pytest/python.py index ee4d7d3f8a7..e0a295a065b 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -22,6 +22,7 @@ from typing import Sequence from typing import Set from typing import Tuple +from typing import Type from typing import TYPE_CHECKING from typing import Union @@ -72,7 +73,6 @@ from _pytest.warning_types import PytestUnhandledCoroutineWarning if TYPE_CHECKING: - from typing import Type from typing_extensions import Literal from _pytest.fixtures import _Scope diff --git a/src/_pytest/python_api.py b/src/_pytest/python_api.py index e5489ec8328..b1f09030ade 100644 --- a/src/_pytest/python_api.py +++ b/src/_pytest/python_api.py @@ -13,7 +13,7 @@ from typing import Optional from typing import Pattern from typing import Tuple -from typing import TYPE_CHECKING +from typing import Type from typing import TypeVar from typing import Union @@ -23,9 +23,6 @@ from _pytest.compat import STRING_TYPES from _pytest.outcomes import fail -if TYPE_CHECKING: - from typing import Type - def _non_numeric_type_error(value, at: Optional[str]) -> TypeError: at_str = " at {}".format(at) if at else "" @@ -560,7 +557,7 @@ def _is_numpy_array(obj: object) -> bool: @overload def raises( - expected_exception: Union["Type[_E]", Tuple["Type[_E]", ...]], + expected_exception: Union[Type[_E], Tuple[Type[_E], ...]], *, match: Optional[Union[str, Pattern[str]]] = ... ) -> "RaisesContext[_E]": @@ -569,7 +566,7 @@ def raises( @overload # noqa: F811 def raises( # noqa: F811 - expected_exception: Union["Type[_E]", Tuple["Type[_E]", ...]], + expected_exception: Union[Type[_E], Tuple[Type[_E], ...]], func: Callable[..., Any], *args: Any, **kwargs: Any @@ -578,9 +575,7 @@ def raises( # noqa: F811 def raises( # noqa: F811 - expected_exception: Union["Type[_E]", Tuple["Type[_E]", ...]], - *args: Any, - **kwargs: Any + expected_exception: Union[Type[_E], Tuple[Type[_E], ...]], *args: Any, **kwargs: Any ) -> Union["RaisesContext[_E]", _pytest._code.ExceptionInfo[_E]]: r"""Assert that a code block/function call raises ``expected_exception`` or raise a failure exception otherwise. @@ -738,7 +733,7 @@ def raises( # noqa: F811 class RaisesContext(Generic[_E]): def __init__( self, - expected_exception: Union["Type[_E]", Tuple["Type[_E]", ...]], + expected_exception: Union[Type[_E], Tuple[Type[_E], ...]], message: str, match_expr: Optional[Union[str, Pattern[str]]] = None, ) -> None: @@ -753,7 +748,7 @@ def __enter__(self) -> _pytest._code.ExceptionInfo[_E]: def __exit__( self, - exc_type: Optional["Type[BaseException]"], + exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType], ) -> bool: @@ -764,9 +759,7 @@ def __exit__( if not issubclass(exc_type, self.expected_exception): return False # Cast to narrow the exception type now that it's verified. - exc_info = cast( - Tuple["Type[_E]", _E, TracebackType], (exc_type, exc_val, exc_tb) - ) + exc_info = cast(Tuple[Type[_E], _E, TracebackType], (exc_type, exc_val, exc_tb)) self.excinfo.fill_unfilled(exc_info) if self.match_expr is not None: self.excinfo.match(self.match_expr) diff --git a/src/_pytest/recwarn.py b/src/_pytest/recwarn.py index a2e6b274197..a455e9e57f0 100644 --- a/src/_pytest/recwarn.py +++ b/src/_pytest/recwarn.py @@ -10,7 +10,7 @@ from typing import Optional from typing import Pattern from typing import Tuple -from typing import TYPE_CHECKING +from typing import Type from typing import TypeVar from typing import Union @@ -19,9 +19,6 @@ from _pytest.fixtures import fixture from _pytest.outcomes import fail -if TYPE_CHECKING: - from typing import Type - T = TypeVar("T") @@ -86,7 +83,7 @@ def deprecated_call( # noqa: F811 @overload def warns( - expected_warning: Optional[Union["Type[Warning]", Tuple["Type[Warning]", ...]]], + expected_warning: Optional[Union[Type[Warning], Tuple[Type[Warning], ...]]], *, match: Optional[Union[str, Pattern[str]]] = ... ) -> "WarningsChecker": @@ -95,7 +92,7 @@ def warns( @overload # noqa: F811 def warns( # noqa: F811 - expected_warning: Optional[Union["Type[Warning]", Tuple["Type[Warning]", ...]]], + expected_warning: Optional[Union[Type[Warning], Tuple[Type[Warning], ...]]], func: Callable[..., T], *args: Any, **kwargs: Any @@ -104,7 +101,7 @@ def warns( # noqa: F811 def warns( # noqa: F811 - expected_warning: Optional[Union["Type[Warning]", Tuple["Type[Warning]", ...]]], + expected_warning: Optional[Union[Type[Warning], Tuple[Type[Warning], ...]]], *args: Any, match: Optional[Union[str, Pattern[str]]] = None, **kwargs: Any @@ -187,7 +184,7 @@ def __len__(self) -> int: """The number of recorded warnings.""" return len(self._list) - def pop(self, cls: "Type[Warning]" = Warning) -> "warnings.WarningMessage": + def pop(self, cls: Type[Warning] = Warning) -> "warnings.WarningMessage": """Pop the first recorded warning, raise exception if not exists.""" for i, w in enumerate(self._list): if issubclass(w.category, cls): @@ -214,7 +211,7 @@ def __enter__(self) -> "WarningsRecorder": # type: ignore def __exit__( self, - exc_type: Optional["Type[BaseException]"], + exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType], ) -> None: @@ -234,7 +231,7 @@ class WarningsChecker(WarningsRecorder): def __init__( self, expected_warning: Optional[ - Union["Type[Warning]", Tuple["Type[Warning]", ...]] + Union[Type[Warning], Tuple[Type[Warning], ...]] ] = None, match_expr: Optional[Union[str, Pattern[str]]] = None, ) -> None: @@ -258,7 +255,7 @@ def __init__( def __exit__( self, - exc_type: Optional["Type[BaseException]"], + exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType], ) -> None: diff --git a/src/_pytest/reports.py b/src/_pytest/reports.py index 94c78581254..a6d593ccd27 100644 --- a/src/_pytest/reports.py +++ b/src/_pytest/reports.py @@ -8,6 +8,7 @@ from typing import List from typing import Optional from typing import Tuple +from typing import Type from typing import TYPE_CHECKING from typing import TypeVar from typing import Union @@ -36,7 +37,6 @@ if TYPE_CHECKING: from typing import NoReturn - from typing_extensions import Type from typing_extensions import Literal from _pytest.runner import CallInfo @@ -199,7 +199,7 @@ def _to_json(self) -> Dict[str, Any]: return _report_to_json(self) @classmethod - def _from_json(cls: "Type[_R]", reportdict: Dict[str, object]) -> _R: + def _from_json(cls: Type[_R], reportdict: Dict[str, object]) -> _R: """Create either a TestReport or CollectReport, depending on the calling class. It is the callers responsibility to know which class to pass here. @@ -213,7 +213,7 @@ def _from_json(cls: "Type[_R]", reportdict: Dict[str, object]) -> _R: def _report_unserialization_failure( - type_name: str, report_class: "Type[BaseReport]", reportdict + type_name: str, report_class: Type[BaseReport], reportdict ) -> "NoReturn": url = "https://github.com/pytest-dev/pytest/issues" stream = StringIO() diff --git a/src/_pytest/runner.py b/src/_pytest/runner.py index 74692e21145..e16fb4ab477 100644 --- a/src/_pytest/runner.py +++ b/src/_pytest/runner.py @@ -9,6 +9,7 @@ from typing import List from typing import Optional from typing import Tuple +from typing import Type from typing import TYPE_CHECKING from typing import TypeVar from typing import Union @@ -33,7 +34,6 @@ from _pytest.outcomes import TEST_OUTCOME if TYPE_CHECKING: - from typing import Type from typing_extensions import Literal from _pytest.main import Session @@ -301,7 +301,9 @@ def from_call( cls, func: "Callable[[], TResult]", when: "Literal['collect', 'setup', 'call', 'teardown']", - reraise: "Optional[Union[Type[BaseException], Tuple[Type[BaseException], ...]]]" = None, + reraise: Optional[ + Union[Type[BaseException], Tuple[Type[BaseException], ...]] + ] = None, ) -> "CallInfo[TResult]": excinfo = None start = timing.time() diff --git a/src/_pytest/skipping.py b/src/_pytest/skipping.py index 9be49bbfad4..cc505fdd7c2 100644 --- a/src/_pytest/skipping.py +++ b/src/_pytest/skipping.py @@ -6,7 +6,7 @@ from typing import Generator from typing import Optional from typing import Tuple -from typing import TYPE_CHECKING +from typing import Type import attr @@ -22,9 +22,6 @@ from _pytest.runner import CallInfo from _pytest.store import StoreKey -if TYPE_CHECKING: - from typing import Type - def pytest_addoption(parser: Parser) -> None: group = parser.getgroup("general") @@ -194,7 +191,7 @@ class Xfail: reason = attr.ib(type=str) run = attr.ib(type=bool) strict = attr.ib(type=bool) - raises = attr.ib(type=Optional[Tuple["Type[BaseException]", ...]]) + raises = attr.ib(type=Optional[Tuple[Type[BaseException], ...]]) def evaluate_xfail_marks(item: Item) -> Optional[Xfail]: diff --git a/src/_pytest/unittest.py b/src/_pytest/unittest.py index 6b466da96bf..62c6e90b71b 100644 --- a/src/_pytest/unittest.py +++ b/src/_pytest/unittest.py @@ -9,6 +9,7 @@ from typing import List from typing import Optional from typing import Tuple +from typing import Type from typing import TYPE_CHECKING from typing import Union @@ -33,7 +34,6 @@ if TYPE_CHECKING: import unittest - from typing import Type from _pytest.fixtures import _Scope diff --git a/src/_pytest/warning_types.py b/src/_pytest/warning_types.py index a7490dc776a..bd3a1d0b720 100644 --- a/src/_pytest/warning_types.py +++ b/src/_pytest/warning_types.py @@ -1,15 +1,12 @@ from typing import Any from typing import Generic -from typing import TYPE_CHECKING +from typing import Type from typing import TypeVar import attr from _pytest.compat import final -if TYPE_CHECKING: - from typing import Type # noqa: F401 (used in type string) - class PytestWarning(UserWarning): """Base class for all warnings emitted by pytest.""" @@ -105,7 +102,7 @@ class UnformattedWarning(Generic[_W]): as opposed to a direct message. """ - category = attr.ib(type="Type[_W]") + category = attr.ib(type=Type["_W"]) template = attr.ib(type=str) def format(self, **kwargs: Any) -> _W: diff --git a/testing/test_config.py b/testing/test_config.py index 02db737d6b9..02696fff265 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -6,7 +6,7 @@ from typing import List from typing import Sequence from typing import Tuple -from typing import TYPE_CHECKING +from typing import Type import attr import py.path @@ -29,9 +29,6 @@ from _pytest.pathlib import Path from _pytest.pytester import Testdir -if TYPE_CHECKING: - from typing import Type - class TestParseIni: @pytest.mark.parametrize( @@ -1936,7 +1933,7 @@ def test_strtobool(): ], ) def test_parse_warning_filter( - arg: str, escape: bool, expected: "Tuple[str, str, Type[Warning], str, int]" + arg: str, escape: bool, expected: Tuple[str, str, Type[Warning], str, int] ) -> None: assert parse_warning_filter(arg, escape=escape) == expected diff --git a/testing/test_monkeypatch.py b/testing/test_monkeypatch.py index 52636f85123..f149e069561 100644 --- a/testing/test_monkeypatch.py +++ b/testing/test_monkeypatch.py @@ -4,7 +4,7 @@ import textwrap from typing import Dict from typing import Generator -from typing import TYPE_CHECKING +from typing import Type import py @@ -12,9 +12,6 @@ from _pytest.monkeypatch import MonkeyPatch from _pytest.pytester import Testdir -if TYPE_CHECKING: - from typing import Type - @pytest.fixture def mp() -> Generator[MonkeyPatch, None, None]: @@ -354,7 +351,7 @@ class SampleInherit(Sample): @pytest.mark.parametrize( "Sample", [Sample, SampleInherit], ids=["new", "new-inherit"], ) -def test_issue156_undo_staticmethod(Sample: "Type[Sample]") -> None: +def test_issue156_undo_staticmethod(Sample: Type[Sample]) -> None: monkeypatch = MonkeyPatch() monkeypatch.setattr(Sample, "hello", None) diff --git a/testing/test_runner.py b/testing/test_runner.py index dff555534b7..d3b7729f728 100644 --- a/testing/test_runner.py +++ b/testing/test_runner.py @@ -5,7 +5,7 @@ from typing import Dict from typing import List from typing import Tuple -from typing import TYPE_CHECKING +from typing import Type import py @@ -17,9 +17,6 @@ from _pytest.config import ExitCode from _pytest.outcomes import OutcomeException -if TYPE_CHECKING: - from typing import Type - class TestSetupState: def test_setup(self, testdir) -> None: @@ -457,7 +454,7 @@ class TestClass(object): @pytest.mark.parametrize( "reporttype", reporttypes, ids=[x.__name__ for x in reporttypes] ) -def test_report_extra_parameters(reporttype: "Type[reports.BaseReport]") -> None: +def test_report_extra_parameters(reporttype: Type[reports.BaseReport]) -> None: args = list(inspect.signature(reporttype.__init__).parameters.keys())[1:] basekw = dict.fromkeys(args, []) # type: Dict[str, List[object]] report = reporttype(newthing=1, **basekw)