Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-144386: Add support for descriptors in ExitStack and AsyncExitStack#144420

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
serhiy-storchaka wants to merge3 commits intopython:main
base:main
Choose a base branch
Loading
fromserhiy-storchaka:exit-stack-descriptors

Conversation

@serhiy-storchaka
Copy link
Member

@serhiy-storchakaserhiy-storchaka commentedFeb 3, 2026
edited
Loading

__enter__(),__exit__(),__aenter__(), and__aexit__() can now be arbitrary descriptors, not only normal methods, for consistency with the "with" and "async with" statements.

…itStack__enter__(), __exit__(), __aenter__(), and __aexit__() can now bearbitrary descriptors, not only normal methods, for consistency with the"with" and "async with" statements.
Copy link
Contributor

@ncoghlanncoghlan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The general approach looks right to me, but is it feasible to avoid adding the dependency on the inspect module by moving that helper function somewhere lower in the import stack?

@@ -1,11 +1,12 @@
"""Utilities for with-statement contexts. See PEP 343."""
import abc
from inspect import getattr_static, _descriptor_get
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Eek, that's a heavy dependency to bring into contextlib by default. Maybe we could move the private helper to types and have both modules import it from there?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

getattr_static itself is a heavy machinery, it depends on many of other private functions ininspect.

We only need_PyObject_LookupSpecial exposed at the Python level. This is a different issue.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@ncoghlanncoghlanncoghlan left review comments

@AA-TurnerAA-TurnerAwaiting requested review from AA-TurnerAA-Turner is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@serhiy-storchaka@ncoghlan

[8]ページ先頭

©2009-2026 Movatter.jp