Closed
Description
Passing any function through compose.compose()
seems to strip away all the information about the types of those functions.
Minimal example:
import compose
def f(x: int) -> str:
return f"{x}"
# compose f with the identity function
g = compose.compose(f)
reveal_type(f(1))
reveal_type(g(1))
Testing on python 3.11 yields:
$ mypy --version
mypy 1.5.1 (compiled: yes)
$ mypy test_compose.py
test_compose.py:11: note: Revealed type is "builtins.str"
test_compose.py:12: note: Revealed type is "Any"
I expected that the static type checker would have printed builtins.str
even for g(1)
.
This is a stripped down example of a larger problem I had early on on a project of mine, where I wrongly assumed that composed functions would have brought over the type information about their signature. I ended up introducing a bug in my project because of this assumption.
This issue is a cross post of something I also found in another library (pytoolz/toolz#569).
Is this a limitation of the libraries? Of the language itself? Or the static analyzers?
Thank you.
Metadata
Metadata
Assignees
Labels
No labels