home.social

#variadic — Public Fediverse posts

Live and recent posts from across the Fediverse tagged #variadic, aggregated by home.social.

  1. @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