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
My current plan is to release type hints for compose in a secondary stub-only package.
I'm not sure how soon I'll get to it, and there are some tricky things to figure out. (I wrote a little bit more on that in the comments of this StackOverflow question.)
So here's the situation when I last looked into it:
Problem: there's no way to do just one type-hint for variadic compose. We have to do type hint overloads for each arity, like this:
fromtypingimportCallable, TypeVar, ParamSpec, overloadP=ParamSpec('P')
R1=TypeVar('R1')
R2=TypeVar('R2')
R3=TypeVar('R3')
R4=TypeVar('R4')
@overloaddefcompose(f2: Callable[[R1], R2], f1: Callable[P, R1]) ->Callable[P, R2]:
...
@overloaddefcompose(f3: Callable[[R2], R3], f2: Callable[[R1], R2], f1: Callable[P, R1]) ->Callable[P, R3]:
...
@overloaddefcompose(f4: Callable[[R3], R4], f3: Callable[[R2], R3], f2: Callable[[R1], R2], f1: Callable[P, R1]) ->Callable[P, R4]:
...
# and so on, up to some large number
When I last tried that, it seemed that MyPy had issues with typing.overload in the same file as the code; I haven't yet gotten around to testing it in a separate typing stub file, but if that works then that might be the best we can do.
(I'm hoping that the above type-hint overloads work well enough for most cases despite compose/acompose/sacompose being classes with callable instances - a more precise solution would be to type-hint __init__ and __call__ in a way that links the types between them, assuming the existing type hint stuff can even handle that.)
Implemented in compose-stubs, about as well as it can be.
I'll promote the stubs to stable v1 release (and push out a compose release with the description updated to mention the stubs package) soon unless someone catches a serious problem that I missed.
Activity
mentalisttraceur commentedon Apr 29, 2023
Cheers!
My current plan is to release type hints for
composein a secondary stub-only package.I'm not sure how soon I'll get to it, and there are some tricky things to figure out. (I wrote a little bit more on that in the comments of this StackOverflow question.)
mentalisttraceur commentedon Aug 17, 2023
So here's the situation when I last looked into it:
Problem: there's no way to do just one type-hint for variadic
compose. We have to do type hint overloads for each arity, like this:When I last tried that, it seemed that MyPy had issues with
typing.overloadin the same file as the code; I haven't yet gotten around to testing it in a separate typing stub file, but if that works then that might be the best we can do.(I'm hoping that the above type-hint overloads work well enough for most cases despite
compose/acompose/sacomposebeing classes with callable instances - a more precise solution would be to type-hint__init__and__call__in a way that links the types between them, assuming the existing type hint stuff can even handle that.)mentalisttraceur commentedon Aug 17, 2023
Finally got around to sitting down and trying the typing stubs package approach. It works!
Confirmed with MyPy, Pyre, and Pyright.
mentalisttraceur commentedon Aug 18, 2023
Implemented in
compose-stubs, about as well as it can be.I'll promote the stubs to stable v1 release (and push out a
composerelease with the description updated to mention the stubs package) soon unless someone catches a serious problem that I missed.mentalisttraceur commentedon Aug 18, 2023
Okay,
compose-stubsis now officially released as v1.0.0, andcomposev1.5.0 now officially points to it in the package description and repo README. 🎉