-
Notifications
You must be signed in to change notification settings - Fork 54
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
Type hint error of wrapped function #122
Comments
Hello, it surely is complicated to infer the type in this case as decorators are hiding lots of details to the linters. In this case, |
Signed-off-by: Matteo Cafasso <[email protected]>
Signed-off-by: Matteo Cafasso <[email protected]>
Signed-off-by: Matteo Cafasso <[email protected]>
Release |
@noxdafox Now it's even worse than before (at least with pyright) ;-) Before the change, I could do an |
These things are half following the type hints and half guessing themselves. I will try a bit harder. How can I scan |
You can call Here is a simple example and the error message: from pebble import concurrent
@concurrent.process(daemon=True)
def foo(x: int) -> str:
return str(x)
future = foo(42)
future.result() # Pyright error: Cannot access member "result" for type "str", Member "result" is unknown I would expect Maybe I can also take a look next week (this week is unfortunately quite busy). But even if we don't figure that out ... your library is super nice. I use it for all my threading / multiprocessing stuff. Thanks for that! |
We cannot infer during load time the arguments as the decorator might be called as such: @concurrent.process
def function():
return
@concurrent.process(timeout=10)
def function():
return
def myfunction():
return
function = concurrent.function(myfunction)
function = concurrent.function(myfunction, timeout=10) In all these cases, the arguments and keyword arguments might be different depending on the situation. For example, if you use the Hence, the In other words, we cannot do: def process(function, timeout: int = None, daemon: bool = True, ...):
... But we have to do this: I was reading a bit around regarding this problem and found few related issues on the It might be quite hard to get linters to infer the types correctly. |
Signed-off-by: Matteo Cafasso <[email protected]>
Did some small fixes but it didn't work. There is some good hope when looking at :https://peps.python.org/pep-0612/ But I could not get it work straight away. Anyways, as it's supported from 3.10 onwards it makes little sense to add it right now as we need to guarantee a certain degree of backwards compatibility. I will try this again in some time when the platforms will be more mature. |
According to #102 Pebble does support type hints. But if I call a wrapped function as below then pyright tells me
'Object of type "ProcessFuture" is not callable'.
. It also tells me that the wrapped function if of type(function) foo: ProcessFuture | _Wrapped[(*args: Any, **kwargs: Any), Any, (*args: Unknown, **kwargs: Unknown), ProcessFuture]
. Not sure what the problem with the type checker here is or if it can be improved on the Pebble side. I am using v5.0.3.The text was updated successfully, but these errors were encountered: