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
This is a feature request, so if there is a way to achieve this already, please point me and future me in the right way.
In TypeScript, we can use the ReturnType utility type to get the return type of a function to reuse in other places. This is very useful to make the code short, readable, and easy to change if necessary, especially in cases where I want to wrap the call of a function from another module in some other function.
In this case, I could maybe give the return type a name like FooReturn and import that in bar, but that seems less elegant rather than just reusing the function I'm already using.
Note that if automatic or manual type inference (#4409) was implemented, most of my usages would be covered.
The text was updated successfully, but these errors were encountered:
I can see how this would be useful, at least occasionally. However, this is not easy to implement in full generality, primarily because of decorators that can change the signature of a function. One option would be to only support functions with simple decorators as targets.
We'd be more likely to prioritize this if there was at least a draft PEP about the feature.
I think if a PEP were to be written, it would be nice to consider more general type introspection, from which a ReturnType-like utility could be built, as well as other useful utilities.
This is a feature request, so if there is a way to achieve this already, please point me and future me in the right way.
In TypeScript, we can use the
ReturnType
utility type to get the return type of a function to reuse in other places. This is very useful to make the code short, readable, and easy to change if necessary, especially in cases where I want to wrap the call of a function from another module in some other function.An example of how it might be used:
In this case, I could maybe give the return type a name like
FooReturn
and import that inbar
, but that seems less elegant rather than just reusing the function I'm already using.Note that if automatic or manual type inference (#4409) was implemented, most of my usages would be covered.
The text was updated successfully, but these errors were encountered: