Skip to content

gh-151907: Reduce duplication in codegen comprehension functions - #154846

Merged
ZeroIntensity merged 3 commits into
python:mainfrom
cdce8p:codegen-comprehension-reduce-duplication
Sep 26, 2026
Merged

ZeroIntensity merged 3 commits into
python:mainfrom
cdce8p:codegen-comprehension-reduce-duplication

Conversation

@cdce8p

@cdce8p cdce8p commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Noticed that #151908 updated both codegen_sync_comprehension_generator and codegen_async_comprehension_generator but missed a spot to use the "new" helper codegen_unpack_starred in the latter. After looking more closely into it, I noticed that a large part is actually identical between both functions. Moving it to a separate functions avoids any unintended differences between sync and async comprehensions just because one code path wasn't updated properly.

Also added two assert(!avoid_creation); to the helper which were added to the async variant but missed for the sync one.

/CC @ZeroIntensity

@ZeroIntensity ZeroIntensity added skip news type-refactor Code refactoring (with no changes in behavior) labels Sep 26, 2026

@ZeroIntensity ZeroIntensity left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice refactor, thanks!

@ZeroIntensity
ZeroIntensity merged commit 109a192 into python:main Sep 26, 2026
60 checks passed
@cdce8p
cdce8p deleted the codegen-comprehension-reduce-duplication branch September 26, 2026 16:58
@bedevere-bot

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 FreeBSD Refleaks 3.x (tier-3) has failed when building commit 109a192.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1613/builds/3890) and take a look at the build logs.
  4. Check if the failure is related to this commit (109a192) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1613/builds/3890

Test leaking resources:

  • test_events: memory blocks
  • test_events: references

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.x.opsec-fbsd14.refleak/build/Lib/test/support/__init__.py", line 970, in gc_collect
    gc.collect()
    ~~~~~~~~~~^^
ResourceWarning: unclosed <socket.socket fd=7, family=2, type=1, proto=6, laddr=('127.0.0.1', 20491), raddr=('127.0.0.1', 52583)>
Task was destroyed but it is pending!
task: <Task pending name='Task-3225' coro=<BaseSelectorEventLoop._accept_connection2() done, defined at /home/buildbot/buildarea/3.x.opsec-fbsd14.refleak/build/Lib/asyncio/selector_events.py:220> wait_for=<Future finished exception=SSLError(1, '[SSL: TLSV1_ALERT_UNKNOWN_CA] tlsv1 alert unknown ca (_ssl.c:1117)')>>
Future exception was never retrieved
future: <Future finished exception=SSLError(1, '[SSL: TLSV1_ALERT_UNKNOWN_CA] tlsv1 alert unknown ca (_ssl.c:1117)')>
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.x.opsec-fbsd14.refleak/build/Lib/asyncio/sslproto.py", line 581, in _on_handshake_complete
    raise handshake_exc
  File "/home/buildbot/buildarea/3.x.opsec-fbsd14.refleak/build/Lib/asyncio/sslproto.py", line 563, in _do_handshake
    self._sslobj.do_handshake()
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/home/buildbot/buildarea/3.x.opsec-fbsd14.refleak/build/Lib/ssl.py", line 961, in do_handshake
    self._sslobj.do_handshake()
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^
ssl.SSLError: [SSL: TLSV1_ALERT_UNKNOWN_CA] tlsv1 alert unknown ca (_ssl.c:1117)
Warning -- Unraisable exception
Exception ignored while calling deallocator <function _SelectorTransport.__del__ at 0x2f4f195962d0>:
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.x.opsec-fbsd14.refleak/build/Lib/asyncio/selector_events.py", line 882, in __del__
    _warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
    ~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ResourceWarning: unclosed transport <_SelectorSocketTransport closing fd=7>
k


Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.x.opsec-fbsd14.refleak/build/Lib/test/support/__init__.py", line 970, in gc_collect
    gc.collect()
    ~~~~~~~~~~^^
ResourceWarning: unclosed <socket.socket fd=8, family=2, type=1, proto=6, laddr=('127.0.0.1', 52237), raddr=('127.0.0.1', 31627)>
Task was destroyed but it is pending!
task: <Task pending name='Task-4648' coro=<BaseSelectorEventLoop._accept_connection2() done, defined at /home/buildbot/buildarea/3.x.opsec-fbsd14.refleak/build/Lib/asyncio/selector_events.py:220> wait_for=<Future pending cb=[Task.task_wakeup()]>>
Warning -- Unraisable exception
Exception ignored while calling deallocator <function _SelectorTransport.__del__ at 0x29f984a696d0>:
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.x.opsec-fbsd14.refleak/build/Lib/asyncio/selector_events.py", line 882, in __del__
    _warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
    ~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ResourceWarning: unclosed transport <_SelectorSocketTransport closing fd=8>
k

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

Labels

skip news type-refactor Code refactoring (with no changes in behavior)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants