You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It was pretty neat, and wanted to try it out for functions that take more than 1 positional argument. Sadly, it does not seem to work.
What's wrong
When trying to run the following code:
fromreturns._internal.pipeline.pipeimportpipedefone_arg_only(num1: float) ->int:
returnint(num1)
deftwo_args(num1: float, num2: int) ->int:
returnint(num1+num2)
defto_string(f: float) ->str:
returnstr(f)
defto_float(s: str) ->float:
returnfloat(s)
if__name__=="__main__":
fizz=pipe(one_arg_only, to_string, to_float)
print(fizz(1)) # Trivial examplebuzz=pipe(to_string, to_float)
print(buzz(two_args(1, 2))) # This works, but is not idealbazz=pipe(two_args, to_string, to_float)
try:
print(bazz(1, 2)) # Too many arguments for "__call__" of "_Pipe" [call-arg]exceptTypeErrorase:
print(
"Cannot pass two arguments even though first function requires 2 positional arguments"
)
raisee
When the types are not correct, mypy throws the following error message:
# Mypy error says: Cannot infer type argument 3 of "pipe"fizz=pipe(one_arg_only, to_string, to_string)
I toyed around with typing.ParamSpec within returns/_internal/pipeline/pipe.pyi to see if that would do the trick, but I couldn't after a couple of hours of getting the above example to have mypy return no errors. Maybe I missed something, or I just have mind block.
Feature Request/Enhancement
I stumbled upon this post a while ago:
python/typing#1245
It was pretty neat, and wanted to try it out for functions that take more than 1 positional argument. Sadly, it does not seem to work.
What's wrong
When trying to run the following code:
you would get the following exception:
How is that should be
Invoking bazz should not throw a
TypeError
.What I have tried
The following works if and only if the types are all correct.
When the types are not correct, mypy throws the following error message:
I toyed around with
typing.ParamSpec
withinreturns/_internal/pipeline/pipe.pyi
to see if that would do the trick, but I couldn't after a couple of hours of getting the above example to have mypy return no errors. Maybe I missed something, or I just have mind block.Related issue: python/typing#1289
The text was updated successfully, but these errors were encountered: