mirror of
https://github.com/astral-sh/ruff.git
synced 2026-11-21 12:16:15 +08:00
Co-authored-by: Micha Reiser <micha@reiser.io> Co-authored-by: David Peter <sharkdp@users.noreply.github.com>
930 B
930 B
What it does
Checks for overloaded functions and methods without a required implementation. An implementation can be omitted in any of the following cases:
- The overloads are defined in a stub file (
.pyi). - All overloads are defined inside
if TYPE_CHECKINGblocks. - The overloaded method is defined in a protocol.
- The method is defined in an abstract base class and every overload is decorated with
@abstractmethod.
Why is this bad?
The @overload definitions describe the calls a type checker should accept. A separate
implementation handles those calls at runtime. Calling an overloaded function without an
implementation raises NotImplementedError.
Example
from typing import overload
@overload
def foo() -> None: ... # error
@overload
def foo(x: int) -> int: ...