Skip to content

Conversation

@serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Feb 3, 2026

__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 be
arbitrary descriptors, not only normal methods, for consistency with the
"with" and "async with" statements.
Copy link
Contributor

@ncoghlan ncoghlan 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?

Copy link
Contributor

@ncoghlan ncoghlan left a comment

Choose a reason for hiding this comment

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

In the absence of a Python binding for the actual special method lookup logic, the lazy import looks like a reasonable mitigation to me.

@serhiy-storchaka serhiy-storchaka merged commit f73d2e7 into python:main Feb 4, 2026
51 checks passed
@serhiy-storchaka serhiy-storchaka deleted the exit-stack-descriptors branch February 4, 2026 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants