I am testing mypy
in one of my projects to see if I will like or not. I know only the basics so far. Here is a little problem I am unable to solve.
I need a function with positional-only parameters. In Python 3.8+:
def func(self, arg: int, /, **data):
(This allows to use self=something
and arg=something
in the data
, if you're curious why.)
To make it work also in Python 3.7 I had to write:
def func(*args, **data):
self, arg = args
And it works fine, but seems to confuse the mypy
, it complains about parameter types in calls of this func
.
How can I annotatate, that arg[1]
is an int?
Update:
I had some partial success with typing.overload.
A single @overload generates this error: "Single overload definition, multiple required" and when I write it twice: "Overloaded function signature 2 will never be matched" but the calls to that method are now checked OK.