JRR
JRR

Reputation: 6152

typing variadic arguments in python

I wrote the following code:

def foo(a: List[str]):
  return a

def bar(*b: Tuple[str, ...]):
  return foo(list(b))

and pycharm says foo expects a List[str] but got List[Tuple[str, ...]] instead. How can I fix this?

Upvotes: 0

Views: 93

Answers (1)

Conchylicultor
Conchylicultor

Reputation: 5729

The Tuple annotation is implicitly added to *args, so in your code b is a Tuple[Tuple[str, ...], ...]. Instead you should have:

def bar(*b: str):
  # b is Tuple[str, ...]
  return foo(list(b))

Upvotes: 1

Related Questions