Replies: 3 comments 1 reply
-
You can have two major cases:
def compose(
first: Callable[[_FirstType], _SecondType],
second: Callable[[_SecondType], _ThirdType],
) -> Callable[[_FirstType], _ThirdType]: ...
Or you can just use https://github.com/dry-python/returns 🙂 |
Beta Was this translation helpful? Give feedback.
-
Does len have overloads? I recall paramspec with functions with overloads is buggy. I’m unsure any type checker handles that case today. I think mypy already has a bug report for that. Edit: https://github.com/python/typeshed/blob/ef6bacab926bd16f8e336f71b5360e37be03b82e/stdlib/builtins.pyi#L1344 Len appears to not have overloads so it’s not that. I tested your examples in pyright and they both work. So this is a bug in mypy to report. |
Beta Was this translation helpful? Give feedback.
-
Thanks @hmc-cs-mdrissi |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to type function composition, and get stuck.
While the general case for
n
functions is more difficult, for two functions this should be easy with Python 3.10's ParamSpec:This works sometimes:
But not always:
I get
mypy
errors:What am I doing wrong? Any ideas?
Beta Was this translation helpful? Give feedback.
All reactions