#Variadic

@smurthys You say return types don't matter, so what are you really looking for here? Just how to handle the function parameters (and their type hints)? Is the variable number of arguments tripping you up?

So depending on your actual use case....

def f(a: int | str | float, b: str | float | None = None) -> int | str:
...

If they pass one argument, or they pass None as the 2nd argument, b will be None. If you need to distinguish those cases, use a sentinel.

#python #variadic #TypeHint

Client Info

Server: https://mastodon.social
Version: 2025.04
Repository: https://github.com/cyevgeniy/lmst