Don't use NotImplementedError in `@overload`s

We used it as a shortcut for avoiding coverage, but pylint has a special
interpretation of it as an abstract method which we don't want.
This commit is contained in:
Ran Benita 2020-08-14 13:35:34 +03:00
parent 2c5403b951
commit f28af14457
13 changed files with 41 additions and 40 deletions

View File

@ -27,3 +27,4 @@ exclude_lines =
^\s*assert False(,|$) ^\s*assert False(,|$)
^\s*if TYPE_CHECKING: ^\s*if TYPE_CHECKING:
^\s*@overload( |$)

View File

@ -334,11 +334,11 @@ class Traceback(List[TracebackEntry]):
@overload @overload
def __getitem__(self, key: int) -> TracebackEntry: def __getitem__(self, key: int) -> TracebackEntry:
raise NotImplementedError() ...
@overload # noqa: F811 @overload # noqa: F811
def __getitem__(self, key: slice) -> "Traceback": # noqa: F811 def __getitem__(self, key: slice) -> "Traceback": # noqa: F811
raise NotImplementedError() ...
def __getitem__( # noqa: F811 def __getitem__( # noqa: F811
self, key: Union[int, slice] self, key: Union[int, slice]

View File

@ -44,11 +44,11 @@ class Source:
@overload @overload
def __getitem__(self, key: int) -> str: def __getitem__(self, key: int) -> str:
raise NotImplementedError() ...
@overload # noqa: F811 @overload # noqa: F811
def __getitem__(self, key: slice) -> "Source": # noqa: F811 def __getitem__(self, key: slice) -> "Source": # noqa: F811
raise NotImplementedError() ...
def __getitem__(self, key: Union[int, slice]) -> Union[str, "Source"]: # noqa: F811 def __getitem__(self, key: Union[int, slice]) -> Union[str, "Source"]: # noqa: F811
if isinstance(key, int): if isinstance(key, int):

View File

@ -378,13 +378,13 @@ else:
def __get__( def __get__(
self, instance: None, owner: Optional["Type[_S]"] = ... self, instance: None, owner: Optional["Type[_S]"] = ...
) -> "cached_property[_S, _T]": ) -> "cached_property[_S, _T]":
raise NotImplementedError() ...
@overload # noqa: F811 @overload # noqa: F811
def __get__( # noqa: F811 def __get__( # noqa: F811
self, instance: _S, owner: Optional["Type[_S]"] = ... self, instance: _S, owner: Optional["Type[_S]"] = ...
) -> _T: ) -> _T:
raise NotImplementedError() ...
def __get__(self, instance, owner=None): # noqa: F811 def __get__(self, instance, owner=None): # noqa: F811
if instance is None: if instance is None:

View File

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

View File

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

View File

@ -327,13 +327,13 @@ class MarkDecorator:
# the first match so it works out even if we break the rules. # the first match so it works out even if we break the rules.
@overload @overload
def __call__(self, arg: _Markable) -> _Markable: # type: ignore[misc] def __call__(self, arg: _Markable) -> _Markable: # type: ignore[misc]
raise NotImplementedError() pass
@overload # noqa: F811 @overload # noqa: F811
def __call__( # noqa: F811 def __call__( # noqa: F811
self, *args: object, **kwargs: object self, *args: object, **kwargs: object
) -> "MarkDecorator": ) -> "MarkDecorator":
raise NotImplementedError() pass
def __call__(self, *args: object, **kwargs: object): # noqa: F811 def __call__(self, *args: object, **kwargs: object): # noqa: F811
"""Call the MarkDecorator.""" """Call the MarkDecorator."""
@ -388,11 +388,11 @@ if TYPE_CHECKING:
class _SkipMarkDecorator(MarkDecorator): class _SkipMarkDecorator(MarkDecorator):
@overload # type: ignore[override,misc] @overload # type: ignore[override,misc]
def __call__(self, arg: _Markable) -> _Markable: def __call__(self, arg: _Markable) -> _Markable:
raise NotImplementedError() ...
@overload # noqa: F811 @overload # noqa: F811
def __call__(self, reason: str = ...) -> "MarkDecorator": # noqa: F811 def __call__(self, reason: str = ...) -> "MarkDecorator": # noqa: F811
raise NotImplementedError() ...
class _SkipifMarkDecorator(MarkDecorator): class _SkipifMarkDecorator(MarkDecorator):
def __call__( # type: ignore[override] def __call__( # type: ignore[override]
@ -401,12 +401,12 @@ if TYPE_CHECKING:
*conditions: Union[str, bool], *conditions: Union[str, bool],
reason: str = ... reason: str = ...
) -> MarkDecorator: ) -> MarkDecorator:
raise NotImplementedError() ...
class _XfailMarkDecorator(MarkDecorator): class _XfailMarkDecorator(MarkDecorator):
@overload # type: ignore[override,misc] @overload # type: ignore[override,misc]
def __call__(self, arg: _Markable) -> _Markable: def __call__(self, arg: _Markable) -> _Markable:
raise NotImplementedError() ...
@overload # noqa: F811 @overload # noqa: F811
def __call__( # noqa: F811 def __call__( # noqa: F811
@ -420,7 +420,7 @@ if TYPE_CHECKING:
] = ..., ] = ...,
strict: bool = ... strict: bool = ...
) -> MarkDecorator: ) -> MarkDecorator:
raise NotImplementedError() ...
class _ParametrizeMarkDecorator(MarkDecorator): class _ParametrizeMarkDecorator(MarkDecorator):
def __call__( # type: ignore[override] def __call__( # type: ignore[override]
@ -437,19 +437,19 @@ if TYPE_CHECKING:
] = ..., ] = ...,
scope: Optional[_Scope] = ... scope: Optional[_Scope] = ...
) -> MarkDecorator: ) -> MarkDecorator:
raise NotImplementedError() ...
class _UsefixturesMarkDecorator(MarkDecorator): class _UsefixturesMarkDecorator(MarkDecorator):
def __call__( # type: ignore[override] def __call__( # type: ignore[override]
self, *fixtures: str self, *fixtures: str
) -> MarkDecorator: ) -> MarkDecorator:
raise NotImplementedError() ...
class _FilterwarningsMarkDecorator(MarkDecorator): class _FilterwarningsMarkDecorator(MarkDecorator):
def __call__( # type: ignore[override] def __call__( # type: ignore[override]
self, *filters: str self, *filters: str
) -> MarkDecorator: ) -> MarkDecorator:
raise NotImplementedError() ...
class MarkGenerator: class MarkGenerator:

View File

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

View File

@ -311,11 +311,11 @@ class Node(metaclass=NodeMeta):
@overload @overload
def get_closest_marker(self, name: str) -> Optional[Mark]: def get_closest_marker(self, name: str) -> Optional[Mark]:
raise NotImplementedError() ...
@overload # noqa: F811 @overload # noqa: F811
def get_closest_marker(self, name: str, default: Mark) -> Mark: # noqa: F811 def get_closest_marker(self, name: str, default: Mark) -> Mark: # noqa: F811
raise NotImplementedError() ...
def get_closest_marker( # noqa: F811 def get_closest_marker( # noqa: F811
self, name: str, default: Optional[Mark] = None self, name: str, default: Optional[Mark] = None

View File

@ -201,7 +201,7 @@ class ParsedCall:
if TYPE_CHECKING: if TYPE_CHECKING:
# The class has undetermined attributes, this tells mypy about it. # The class has undetermined attributes, this tells mypy about it.
def __getattr__(self, key: str): def __getattr__(self, key: str):
raise NotImplementedError() ...
class HookRecorder: class HookRecorder:
@ -274,13 +274,13 @@ class HookRecorder:
def getreports( def getreports(
self, names: "Literal['pytest_collectreport']", self, names: "Literal['pytest_collectreport']",
) -> Sequence[CollectReport]: ) -> Sequence[CollectReport]:
raise NotImplementedError() ...
@overload # noqa: F811 @overload # noqa: F811
def getreports( # noqa: F811 def getreports( # noqa: F811
self, names: "Literal['pytest_runtest_logreport']", self, names: "Literal['pytest_runtest_logreport']",
) -> Sequence[TestReport]: ) -> Sequence[TestReport]:
raise NotImplementedError() ...
@overload # noqa: F811 @overload # noqa: F811
def getreports( # noqa: F811 def getreports( # noqa: F811
@ -290,7 +290,7 @@ class HookRecorder:
"pytest_runtest_logreport", "pytest_runtest_logreport",
), ),
) -> Sequence[Union[CollectReport, TestReport]]: ) -> Sequence[Union[CollectReport, TestReport]]:
raise NotImplementedError() ...
def getreports( # noqa: F811 def getreports( # noqa: F811
self, self,
@ -337,13 +337,13 @@ class HookRecorder:
def getfailures( def getfailures(
self, names: "Literal['pytest_collectreport']", self, names: "Literal['pytest_collectreport']",
) -> Sequence[CollectReport]: ) -> Sequence[CollectReport]:
raise NotImplementedError() ...
@overload # noqa: F811 @overload # noqa: F811
def getfailures( # noqa: F811 def getfailures( # noqa: F811
self, names: "Literal['pytest_runtest_logreport']", self, names: "Literal['pytest_runtest_logreport']",
) -> Sequence[TestReport]: ) -> Sequence[TestReport]:
raise NotImplementedError() ...
@overload # noqa: F811 @overload # noqa: F811
def getfailures( # noqa: F811 def getfailures( # noqa: F811
@ -353,7 +353,7 @@ class HookRecorder:
"pytest_runtest_logreport", "pytest_runtest_logreport",
), ),
) -> Sequence[Union[CollectReport, TestReport]]: ) -> Sequence[Union[CollectReport, TestReport]]:
raise NotImplementedError() ...
def getfailures( # noqa: F811 def getfailures( # noqa: F811
self, self,

View File

@ -529,7 +529,7 @@ def raises(
*, *,
match: "Optional[Union[str, Pattern[str]]]" = ... match: "Optional[Union[str, Pattern[str]]]" = ...
) -> "RaisesContext[_E]": ) -> "RaisesContext[_E]":
... # pragma: no cover ...
@overload # noqa: F811 @overload # noqa: F811
@ -539,7 +539,7 @@ def raises( # noqa: F811
*args: Any, *args: Any,
**kwargs: Any **kwargs: Any
) -> _pytest._code.ExceptionInfo[_E]: ) -> _pytest._code.ExceptionInfo[_E]:
... # pragma: no cover ...
def raises( # noqa: F811 def raises( # noqa: F811

View File

@ -42,14 +42,14 @@ def recwarn() -> Generator["WarningsRecorder", None, None]:
def deprecated_call( def deprecated_call(
*, match: Optional[Union[str, "Pattern[str]"]] = ... *, match: Optional[Union[str, "Pattern[str]"]] = ...
) -> "WarningsRecorder": ) -> "WarningsRecorder":
raise NotImplementedError() ...
@overload # noqa: F811 @overload # noqa: F811
def deprecated_call( # noqa: F811 def deprecated_call( # noqa: F811
func: Callable[..., T], *args: Any, **kwargs: Any func: Callable[..., T], *args: Any, **kwargs: Any
) -> T: ) -> T:
raise NotImplementedError() ...
def deprecated_call( # noqa: F811 def deprecated_call( # noqa: F811
@ -89,7 +89,7 @@ def warns(
*, *,
match: "Optional[Union[str, Pattern[str]]]" = ... match: "Optional[Union[str, Pattern[str]]]" = ...
) -> "WarningsChecker": ) -> "WarningsChecker":
raise NotImplementedError() ...
@overload # noqa: F811 @overload # noqa: F811
@ -99,7 +99,7 @@ def warns( # noqa: F811
*args: Any, *args: Any,
**kwargs: Any **kwargs: Any
) -> T: ) -> T:
raise NotImplementedError() ...
def warns( # noqa: F811 def warns( # noqa: F811

View File

@ -71,7 +71,7 @@ class BaseReport:
if TYPE_CHECKING: if TYPE_CHECKING:
# Can have arbitrary fields given to __init__(). # Can have arbitrary fields given to __init__().
def __getattr__(self, key: str) -> Any: def __getattr__(self, key: str) -> Any:
raise NotImplementedError() ...
def toterminal(self, out: TerminalWriter) -> None: def toterminal(self, out: TerminalWriter) -> None:
if hasattr(self, "node"): if hasattr(self, "node"):