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?
How to use a constant object like a literal type-hint?
I have a unique and constant object as a special value, which I would like to use for type-hints in different occasions.
How to handle typing with TypeVar when generic object is stored as a dictionary value?
I write a small declarative API client and I want it to be fully typed (query params, body, etc), especially when it comes to query_params and body I would like PyCharm to autosuggest what type the route expects when issuing the .call() method.