-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
I'm unsure if this might be a bug, a feature request or if I just failed to find the right spot in the documentation.
What I want to do: I have an abstract base class that defines an interface which derived classes need to implement. There's an abstract method run
that requires several mandatory arguments, and may accept additional optional arguments (to override defaults). Currently I'm not sure how I can model this using mypy. Here's some example code that reproduces the issue (ran with Python 3.7 and mypy 0.720:
import abc
from typing import Any
class Base(abc.ABC):
@abc.abstractmethod
def run(self, model: Any, **kwargs: int) -> None:
pass
class Child(Base):
def run(self, model: Any, foo : int) -> None:
pass
This produces the following error:
mypy_test.py:12: error: Signature of "run" incompatible with supertype "Base"
I sued the **kwargs
annotation in reference to this PEP but I realize the use case is different. I couldn't find anything in the mypy documentation about annotating this correctly.
I could of course use **kwargs
in the Child
class and parse optional parameters from there, but I don't think that's a good solution. Any help to get this working would be highly appreciated!