Skip to content

gh-143055: Fix crash in AST unparser when unparsing dict comprehension unpacking#145556

Open
StanFromIreland wants to merge 4 commits intopython:mainfrom
StanFromIreland:dict-comp-unparse
Open

gh-143055: Fix crash in AST unparser when unparsing dict comprehension unpacking#145556
StanFromIreland wants to merge 4 commits intopython:mainfrom
StanFromIreland:dict-comp-unparse

Conversation

@StanFromIreland
Copy link
Member

@StanFromIreland StanFromIreland commented Mar 5, 2026

>>> from __future__ import annotations
... 
... spam: {**x for x in ()}
... 
Segmentation fault (core dumped)

Found by OSS Fuzz in #489790200.

eq("{**x for x in ()}")
eq("[(x, y) for x, y in (a, b)]")
eq("[(x,) for x, in (a,)]")
eq("Python3 > Python2 > COBOL")
Copy link
Member

Choose a reason for hiding this comment

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

Would you mind adding tests for the corresponding case with list comprehensions too?

>>> from __future__ import annotations
>>> def f(x: [*x for x in y]): pass
... 
>>> f.__annotations__
{'x': '[*x for x in y]'}

It seems to work correctly already but we should test it explicitly.

@StanFromIreland
Copy link
Member Author

Something broke with the CI:-(

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.

2 participants