Type hint a function as abstract, not needing a body #2030
-
Is there a way to hint that a function is abstract and doesn't need a body, like with the P = ParamSpec('P')
T_co = TypeVar('T_co', covariant=True)
class TypedSignal(Generic[P, T_co]):
def __init__(self, spec: Callable[P, T_co]) -> None: ...
def connect(self, handler: Callable[P, T_co]) -> Callable[P, T_co]: ...
def send(self, *args: P.args, **kwargs: P.kwargs) -> list[tuple[Callable[P, T_co], T_co]]: ...
@TypedSignal
def my_signal(sender: SomeType, arg: OtherType) -> ReturnType: ...
@my_signal.connect
def my_signal_handler(sender: SomeType, arg: OtherType) -> ReturnType:
# Insert real implementation At the moment, Mypy complains |
Beta Was this translation helpful? Give feedback.
Answered by
hauntsaninja
Jun 23, 2025
Replies: 1 comment 1 reply
-
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
jace
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
raise NotImplementedError
/--disable-error-code empty-body
/# type: ignore[empty-body]
are your best bet