Skip Navigation
InitialsDiceBearhttps://github.com/dicebear/dicebearhttps://creativecommons.org/publicdomain/zero/1.0/„Initials” (https://github.com/dicebear/dicebear) by „DiceBear”, licensed under „CC0 1.0” (https://creativecommons.org/publicdomain/zero/1.0/)ET
eternacht @programming.dev
Posts 0
Comments 2
[Answered] Typehints for functions that have variable signatures
  • This is the real answer, overloads are meant for exactly this purpose.

    It’ll be something like this:

    from typing import Literal, overload
    
    @overload
    def foo() -> Data: …
    @overload
    def foo(return_more: Literal[True]) -> tuple[Data, Data]: …
    def foo(return_more: bool = False) -> Data | tuple[Data, Data]
        ...
        if return_more:
            return data, more_data
       return data