-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
function compatability check #12
Comments
I had this planned for the future, but it's a considerable amount of work and I haven't had much time to dedicate to anything except for bug fixing. |
Ok thanks, |
This looks related to the functionality of @OverRide in pytypes, see https://github.com/Stewori/pytypes#usage-example. I think what you are asking for is already done there internally. It should be doable to make the right pieces available in public API. This still requires some thought, but given what's already there it should be a comparably low hanging fruit. |
I just revisited this issue. What is the intended use case here? The closest thing on my agenda is #84. |
typeguard mainly deals with runtime type checking of function arguments. To check whether arguments are compatible for a function call, we want to know if they are of the correct type. What's asked for in this issue is different, here instead we want to know whether two static types have subtype relationship. I.e. were comparing two types, instead of comparing an instance and a type. Since that's a whole different problem realm, I'll make the argument that it'd be feature-creep to add it to typeguard, and that it's better solved elsewhere. You can get something sort of close in this way: from typing import List, Any, Sequence
from typeguard import functions_compatible
def f1(var1: int) -> List[int]:
return [var1]
def f2(var1: List[int]) -> Any:
return var1
functions_compatible(f1, f2) # True
functions_compatible(f2, f1) # True, because Any can be int
functions_compatible(f2, f1, strict=True) # False, because Any is not always int It's worth noting that essentially nothing from current typeguard implementation could help in making the subtype check more feature-complete. To support arbitrary types, you'd essentially need to implement a full static type checker, or do something crazy like calling into mypy from runtime. |
Awesome project, I think it will be very useful.
One question, is there anything that might be used to check the compatibility between two functions?
I am imagining something like this:
I am working on a configurable data pipeline that is meant to run for a very long time, but the exact function connections are not always known until import time or later.
The text was updated successfully, but these errors were encountered: