From 7f0d2beb508068145a7e929fc760726e1a450915 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Fri, 2 Oct 2020 13:07:37 -0700 Subject: [PATCH] py36+: remove _pytest.compat.overload --- src/_pytest/_code/code.py | 10 ++++------ src/_pytest/_code/source.py | 9 ++++----- src/_pytest/assertion/rewrite.py | 2 +- src/_pytest/compat.py | 18 +++++------------- src/_pytest/fixtures.py | 10 +++++----- src/_pytest/main.py | 8 ++++---- src/_pytest/mark/structures.py | 18 ++++++++---------- src/_pytest/monkeypatch.py | 8 ++++---- src/_pytest/nodes.py | 8 ++++---- src/_pytest/pytester.py | 22 +++++++++++----------- src/_pytest/python_api.py | 8 ++++---- src/_pytest/recwarn.py | 16 +++++++--------- 12 files changed, 61 insertions(+), 76 deletions(-) diff --git a/src/_pytest/_code/code.py b/src/_pytest/_code/code.py index ce63b4b16bf..0f13e699bbf 100644 --- a/src/_pytest/_code/code.py +++ b/src/_pytest/_code/code.py @@ -17,6 +17,7 @@ from typing import List from typing import Mapping from typing import Optional +from typing import overload from typing import Pattern from typing import Sequence from typing import Set @@ -41,7 +42,6 @@ from _pytest._io.saferepr import saferepr from _pytest.compat import final from _pytest.compat import get_real_func -from _pytest.compat import overload from _pytest.pathlib import Path if TYPE_CHECKING: @@ -346,13 +346,11 @@ def cut( def __getitem__(self, key: int) -> TracebackEntry: ... - @overload # noqa: F811 - def __getitem__(self, key: slice) -> "Traceback": # noqa: F811 + @overload + def __getitem__(self, key: slice) -> "Traceback": ... - def __getitem__( # noqa: F811 - self, key: Union[int, slice] - ) -> Union[TracebackEntry, "Traceback"]: + def __getitem__(self, key: Union[int, slice]) -> Union[TracebackEntry, "Traceback"]: if isinstance(key, slice): return self.__class__(super().__getitem__(key)) else: diff --git a/src/_pytest/_code/source.py b/src/_pytest/_code/source.py index 4ba18aa6361..028ff48a3fe 100644 --- a/src/_pytest/_code/source.py +++ b/src/_pytest/_code/source.py @@ -8,11 +8,10 @@ from typing import Iterator from typing import List from typing import Optional +from typing import overload from typing import Tuple from typing import Union -from _pytest.compat import overload - class Source: """An immutable object holding a source code fragment. @@ -46,11 +45,11 @@ def __eq__(self, other: object) -> bool: def __getitem__(self, key: int) -> str: ... - @overload # noqa: F811 - def __getitem__(self, key: slice) -> "Source": # noqa: F811 + @overload + def __getitem__(self, key: slice) -> "Source": ... - def __getitem__(self, key: Union[int, slice]) -> Union[str, "Source"]: # noqa: F811 + def __getitem__(self, key: Union[int, slice]) -> Union[str, "Source"]: if isinstance(key, int): return self.lines[key] else: diff --git a/src/_pytest/assertion/rewrite.py b/src/_pytest/assertion/rewrite.py index 28a206c27a3..f50ef232a17 100644 --- a/src/_pytest/assertion/rewrite.py +++ b/src/_pytest/assertion/rewrite.py @@ -41,7 +41,7 @@ from _pytest.store import StoreKey if TYPE_CHECKING: - from _pytest.assertion import AssertionState # noqa: F401 + from _pytest.assertion import AssertionState assertstate_key = StoreKey["AssertionState"]() diff --git a/src/_pytest/compat.py b/src/_pytest/compat.py index 8fa58bccf16..ef4164268e2 100644 --- a/src/_pytest/compat.py +++ b/src/_pytest/compat.py @@ -11,7 +11,6 @@ from typing import Callable from typing import Generic from typing import Optional -from typing import overload as overload from typing import Tuple from typing import TYPE_CHECKING from typing import TypeVar @@ -326,12 +325,6 @@ def safe_isclass(obj: object) -> bool: return False -if sys.version_info < (3, 5, 2): - - def overload(f): # noqa: F811 - return f - - if TYPE_CHECKING: if sys.version_info >= (3, 8): from typing import final as final @@ -341,13 +334,14 @@ def overload(f): # noqa: F811 from typing import final as final else: - def final(f): # noqa: F811 + def final(f): return f if sys.version_info >= (3, 8): from functools import cached_property as cached_property else: + from typing import overload from typing import Type class cached_property(Generic[_S, _T]): @@ -363,13 +357,11 @@ def __get__( ) -> "cached_property[_S, _T]": ... - @overload # noqa: F811 - def __get__( # noqa: F811 - self, instance: _S, owner: Optional[Type[_S]] = ... - ) -> _T: + @overload + def __get__(self, instance: _S, owner: Optional[Type[_S]] = ...) -> _T: ... - def __get__(self, instance, owner=None): # noqa: F811 + def __get__(self, instance, owner=None): if instance is None: return self value = instance.__dict__[self.func.__name__] = self.func(instance) diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index d793ea37f1e..84e748941b2 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -16,6 +16,7 @@ from typing import Iterator from typing import List from typing import Optional +from typing import overload from typing import Sequence from typing import Set from typing import Tuple @@ -43,7 +44,6 @@ from _pytest.compat import is_generator from _pytest.compat import NOTSET from _pytest.compat import order_preserving_dict -from _pytest.compat import overload from _pytest.compat import safe_getattr from _pytest.config import _PluggyPlugin from _pytest.config import Config @@ -462,7 +462,7 @@ def _getnextfixturedef(self, argname: str) -> "FixtureDef[Any]": @property def config(self) -> Config: """The pytest config object associated with this request.""" - return self._pyfuncitem.config # type: ignore[no-any-return] # noqa: F723 + return self._pyfuncitem.config # type: ignore[no-any-return] @property def function(self): @@ -1225,8 +1225,8 @@ def fixture( ... -@overload # noqa: F811 -def fixture( # noqa: F811 +@overload +def fixture( fixture_function: None = ..., *, scope: "Union[_Scope, Callable[[str, Config], _Scope]]" = ..., @@ -1243,7 +1243,7 @@ def fixture( # noqa: F811 ... -def fixture( # noqa: F811 +def fixture( fixture_function: Optional[_FixtureFunction] = None, *, scope: "Union[_Scope, Callable[[str, Config], _Scope]]" = "function", diff --git a/src/_pytest/main.py b/src/_pytest/main.py index 31dc28e5d0e..624f8abb2a4 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -11,6 +11,7 @@ from typing import Iterator from typing import List from typing import Optional +from typing import overload from typing import Sequence from typing import Set from typing import Tuple @@ -24,7 +25,6 @@ import _pytest._code from _pytest import nodes from _pytest.compat import final -from _pytest.compat import overload from _pytest.config import Config from _pytest.config import directory_arg from _pytest.config import ExitCode @@ -562,13 +562,13 @@ def perform_collect( ) -> Sequence[nodes.Item]: ... - @overload # noqa: F811 - def perform_collect( # noqa: F811 + @overload + def perform_collect( self, args: Optional[Sequence[str]] = ..., genitems: bool = ... ) -> Sequence[Union[nodes.Item, nodes.Collector]]: ... - def perform_collect( # noqa: F811 + def perform_collect( self, args: Optional[Sequence[str]] = None, genitems: bool = True ) -> Sequence[Union[nodes.Item, nodes.Collector]]: """Perform the collection phase for this session. diff --git a/src/_pytest/mark/structures.py b/src/_pytest/mark/structures.py index 23c552d9897..8542434a52b 100644 --- a/src/_pytest/mark/structures.py +++ b/src/_pytest/mark/structures.py @@ -11,6 +11,7 @@ from typing import MutableMapping from typing import NamedTuple from typing import Optional +from typing import overload from typing import Sequence from typing import Set from typing import Tuple @@ -26,7 +27,6 @@ from ..compat import final from ..compat import NOTSET from ..compat import NotSetType -from ..compat import overload from _pytest.config import Config from _pytest.outcomes import fail from _pytest.warning_types import PytestUnknownMarkWarning @@ -330,13 +330,11 @@ def with_args(self, *args: object, **kwargs: object) -> "MarkDecorator": def __call__(self, arg: _Markable) -> _Markable: # type: ignore[misc] pass - @overload # noqa: F811 - def __call__( # noqa: F811 - self, *args: object, **kwargs: object - ) -> "MarkDecorator": + @overload + def __call__(self, *args: object, **kwargs: object) -> "MarkDecorator": pass - def __call__(self, *args: object, **kwargs: object): # noqa: F811 + def __call__(self, *args: object, **kwargs: object): """Call the MarkDecorator.""" if args and not kwargs: func = args[0] @@ -391,8 +389,8 @@ class _SkipMarkDecorator(MarkDecorator): def __call__(self, arg: _Markable) -> _Markable: ... - @overload # noqa: F811 - def __call__(self, reason: str = ...) -> "MarkDecorator": # noqa: F811 + @overload + def __call__(self, reason: str = ...) -> "MarkDecorator": ... class _SkipifMarkDecorator(MarkDecorator): @@ -409,8 +407,8 @@ class _XfailMarkDecorator(MarkDecorator): def __call__(self, arg: _Markable) -> _Markable: ... - @overload # noqa: F811 - def __call__( # noqa: F811 + @overload + def __call__( self, condition: Union[str, bool] = ..., *conditions: Union[str, bool], diff --git a/src/_pytest/monkeypatch.py b/src/_pytest/monkeypatch.py index bbd96779da5..8251fd9bd1c 100644 --- a/src/_pytest/monkeypatch.py +++ b/src/_pytest/monkeypatch.py @@ -9,13 +9,13 @@ from typing import List from typing import MutableMapping from typing import Optional +from typing import overload from typing import Tuple from typing import TypeVar from typing import Union import pytest from _pytest.compat import final -from _pytest.compat import overload from _pytest.fixtures import fixture from _pytest.pathlib import Path @@ -156,13 +156,13 @@ def setattr( ) -> None: ... - @overload # noqa: F811 - def setattr( # noqa: F811 + @overload + def setattr( self, target: object, name: str, value: object, raising: bool = ..., ) -> None: ... - def setattr( # noqa: F811 + def setattr( self, target: Union[str, object], name: Union[object, str], diff --git a/src/_pytest/nodes.py b/src/_pytest/nodes.py index c8375e7cdb8..f3568b1677e 100644 --- a/src/_pytest/nodes.py +++ b/src/_pytest/nodes.py @@ -8,6 +8,7 @@ from typing import Iterator from typing import List from typing import Optional +from typing import overload from typing import Set from typing import Tuple from typing import Type @@ -22,7 +23,6 @@ from _pytest._code.code import ExceptionInfo from _pytest._code.code import TerminalRepr from _pytest.compat import cached_property -from _pytest.compat import overload from _pytest.config import Config from _pytest.config import ConftestImportFailure from _pytest.deprecated import FSCOLLECTOR_GETHOOKPROXY_ISINITPATH @@ -316,11 +316,11 @@ def iter_markers_with_node( def get_closest_marker(self, name: str) -> Optional[Mark]: ... - @overload # noqa: F811 - def get_closest_marker(self, name: str, default: Mark) -> Mark: # noqa: F811 + @overload + def get_closest_marker(self, name: str, default: Mark) -> Mark: ... - def get_closest_marker( # noqa: F811 + def get_closest_marker( self, name: str, default: Optional[Mark] = None ) -> Optional[Mark]: """Return the first marker matching the name, from closest (for diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index 29690f0f011..df549ea1d6e 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -16,6 +16,7 @@ from typing import Iterable from typing import List from typing import Optional +from typing import overload from typing import Sequence from typing import Tuple from typing import Type @@ -31,7 +32,6 @@ from _pytest._code import Source from _pytest.capture import _get_multicapture from _pytest.compat import final -from _pytest.compat import overload from _pytest.config import _PluggyPlugin from _pytest.config import Config from _pytest.config import ExitCode @@ -277,14 +277,14 @@ def getreports( ) -> Sequence[CollectReport]: ... - @overload # noqa: F811 - def getreports( # noqa: F811 + @overload + def getreports( self, names: "Literal['pytest_runtest_logreport']", ) -> Sequence[TestReport]: ... - @overload # noqa: F811 - def getreports( # noqa: F811 + @overload + def getreports( self, names: Union[str, Iterable[str]] = ( "pytest_collectreport", @@ -293,7 +293,7 @@ def getreports( # noqa: F811 ) -> Sequence[Union[CollectReport, TestReport]]: ... - def getreports( # noqa: F811 + def getreports( self, names: Union[str, Iterable[str]] = ( "pytest_collectreport", @@ -340,14 +340,14 @@ def getfailures( ) -> Sequence[CollectReport]: ... - @overload # noqa: F811 - def getfailures( # noqa: F811 + @overload + def getfailures( self, names: "Literal['pytest_runtest_logreport']", ) -> Sequence[TestReport]: ... - @overload # noqa: F811 - def getfailures( # noqa: F811 + @overload + def getfailures( self, names: Union[str, Iterable[str]] = ( "pytest_collectreport", @@ -356,7 +356,7 @@ def getfailures( # noqa: F811 ) -> Sequence[Union[CollectReport, TestReport]]: ... - def getfailures( # noqa: F811 + def getfailures( self, names: Union[str, Iterable[str]] = ( "pytest_collectreport", diff --git a/src/_pytest/python_api.py b/src/_pytest/python_api.py index b1f09030ade..3c1993be579 100644 --- a/src/_pytest/python_api.py +++ b/src/_pytest/python_api.py @@ -11,6 +11,7 @@ from typing import cast from typing import Generic from typing import Optional +from typing import overload from typing import Pattern from typing import Tuple from typing import Type @@ -19,7 +20,6 @@ import _pytest._code from _pytest.compat import final -from _pytest.compat import overload from _pytest.compat import STRING_TYPES from _pytest.outcomes import fail @@ -564,8 +564,8 @@ def raises( ... -@overload # noqa: F811 -def raises( # noqa: F811 +@overload +def raises( expected_exception: Union[Type[_E], Tuple[Type[_E], ...]], func: Callable[..., Any], *args: Any, @@ -574,7 +574,7 @@ def raises( # noqa: F811 ... -def raises( # noqa: F811 +def raises( 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`` diff --git a/src/_pytest/recwarn.py b/src/_pytest/recwarn.py index a455e9e57f0..cc499138c77 100644 --- a/src/_pytest/recwarn.py +++ b/src/_pytest/recwarn.py @@ -8,6 +8,7 @@ from typing import Iterator from typing import List from typing import Optional +from typing import overload from typing import Pattern from typing import Tuple from typing import Type @@ -15,7 +16,6 @@ from typing import Union from _pytest.compat import final -from _pytest.compat import overload from _pytest.fixtures import fixture from _pytest.outcomes import fail @@ -43,14 +43,12 @@ def deprecated_call( ... -@overload # noqa: F811 -def deprecated_call( # noqa: F811 - func: Callable[..., T], *args: Any, **kwargs: Any -) -> T: +@overload +def deprecated_call(func: Callable[..., T], *args: Any, **kwargs: Any) -> T: ... -def deprecated_call( # noqa: F811 +def deprecated_call( func: Optional[Callable[..., Any]] = None, *args: Any, **kwargs: Any ) -> Union["WarningsRecorder", Any]: """Assert that code produces a ``DeprecationWarning`` or ``PendingDeprecationWarning``. @@ -90,8 +88,8 @@ def warns( ... -@overload # noqa: F811 -def warns( # noqa: F811 +@overload +def warns( expected_warning: Optional[Union[Type[Warning], Tuple[Type[Warning], ...]]], func: Callable[..., T], *args: Any, @@ -100,7 +98,7 @@ def warns( # noqa: F811 ... -def warns( # noqa: F811 +def warns( expected_warning: Optional[Union[Type[Warning], Tuple[Type[Warning], ...]]], *args: Any, match: Optional[Union[str, Pattern[str]]] = None,