enforce
enforce copied to clipboard
Support for `@overload`ed callables
This is a bit of a tricky one, but suppose you had something like the following:
@overload
def test(a: int, b: float) -> str: ...
@overload
def test(a: List[int], b: List[float]) -> List[str]: ...
@runtime_validation
def test(a, b):
return ...
It would be cool if the correct overload could be narrowed down to and validated with the arguments at runtime.
There has been some discussion in the official typing repo on how to accomplish this:
https://github.com/python/typing/issues/711
The gist is to inject a custom @overload implementation. I imagine there'd be work in tricking intellisense servers into thinking it's the original.