Add option to functools.update_wrapper()/@wraps to copy the coroutine flag
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Feature or enhancement
Proposal:
This came up during python/cpython#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
@deprecatedexample 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading functools.update_wrapper() and @wraps, then review the prior discussions in #100317 and python/cpython#122088 about coroutine-status copying. Done would require an agreed optional API behavior, with matching implementation, tests, and documentation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100