-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
docs: use ParamSpec in "Declaring decorators" #13237
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
docs: use ParamSpec in "Declaring decorators" #13237
Conversation
While the documented approach is valid for the common case of a decorator which doesn't change the function type, and as the docs say the |
@@ -553,16 +552,17 @@ Here's a complete example of a function decorator: | |||
|
|||
.. code-block:: python | |||
|
|||
from typing import Any, Callable, TypeVar, cast | |||
from typing import Callable, ParamSpec, TypeVar |
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 think that we should include both examples. Because both techniques are quite common. This way we can clearly show why ParamSpec
is better.
What do you think?
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.
@sobolevn Check it out now. I've re-introduced the non-ParamSpec example, and also added an example where we change the return type (to show where ParamSpec is actually useful beyond "avoiding casts" type pure-ism).
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.
LGTM! Thank you.
Let's wait for a bit, maybe @srittau or @JelleZijlstra have some feedback? |
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.
Looks good, a few editorial suggestions
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Resolves #12983.