Skip to content

Commit

Permalink
Merge pull request #7645 from bluetech/pylint-abc
Browse files Browse the repository at this point in the history
Don't use NotImplementedError in `@overload`s
  • Loading branch information
bluetech committed Aug 14, 2020
2 parents 2c5403b + f28af14 commit d426a79
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 40 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Expand Up @@ -27,3 +27,4 @@ exclude_lines =
^\s*assert False(,|$)

^\s*if TYPE_CHECKING:
^\s*@overload( |$)
4 changes: 2 additions & 2 deletions src/_pytest/_code/code.py
Expand Up @@ -334,11 +334,11 @@ def cut(

@overload
def __getitem__(self, key: int) -> TracebackEntry:
raise NotImplementedError()
...

@overload # noqa: F811
def __getitem__(self, key: slice) -> "Traceback": # noqa: F811
raise NotImplementedError()
...

def __getitem__( # noqa: F811
self, key: Union[int, slice]
Expand Down
4 changes: 2 additions & 2 deletions src/_pytest/_code/source.py
Expand Up @@ -44,11 +44,11 @@ def __eq__(self, other: object) -> bool:

@overload
def __getitem__(self, key: int) -> str:
raise NotImplementedError()
...

@overload # noqa: F811
def __getitem__(self, key: slice) -> "Source": # noqa: F811
raise NotImplementedError()
...

def __getitem__(self, key: Union[int, slice]) -> Union[str, "Source"]: # noqa: F811
if isinstance(key, int):
Expand Down
4 changes: 2 additions & 2 deletions src/_pytest/compat.py
Expand Up @@ -378,13 +378,13 @@ def __init__(self, func: Callable[[_S], _T]) -> None:
def __get__(
self, instance: None, owner: Optional["Type[_S]"] = ...
) -> "cached_property[_S, _T]":
raise NotImplementedError()
...

@overload # noqa: F811
def __get__( # noqa: F811
self, instance: _S, owner: Optional["Type[_S]"] = ...
) -> _T:
raise NotImplementedError()
...

def __get__(self, instance, owner=None): # noqa: F811
if instance is None:
Expand Down
4 changes: 2 additions & 2 deletions src/_pytest/fixtures.py
Expand Up @@ -1230,7 +1230,7 @@ def fixture(
] = ...,
name: Optional[str] = ...
) -> _FixtureFunction:
raise NotImplementedError()
...


@overload # noqa: F811
Expand All @@ -1248,7 +1248,7 @@ def fixture( # noqa: F811
] = ...,
name: Optional[str] = None
) -> FixtureFunctionMarker:
raise NotImplementedError()
...


def fixture( # noqa: F811
Expand Down
8 changes: 4 additions & 4 deletions src/_pytest/main.py
Expand Up @@ -501,13 +501,13 @@ def gethookproxy(self, fspath: py.path.local):
def perform_collect(
self, args: Optional[Sequence[str]] = ..., genitems: "Literal[True]" = ...
) -> Sequence[nodes.Item]:
raise NotImplementedError()
...

@overload # noqa: F811
def perform_collect( # noqa: F811
self, args: Optional[Sequence[str]] = ..., genitems: bool = ...
) -> Sequence[Union[nodes.Item, nodes.Collector]]:
raise NotImplementedError()
...

def perform_collect( # noqa: F811
self, args: Optional[Sequence[str]] = None, genitems: bool = True
Expand All @@ -528,13 +528,13 @@ def perform_collect( # noqa: F811
def _perform_collect(
self, args: Optional[Sequence[str]], genitems: "Literal[True]"
) -> List[nodes.Item]:
raise NotImplementedError()
...

@overload # noqa: F811
def _perform_collect( # noqa: F811
self, args: Optional[Sequence[str]], genitems: bool
) -> Union[List[Union[nodes.Item]], List[Union[nodes.Item, nodes.Collector]]]:
raise NotImplementedError()
...

def _perform_collect( # noqa: F811
self, args: Optional[Sequence[str]], genitems: bool
Expand Down
20 changes: 10 additions & 10 deletions src/_pytest/mark/structures.py
Expand Up @@ -327,13 +327,13 @@ def with_args(self, *args: object, **kwargs: object) -> "MarkDecorator":
# the first match so it works out even if we break the rules.
@overload
def __call__(self, arg: _Markable) -> _Markable: # type: ignore[misc]
raise NotImplementedError()
pass

@overload # noqa: F811
def __call__( # noqa: F811
self, *args: object, **kwargs: object
) -> "MarkDecorator":
raise NotImplementedError()
pass

def __call__(self, *args: object, **kwargs: object): # noqa: F811
"""Call the MarkDecorator."""
Expand Down Expand Up @@ -388,11 +388,11 @@ def store_mark(obj, mark: Mark) -> None:
class _SkipMarkDecorator(MarkDecorator):
@overload # type: ignore[override,misc]
def __call__(self, arg: _Markable) -> _Markable:
raise NotImplementedError()
...

@overload # noqa: F811
def __call__(self, reason: str = ...) -> "MarkDecorator": # noqa: F811
raise NotImplementedError()
...

class _SkipifMarkDecorator(MarkDecorator):
def __call__( # type: ignore[override]
Expand All @@ -401,12 +401,12 @@ def __call__( # type: ignore[override]
*conditions: Union[str, bool],
reason: str = ...
) -> MarkDecorator:
raise NotImplementedError()
...

class _XfailMarkDecorator(MarkDecorator):
@overload # type: ignore[override,misc]
def __call__(self, arg: _Markable) -> _Markable:
raise NotImplementedError()
...

@overload # noqa: F811
def __call__( # noqa: F811
Expand All @@ -420,7 +420,7 @@ def __call__( # noqa: F811
] = ...,
strict: bool = ...
) -> MarkDecorator:
raise NotImplementedError()
...

class _ParametrizeMarkDecorator(MarkDecorator):
def __call__( # type: ignore[override]
Expand All @@ -437,19 +437,19 @@ def __call__( # type: ignore[override]
] = ...,
scope: Optional[_Scope] = ...
) -> MarkDecorator:
raise NotImplementedError()
...

class _UsefixturesMarkDecorator(MarkDecorator):
def __call__( # type: ignore[override]
self, *fixtures: str
) -> MarkDecorator:
raise NotImplementedError()
...

class _FilterwarningsMarkDecorator(MarkDecorator):
def __call__( # type: ignore[override]
self, *filters: str
) -> MarkDecorator:
raise NotImplementedError()
...


class MarkGenerator:
Expand Down
4 changes: 2 additions & 2 deletions src/_pytest/monkeypatch.py
Expand Up @@ -152,13 +152,13 @@ def test_partial(monkeypatch):
def setattr(
self, target: str, name: object, value: Notset = ..., raising: bool = ...,
) -> None:
raise NotImplementedError()
...

@overload # noqa: F811
def setattr( # noqa: F811
self, target: object, name: str, value: object, raising: bool = ...,
) -> None:
raise NotImplementedError()
...

def setattr( # noqa: F811
self,
Expand Down
4 changes: 2 additions & 2 deletions src/_pytest/nodes.py
Expand Up @@ -311,11 +311,11 @@ def iter_markers_with_node(

@overload
def get_closest_marker(self, name: str) -> Optional[Mark]:
raise NotImplementedError()
...

@overload # noqa: F811
def get_closest_marker(self, name: str, default: Mark) -> Mark: # noqa: F811
raise NotImplementedError()
...

def get_closest_marker( # noqa: F811
self, name: str, default: Optional[Mark] = None
Expand Down
14 changes: 7 additions & 7 deletions src/_pytest/pytester.py
Expand Up @@ -201,7 +201,7 @@ def __repr__(self) -> str:
if TYPE_CHECKING:
# The class has undetermined attributes, this tells mypy about it.
def __getattr__(self, key: str):
raise NotImplementedError()
...


class HookRecorder:
Expand Down Expand Up @@ -274,13 +274,13 @@ def getcall(self, name: str) -> ParsedCall:
def getreports(
self, names: "Literal['pytest_collectreport']",
) -> Sequence[CollectReport]:
raise NotImplementedError()
...

@overload # noqa: F811
def getreports( # noqa: F811
self, names: "Literal['pytest_runtest_logreport']",
) -> Sequence[TestReport]:
raise NotImplementedError()
...

@overload # noqa: F811
def getreports( # noqa: F811
Expand All @@ -290,7 +290,7 @@ def getreports( # noqa: F811
"pytest_runtest_logreport",
),
) -> Sequence[Union[CollectReport, TestReport]]:
raise NotImplementedError()
...

def getreports( # noqa: F811
self,
Expand Down Expand Up @@ -337,13 +337,13 @@ def matchreport(
def getfailures(
self, names: "Literal['pytest_collectreport']",
) -> Sequence[CollectReport]:
raise NotImplementedError()
...

@overload # noqa: F811
def getfailures( # noqa: F811
self, names: "Literal['pytest_runtest_logreport']",
) -> Sequence[TestReport]:
raise NotImplementedError()
...

@overload # noqa: F811
def getfailures( # noqa: F811
Expand All @@ -353,7 +353,7 @@ def getfailures( # noqa: F811
"pytest_runtest_logreport",
),
) -> Sequence[Union[CollectReport, TestReport]]:
raise NotImplementedError()
...

def getfailures( # noqa: F811
self,
Expand Down
4 changes: 2 additions & 2 deletions src/_pytest/python_api.py
Expand Up @@ -529,7 +529,7 @@ def raises(
*,
match: "Optional[Union[str, Pattern[str]]]" = ...
) -> "RaisesContext[_E]":
... # pragma: no cover
...


@overload # noqa: F811
Expand All @@ -539,7 +539,7 @@ def raises( # noqa: F811
*args: Any,
**kwargs: Any
) -> _pytest._code.ExceptionInfo[_E]:
... # pragma: no cover
...


def raises( # noqa: F811
Expand Down
8 changes: 4 additions & 4 deletions src/_pytest/recwarn.py
Expand Up @@ -42,14 +42,14 @@ def recwarn() -> Generator["WarningsRecorder", None, None]:
def deprecated_call(
*, match: Optional[Union[str, "Pattern[str]"]] = ...
) -> "WarningsRecorder":
raise NotImplementedError()
...


@overload # noqa: F811
def deprecated_call( # noqa: F811
func: Callable[..., T], *args: Any, **kwargs: Any
) -> T:
raise NotImplementedError()
...


def deprecated_call( # noqa: F811
Expand Down Expand Up @@ -89,7 +89,7 @@ def warns(
*,
match: "Optional[Union[str, Pattern[str]]]" = ...
) -> "WarningsChecker":
raise NotImplementedError()
...


@overload # noqa: F811
Expand All @@ -99,7 +99,7 @@ def warns( # noqa: F811
*args: Any,
**kwargs: Any
) -> T:
raise NotImplementedError()
...


def warns( # noqa: F811
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/reports.py
Expand Up @@ -71,7 +71,7 @@ def __init__(self, **kw: Any) -> None:
if TYPE_CHECKING:
# Can have arbitrary fields given to __init__().
def __getattr__(self, key: str) -> Any:
raise NotImplementedError()
...

def toterminal(self, out: TerminalWriter) -> None:
if hasattr(self, "node"):
Expand Down

0 comments on commit d426a79

Please sign in to comment.