Relative Content

Tag Archive for pythonpython-typingtype-hinting

Python type hinting: Explicitly exclude invalid overload combinations?

I have a function with two parameters that can each take one of two types. Three of the four pairwise combinations are valid, but the fourth is invalid. I’d like to find a way to type hint this scenario that can check these types, but not necessarily have to write code to check for the invalid case every single time I call foo(). Is there a way I can improve the type hints for either foo(), bar(), or both?