Skip to content
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 option to functools.update_wrapper()/@wraps to copy the coroutine flag #121967

Open
srittau opened this issue Jul 18, 2024 · 0 comments
Open
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@srittau
Copy link
Contributor

srittau commented Jul 18, 2024

Feature or enhancement

Proposal:

This came up during #122088, where it was noted that @deprecated drops the coroutine flag of a function. @deprecated uses @wraps/update_wrapper internally. This was previously discussed in #100317, where it was suggested that the flag should be copied automatically. It was ultimately decided by @gvanrossum that this is dangerous, since wrappers might decide to convert from/to coroutines.

I propose to add a flag to update_wrapper() and @wraps to optionally copy the status:

  • It's more convenient to use than using the boilerplate code mentioned in the previous issue. Especially since I would assume that most wrappers want to copy this status.
  • Probably more important: This makes this problem and its solution discoverable. As the @deprecated example shows, most people probably don't think about this issue when creating a wrapper. By adding a flag to the API and the documentation, this problem will be mentioned and can be discovered by users of @wraps, either while reading the documentation, or when the IDE shows the availability of the flag.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

@srittau srittau added the type-feature A feature request or enhancement label Jul 18, 2024
@AlexWaygood AlexWaygood added the stdlib Python modules in the Lib dir label Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants