FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-144386: Update equivalent code for "with", "async with" and "async for" by serhiy-storchaka · Pull Request #144472 · python/cpython · GitHub

Repository navigation

gh-144386: Update equivalent code for "with", "async with" and "async for" - #144472

Merged
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:docs-special-methods-lookup
Feb 18, 2026
Merged

serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:docs-special-methods-lookup

Conversation

serhiy-storchaka commented Feb 4, 2026 •
edited by github-actions Bot
Loading

Copy link
Copy Markdown
Member

They use special method lookup for special methods.


📚 Documentation preview 📚: https://cpython-previews--144472.org.readthedocs.build/

…"async for"

They use special method lookup for special methods.

tanloong commented Feb 5, 2026

Copy link
Copy Markdown
Contributor

I happened to notice that there might be a small point to adjust. The updated equivalent code manager.__enter__ could look up __enter__ in the instance attributes, but the with-statement does not.

import sys
class CM:
    def __init__(self):
        def __enter__():
            pass
        def __exit__(*exc_details):
            pass
        self.__enter__ = __enter__
        self.__exit__ = __exit__


# Not works: TypeError: 'CM' object does not support the context manager protocol (missed __exit__ method)
with CM():
    pass

# Works
manager = CM()
enter = manager.__enter__
exit_ = manager.__exit__
value = enter()
hit_except = False
try:
    TARGET = value
except:
    hit_except = True
    if not exit(*sys.exc_info()):
        raise
finally:
    if not hit_except:
        exit_(None, None, None)

Copy link
Copy Markdown
Member Author

Yes, this is what the added note for.

tanloong commented Feb 5, 2026

Copy link
Copy Markdown
Contributor

Oops, I missed that.

Copy link
Copy Markdown

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

serhiy-storchaka deleted the docs-special-methods-lookup branch February 18, 2026 11:13
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 18, 2026
…"async for" (pythonGH-144472)

They use special method lookup for special methods.
(cherry picked from commit 9e8fa2d)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 18, 2026
…"async for" (pythonGH-144472)

They use special method lookup for special methods.
(cherry picked from commit 9e8fa2d)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>

bedevere-app Bot commented Feb 18, 2026

Copy link
Copy Markdown

GH-144945 is a backport of this pull request to the 3.14 branch.

bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Feb 18, 2026

bedevere-app Bot commented Feb 18, 2026

Copy link
Copy Markdown

GH-144946 is a backport of this pull request to the 3.13 branch.

bedevere-app Bot removed the needs backport to 3.13 only security fixes label Feb 18, 2026
serhiy-storchaka added a commit that referenced this pull request Feb 18, 2026
… "async for" (GH-144472) (GH-144945)

They use special method lookup for special methods.
(cherry picked from commit 9e8fa2d)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit that referenced this pull request Feb 18, 2026
… "async for" (GH-144472) (GH-144946)

They use special method lookup for special methods.
(cherry picked from commit 9e8fa2d)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
brijkapadia pushed a commit to brijkapadia/cpython that referenced this pull request Feb 28, 2026
…"async for" (pythonGH-144472)

They use special method lookup for special methods.
ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
…"async for" (pythonGH-144472)

They use special method lookup for special methods.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip news

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL