fix: render dict **-unpacking as **value instead of None: value#467
Merged
Conversation
`ExprDict.iterate` rendered the `None` key that the AST uses to mark a
`**`-unpacked value as a literal `None: value`, producing invalid Python
(e.g. `{None: base, 'x': 1}` for `{**base, 'x': 1}`). Render those entries
as `**value`. A genuine `None` literal key is an `ast.Constant` rather
than the AST's unpacking marker, so it is preserved.
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.
Description
ExprDict.iteraterenders theNonekey that the AST uses to mark a**-unpacked value as a literalNone: value, producing invalid (and semantically wrong) Python:_build_dictfaithfully preserves the AST'sNone-key unpacking marker, butiteratethen renders it with the literal text"None". This affects any rendered signature/default/annotation containing a dict with**-unpacking.The fix renders entries whose key is the unpacking marker as
**value(nokey:part):A genuine
Noneliteral key is anast.Constant, not the AST's unpacking marker, so it is left untouched ({None: 1, "y": 2}still renders as{None: 1, 'y': 2}).Verification
test_render_dict_with_unpackingcovering**-spread, multiple spreads, and the literal-None-key case.griffelibsuite passes with no new failures (the unrelatedtest_finder.py::test_pth_file_handling*andtest_api/test_gitfailures are pre-existing on this environment, identical with the change stashed).This pull request was prepared with the assistance of AI, under my direction and review.