-
Notifications
You must be signed in to change notification settings - Fork 242
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
Add Aliasing Decorators section to libraries.rst #1243
base: main
Are you sure you want to change the base?
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
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? |
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:
#1236