-
Notifications
You must be signed in to change notification settings - Fork 282
Add Aliasing Decorators section to libraries.rst #1243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
|
Thanks for the fast review and cool suggestion! I've rewritten the example using |
Co-authored-by: Alex Waygood <[email protected]>
|
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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