GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-143055: Implementation of PEP 798 by adqm · Pull Request #143056 · python/cpython

Conversation

@adqm

@adqm adqm commented Dec 21, 2025 •
edited by github-actions Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

This PR is an implementation of PEP 798 (Unpacking in Comprehensions), reflecting the SC's required modification to genexp semantics from the original proposal.

Feedback is welcome! :)

  • Issue: Implement PEP 798 – Unpacking in Comprehensions #143055

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

johnslavik, ZeroIntensity, nineteendo, and fgeorgatos reacted with rocket emoji
All reactions
  • 🚀 4 reactions
adqm added 8 commits December 20, 2025 18:24
@adqm
tests for pep798
0288001
@adqm
initial implementation of pep798 basics
a7ea132
@adqm
update error messages
c23496e
* add error messages for dict unpacking in dict keys/values

* change phrasing of existing error messages about using dict unpacking in a
  listcomp / genexp
@adqm
improve error reporting for invalid starred expressions
49405ac
@adqm
fix for affected test case in test_encodings
26841f9
@adqm
add news blurb
3ebe2f6
@adqm
first pass at adding documentation for comprehension unpacking
0713bbc
@adqm
code formatting
0393552
@adqm
adqm requested review from AA-Turner, Eclips4, JelleZijlstra, iritkatriel, isidentical, lysnikolaou, markshannon, pablogsal, tomasr8 and willingc as code owners December 21, 2025 23:46
@bedevere-app bedevere-app Bot added the awaiting review label Dec 21, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Dec 21, 2025
Implement PEP 798 – Unpacking in Comprehensions #143055
Closed
JelleZijlstra
JelleZijlstra reviewed Dec 22, 2025
View reviewed changes

@JelleZijlstra JelleZijlstra left a comment

Copy link
Copy Markdown
Member

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.

Thanks! A few nitpicky comments, I didn't read past Lib/test yet.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

adqm reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Doc/reference/expressions.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/reference/expressions.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/tutorial/datastructures.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Grammar/python.gram Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Grammar/python.gram Resolved

Uh oh!

There was an error while loading. Please reload this page.

adqm and others added 2 commits December 22, 2025 14:24
@adqm @JelleZijlstra
Apply suggestions from code review
fa16f82
Co-authored-by: Jelle Zijlstra <[email protected]>
@adqm
rearrange dict comprehension reference into a bulleted list
81e86b3
JelleZijlstra
JelleZijlstra approved these changes Dec 22, 2025
View reviewed changes

@JelleZijlstra JelleZijlstra left a comment

Copy link
Copy Markdown
Member

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 C code all looks good. I'll run it through the buildbots to make sure though.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

adqm reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Dec 22, 2025
@JelleZijlstra JelleZijlstra added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Dec 22, 2025
@bedevere-bot

bedevere-bot commented Dec 22, 2025

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @JelleZijlstra for commit 81e86b3 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F143056%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Dec 22, 2025
ZeroIntensity
ZeroIntensity approved these changes Dec 23, 2025
View reviewed changes

@ZeroIntensity ZeroIntensity left a comment

Copy link
Copy Markdown
Member

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.

I'm assuming the plan is to document this in 3.15 "What's New" later?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/reference/expressions.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/reference/expressions.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

adqm added 2 commits December 23, 2025 10:32
@adqm
0 -> zero
74df6b9
@adqm
use .. versionchanged:: next instead of 3.15
23538a8
@adqm

adqm commented Dec 23, 2025

Copy link
Copy Markdown
Contributor Author

@ZeroIntensity Thanks for the review!

I'm assuming the plan is to document this in 3.15 "What's New" later?

I haven't drafted a blurb for "What's New" yet, but I'm happy to do so. I can do that in a separate PR later, or I don't mind adding it to this one if that's better.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adqm
docs: fix generator_expression grammar rule
fcf129f
@JelleZijlstra

JelleZijlstra commented Dec 27, 2025

Copy link
Copy Markdown
Member

Probably easiest to add the What's New entry here too.

adqm and hugovk reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal

pablogsal commented Dec 27, 2025

Copy link
Copy Markdown
Member

Will try to make a pass over the grammar next week if @lysnikolaou doesn't beat me to it

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dylwil3 dylwil3 mentioned this pull request Jan 6, 2026
Allow Python 3.15 as valid target-version value in preview astral-sh/ruff#22419
Merged
lysnikolaou
lysnikolaou approved these changes Jan 28, 2026
View reviewed changes

@lysnikolaou lysnikolaou left a comment

Copy link
Copy Markdown
Member

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.

I had a look at the grammar. The changes look great in general. I left a couple of minor comments, but feel free to merge if the PR is not blocked otherwise.

Maybe @pablogsal wants to give it a look as well?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

adqm reacted with heart emoji
All reactions
  • ❤️ 1 reaction
Comment thread Grammar/python.gram Outdated

if_expression[expr_ty]:
| a=disjunction 'if' b=disjunction 'else' c=expression { _PyAST_IfExp(b, a, c, EXTRA) }
| invalid_if_expression

@lysnikolaou lysnikolaou Jan 27, 2026

Copy link
Copy Markdown
Member

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.

I'm pretty sure this alternative is never reached, since, in the second pass, it's encountered in expression before we get to if_expression and only in invalid rules otherwise that will overwrite the error either way.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@adqm adqm Jan 29, 2026

Copy link
Copy Markdown
Contributor Author

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.

Thanks for taking a look! Yep, I think you're right that we can't reach invalid_if_expression here, good catch. I'll push that change today (along with a what's new entry).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Grammar/python.gram
Comment on lines +896 to +898
| &'(' (genexp | tuple | group)
| &'[' (listcomp | list)
| &'{' (dictcomp | setcomp | dict | set)

@lysnikolaou lysnikolaou Jan 28, 2026

Copy link
Copy Markdown
Member

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.

Changing the order here is probably only about error messages, right? If so, have you checked whether this affects parsing performance at all? To be clear, I'm okay to sacrifice a bit of performance for better error messages.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@adqm adqm Jan 29, 2026

Copy link
Copy Markdown
Contributor Author

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.

Yep, the reordering here was purely for error reporting. I hadn't done any performance testing before, but I did a quick, unscientific test this morning, doing some quick timings on ast.parse for a few things.

As might be expected, compared to the place I branched from, it looks like this branch is, in general, a little bit faster on comprehensions and a little bit slower on literal lists. It's a little hard to say how this works out on the whole, but the time for parsing the full standard library was always within ±2% every time I ran it. I can look more thoroughly if we're concerned about this, but this little test at least suggests that things haven't blown up on average.

Sample results:

TestReasonThis BranchMerge baseChange
[] (1e5 times)empty list0.58380.5539~5% slower
[x, y, z, a, b, c] (1e5 times)well-formed list1.40511.3827~2% slower
[1, 2, 3, 4, 5, 6 (1e5 times)broken list1.17501.1413~3% slower
[x for x in y if z and a] (1e5 times)well-formed comprehension1.16421.2393~6% faster
[x for x in (1e5 times)broken comprehension0.65680.7014~6% faster
[**x for x in y] (1e5 times)broken comprehension unpacking (new specific error message)1.26751.0519~20% slower
[x if x else y] (1e5 times)good ifexp1.01630.9890~3% slower
[*x if x else y] (1e5 times)broken ifexp (new specific error message)1.32991.7870~26% faster
full stdlib (5 times)26.164126.2642~equal

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
adqm added 2 commits January 29, 2026 08:29
@adqm
remove redundant grammar rule
acaf3b1
@adqm
add "what's new" blurb
b5ae690
@JelleZijlstra

JelleZijlstra commented Jan 30, 2026

Copy link
Copy Markdown
Member

Going to "Update branch" to see if it fixes CI

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JelleZijlstra
Merge branch 'main' into pep798
7c16250
@adqm

adqm commented Jan 30, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @JelleZijlstra! Does "update branch" run a different set of tests? Unless I'm missing something, it looks like the test that's currently failing wasn't run on any of the earlier commits. Is that something I should be concerned about?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ZeroIntensity

ZeroIntensity commented Jan 30, 2026

Copy link
Copy Markdown
Member

It's relatively new, so it wasn't on this PR before the update. I think it's an issue with main and not this PR, but we aren't blocked from merging by a failing CIFuzz anyway.

adqm reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JelleZijlstra
JelleZijlstra merged commit ccbe41e into python:main Jan 31, 2026
48 of 50 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Jan 31, 2026
@bedevere-bot

bedevere-bot commented Jan 31, 2026

Copy link
Copy Markdown

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

Hi! The buildbot AMD64 FreeBSD14 3.x (tier-3) has failed when building commit ccbe41e.

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/1232/builds/7885) and take a look at the build logs.
  4. Check if the failure is related to this commit (ccbe41e) 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/1232/builds/7885

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/build/Lib/test/support/__init__.py", line 947, in gc_collect
    gc.collect()
    ~~~~~~~~~~^^
ResourceWarning: unclosed <socket.socket fd=8, family=2, type=1, proto=6, laddr=('127.0.0.1', 50174), raddr=('127.0.0.1', 54992)>
Warning -- Unraisable exception
Exception ignored while calling deallocator <function _SelectorTransport.__del__ at 0x1c7f3879be90>:
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.x.opsec-fbsd14/build/Lib/asyncio/selector_events.py", line 873, in __del__
    _warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
    ~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ResourceWarning: unclosed transport <_SelectorSocketTransport closing fd=8>
k


Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.x.opsec-fbsd14/build/Lib/test/support/__init__.py", line 947, in gc_collect
    gc.collect()
    ~~~~~~~~~~^^
ResourceWarning: unclosed <socket.socket fd=8, family=2, type=1, proto=6, laddr=('127.0.0.1', 60632), raddr=('127.0.0.1', 51955)>
Warning -- Unraisable exception
Exception ignored while calling deallocator <function _SelectorTransport.__del__ at 0x1bd099e02990>:
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.x.opsec-fbsd14/build/Lib/asyncio/selector_events.py", line 873, in __del__
    _warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
    ~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ResourceWarning: unclosed transport <_SelectorSocketTransport closing fd=8>
k
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JelleZijlstra

JelleZijlstra commented Jan 31, 2026

Copy link
Copy Markdown
Member

Looks unrelated

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adqm

adqm commented Feb 1, 2026

Copy link
Copy Markdown
Contributor Author

Exciting to see this merged! Thanks for the help, everyone :)

If issues with the code do come up, I'm happy to help fix them.

hugovk reacted with hooray emoji ZeroIntensity reacted with heart emoji hugovk reacted with rocket emoji
All reactions
  • 🎉 1 reaction
  • ❤️ 1 reaction
  • 🚀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

thunder-coding pushed a commit to thunder-coding/cpython that referenced this pull request Feb 15, 2026
@adqm @JelleZijlstra @thunder-coding
pythongh-143055: Implementation of PEP 798 (python#143056)
7bfd8a4
Co-authored-by: Jelle Zijlstra <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ZeroIntensity ZeroIntensity ZeroIntensity approved these changes
@JelleZijlstra JelleZijlstra JelleZijlstra approved these changes
@lysnikolaou lysnikolaou lysnikolaou approved these changes
@pablogsal pablogsal Awaiting requested review from pablogsal pablogsal is a code owner
@iritkatriel iritkatriel Awaiting requested review from iritkatriel iritkatriel is a code owner
@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner
@isidentical isidentical Awaiting requested review from isidentical isidentical is a code owner
@Eclips4 Eclips4 Awaiting requested review from Eclips4 Eclips4 is a code owner
@tomasr8 tomasr8 Awaiting requested review from tomasr8 tomasr8 is a code owner
@willingc willingc Awaiting requested review from willingc willingc is a code owner
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@adqm @bedevere-bot @JelleZijlstra @pablogsal @ZeroIntensity @lysnikolaou
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.