typing icon indicating copy to clipboard operation
typing copied to clipboard

Add Aliasing Decorators section to libraries.rst

Open Drino opened this issue 2 years ago • 5 comments

I believe I'm not the only one who will struggle with behavior of Callable type aliases. I hope if this is added to the documentation - some people will save an hour on figuring how TypeAlias work.

I'm not sure if it is worth introducing "decorator factory" term here, but it is used in mypy documentation.

Related discussion: https://github.com/python/typing/discussions/1236

Drino avatar Aug 22 '22 11:08 Drino

All commit authors signed the Contributor License Agreement.
CLA signed

cpython-cla-bot[bot] avatar Aug 22 '22 11:08 cpython-cla-bot[bot]

But I think we should rather recommend to use the _typeshed.IdentityFunction protocol, instead of recommending a custom protocol.

I think it's important to note that this only works in stub files, if you have from __future__ annotations enabled, or if you use -> "IdentityFunction" instead of -> IdentityFunction.

AlexWaygood avatar Aug 22 '22 16:08 AlexWaygood

I think it's important to note that this only works in stub files, if you have from __future__ annotations enabled, or if you use -> "IdentityFunction" instead of -> IdentityFunction.

Thanks, easy to forget when always using the future import. :)

srittau avatar Aug 22 '22 16:08 srittau

Thanks for the fast review and cool suggestion!

I've rewritten the example using IdentityFunction, though I'm a little bit concerned to show a "proper" example of decorator protocol definition, so I've added another one with slightly less trivial decorator.

Drino avatar Aug 22 '22 16:08 Drino

@srittau Hello, I've went through your comments and it seems that I've resolved the issues. Would you look at this PR one more time please?

Drino avatar Sep 23 '22 18:09 Drino