Skip to content

Support PEP 798 dict-comp unpacking and PEP 810 lazy imports#3094

Draft
Pierre-Sassoulas wants to merge 1 commit into
mainfrom
python3.15
Draft

Support PEP 798 dict-comp unpacking and PEP 810 lazy imports#3094
Pierre-Sassoulas wants to merge 1 commit into
mainfrom
python3.15

Conversation

@Pierre-Sassoulas

Copy link
Copy Markdown
Member

Type of Changes

Type
✨ New feature

Description

Python 3.15 adds two AST-level constructs astroid did not model:

  • PEP 798 dict-comprehension unpacking ({**d for d in dicts}). CPython stores the unpacked mapping in DictComp.key and leaves value as None, which crashed the rebuilder. astroid now mirrors the {**d} Dict representation with a DictUnpack key, and as_string round-trips the construct.
  • PEP 810 explicit lazy imports. Import and ImportFrom gain a lazy boolean attribute, set from CPython's is_lazy AST field and rendered by as_string. Name binding and inference are unchanged.

List/set/generator comprehension unpacking already parsed; the new frozendict and sentinel builtins are inferred for free via raw-building. Tests live next to the feature they exercise (lazy imports in ImportNodeTest, comprehension unpacking in Python3TC, builtin inference in InferenceTest), gated with skipif(not PY315_PLUS).

Python 3.15 adds two AST-level constructs astroid did not model:

- PEP 798 dict-comprehension unpacking (``{**d for d in dicts}``).
  CPython stores the unpacked mapping in ``DictComp.key`` and leaves
  ``value`` as ``None``, which crashed the rebuilder. astroid now mirrors
  the ``{**d}`` Dict representation with a ``DictUnpack`` key, and
  ``as_string`` round-trips the construct.
- PEP 810 explicit lazy imports. ``Import`` and ``ImportFrom`` gain a
  ``lazy`` boolean attribute, set from CPython's ``is_lazy`` AST field and
  rendered by ``as_string``. Name binding and inference are unchanged.

List/set/generator comprehension unpacking already parsed; the new
``frozendict`` and ``sentinel`` builtins are inferred for free via
raw-building. Tests live next to the feature they exercise (lazy imports
in ImportNodeTest, comprehension unpacking in Python3TC, builtin inference
in InferenceTest), gated with skipif(not PY315_PLUS).
@Pierre-Sassoulas Pierre-Sassoulas added this to the 4.2.0 milestone Jun 8, 2026
@codspeed-hq

codspeed-hq Bot commented Jun 8, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 3 untouched benchmarks


Comparing python3.15 (4ddf096) with main (c50a1f4)

Open in CodSpeed

@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.62%. Comparing base (926f4c9) to head (4ddf096).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3094      +/-   ##
==========================================
+ Coverage   93.60%   93.62%   +0.01%     
==========================================
  Files          92       92              
  Lines       11364    11380      +16     
==========================================
+ Hits        10637    10654      +17     
+ Misses        727      726       -1     
Flag Coverage Δ
linux 93.48% <100.00%> (+0.01%) ⬆️
pypy 93.62% <100.00%> (+0.01%) ⬆️
windows 93.59% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
astroid/nodes/as_string.py 97.34% <100.00%> (+0.29%) ⬆️
astroid/nodes/node_classes.py 95.15% <100.00%> (+<0.01%) ⬆️
astroid/rebuilder.py 98.84% <100.00%> (+0.01%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant