Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34k
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
base:main
Are you sure you want to change the base?
Conversation
…itStack__enter__(), __exit__(), __aenter__(), and __aexit__() can now bearbitrary descriptors, not only normal methods, for consistency with the"with" and "async with" statements.
b9d6d32 tobfa8dd3Compare
ncoghlan left a comment
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.
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?
Lib/contextlib.py Outdated
| @@ -1,11 +1,12 @@ | |||
| """Utilities for with-statement contexts. See PEP 343.""" | |||
| import abc | |||
| from inspect import getattr_static, _descriptor_get | |||
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.
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?
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.
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.
Uh oh!
There was an error while loading.Please reload this page.
__enter__(),__exit__(),__aenter__(), and__aexit__()can now be arbitrary descriptors, not only normal methods, for consistency with the "with" and "async with" statements.ExitStack.enter_context#144386