2021年4月5日星期一

Python type hint Callable with one known positional type and then *args and **kwargs

I the below function foo, which has:

  • One positional arg with a known type
  • A variable number of positional and keyword args after that
from typing import Callable    def foo(bar: str, *args, **kwargs) -> None:      """Some function with one positional arg and then *args and **kwargs."""    foo_: Callable[[str, ...], None] = foo  # error: Unexpected '...'  

How can I type hint this?

Currently, mypy==0.812 throws the error: error: Unexpected '...' [misc]

https://stackoverflow.com/questions/66961423/python-type-hint-callable-with-one-known-positional-type-and-then-args-and-kw April 06, 2021 at 08:52AM

没有评论:

发表评论