Merge pull request #7845 from pytest-dev/py36_overload

py36+: remove _pytest.compat.overload
This commit is contained in:
Anthony Sottile 2020-10-03 11:45:29 -07:00 committed by GitHub
commit 3b957c2244
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 61 additions and 76 deletions

View File

@ -17,6 +17,7 @@ from typing import Iterable
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 safeformat
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 @@ class Traceback(List[TracebackEntry]):
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:

View File

@ -8,11 +8,10 @@ from typing import Iterable
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 @@ class Source:
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:

View File

@ -41,7 +41,7 @@ from _pytest.pathlib import PurePath
from _pytest.store import StoreKey
if TYPE_CHECKING:
from _pytest.assertion import AssertionState # noqa: F401
from _pytest.assertion import AssertionState
assertstate_key = StoreKey["AssertionState"]()

View File

@ -11,7 +11,6 @@ from typing import Any
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 @@ elif sys.version_info >= (3, 8):
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 @@ else:
) -> "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)

View File

@ -16,6 +16,7 @@ from typing import Iterable
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 getlocation
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 @@ class FixtureRequest:
@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",

View File

@ -11,6 +11,7 @@ from typing import FrozenSet
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 py
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 @@ class Session(nodes.FSCollector):
) -> 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.

View File

@ -11,6 +11,7 @@ from typing import Mapping
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 ascii_escaped
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 @@ class 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 @@ if TYPE_CHECKING:
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 @@ if TYPE_CHECKING:
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],

View File

@ -9,13 +9,13 @@ from typing import Generator
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 @@ class MonkeyPatch:
) -> 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],

View File

@ -8,6 +8,7 @@ from typing import Iterable
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 import getfslineno
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 @@ class Node(metaclass=NodeMeta):
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

View File

@ -16,6 +16,7 @@ from typing import Generator
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 import timing
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 @@ class HookRecorder:
) -> 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 @@ class HookRecorder:
) -> Sequence[Union[CollectReport, TestReport]]:
...
def getreports( # noqa: F811
def getreports(
self,
names: Union[str, Iterable[str]] = (
"pytest_collectreport",
@ -340,14 +340,14 @@ class HookRecorder:
) -> 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 @@ class HookRecorder:
) -> Sequence[Union[CollectReport, TestReport]]:
...
def getfailures( # noqa: F811
def getfailures(
self,
names: Union[str, Iterable[str]] = (
"pytest_collectreport",

View File

@ -11,6 +11,7 @@ from typing import Callable
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 @@ from typing import Union
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``

View File

@ -8,6 +8,7 @@ from typing import Generator
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 TypeVar
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,