Support PEP 798 dict-comp unpacking and PEP 810 lazy imports#3094
Draft
Pierre-Sassoulas wants to merge 1 commit into
Draft
Support PEP 798 dict-comp unpacking and PEP 810 lazy imports#3094Pierre-Sassoulas wants to merge 1 commit into
Pierre-Sassoulas wants to merge 1 commit into
Conversation
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).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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
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.
Type of Changes
Description
Python 3.15 adds two AST-level constructs astroid did not model:
{**d for d in dicts}). CPython stores the unpacked mapping inDictComp.keyand leavesvalueasNone, which crashed the rebuilder. astroid now mirrors the{**d}Dict representation with aDictUnpackkey, andas_stringround-trips the construct.ImportandImportFromgain alazyboolean attribute, set from CPython'sis_lazyAST field and rendered byas_string. Name binding and inference are unchanged.List/set/generator comprehension unpacking already parsed; the new
frozendictandsentinelbuiltins 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).