I\'m trying out Python\'s type annotations with abstract base classes to write some interfaces. Is there a way to annotate the possible types of *args
and
As a short addition to the previous answer, if you're trying to use mypy on Python 2 files and need to use comments to add types instead of annotations, you need to prefix the types for args
and kwargs
with *
and **
respectively:
def foo(param, *args, **kwargs):
# type: (bool, *str, **int) -> None
pass
This is treated by mypy as being the same as the below, Python 3.5 version of foo
:
def foo(param: bool, *args: str, **kwargs: int) -> None:
pass