4 ms·
That's both genius and a massive hack, love it. For those who are wondering: they alias @typing.overload as @ovld only for type checkers. Normally, @typing.ov
by mpeg 1y ago
That's both genius and a massive hack, love it.
For those who are wondering: they alias @typing.overload as @ovld only for type checkers.
Normally, @typing.overload is a way to define multiple function signatures with empty bodies so your type checker can work nicely with functions that for example only return a certain type when called with a certain signature, but the function implementation is left to you and usually involves a bunch of runtime type checks to branch your logic the right way
- paddy_m 1y agoWhat is the return type of an overloaded function? I don't see that in any of the examples. I think it would make sense to have each function return either the exact same type, or a generic. @ovld(int) #all of these overloads should return an int len(a:list) -> int len(a:str) -> int #the effective type of len is len(a:Union[int, str]) -> int and then a generic example T = TypeVar('T') @ovld(T) add(a:np.int8, b:np.int8) -> np.int8 @ovld(T) add(a:np.int16, b:np.int16) -> np.int16 In the second example, I don't know how you would connect the input params to the generic T. If you put concrete types in, I see how ovld works. Am I missing something?