Add Aliasing Decorators section to libraries.rst#1243
Conversation
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](https://mypy.readthedocs.io/en/stable/generics.html#decorator-factories). Related discussion: python#1236
JelleZijlstra
left a comment
There was a problem hiding this comment.
Thanks, this is a useful addition.
I'm not sure it should be in the "libraries" document, but there's already a TODO on moving it out.
There was a problem hiding this comment.
Thanks, this makes sense. But I think we should rather recommend to use the _typeshed.IdentityFunction protocol, instead of recommending a custom protocol.
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from _typeshed import IdentityFunction
def decorator_factory(*, mode: str) -> "IdentityFunction":
"""
Decorator factory is invoked with arguments like this:
@decorator_factory(mode="easy")
def my_function(): ...
"""
...
I think it's important to note that this only works in stub files, if you have |
Thanks, easy to forget when always using the future import. :) |
Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
|
Thanks for the fast review and cool suggestion! I've rewritten the example using |
|
@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? |
Also, replace class names with links to the Python docs
srittau
left a comment
There was a problem hiding this comment.
I'm sorry. This completely to fell through the cracks. LGTM now, although I've changed a few links to refer to the – now existing – typing spec and to link to the Python docs.
I believe I'm not the only one who will struggle with behavior of
Callabletype aliases.I hope if this is added to the documentation - some people will save an hour on figuring how
TypeAliaswork.I'm not sure if it is worth introducing "decorator factory" term here, but it is used in mypy documentation.
Related discussion:
#1236