Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

py36+: remove _pytest.compat.overload #7845

Merged
merged 1 commit into from Oct 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/_pytest/_code/code.py
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 4 additions & 5 deletions src/_pytest/_code/source.py
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/assertion/rewrite.py
Expand Up @@ -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"]()
Expand Down
18 changes: 5 additions & 13 deletions src/_pytest/compat.py
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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]):
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions src/_pytest/fixtures.py
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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]]" = ...,
Expand All @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions src/_pytest/main.py
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down
18 changes: 8 additions & 10 deletions src/_pytest/mark/structures.py
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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):
Expand All @@ -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],
Expand Down
8 changes: 4 additions & 4 deletions src/_pytest/monkeypatch.py
Expand Up @@ -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

Expand Down Expand Up @@ -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],
Expand Down
8 changes: 4 additions & 4 deletions src/_pytest/nodes.py
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions src/_pytest/pytester.py
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down