Describe the bug
Griffe raises a KeyError when it encounters a walrus operator (NamedExpr) in the output part of a list, set or dict comprehension, or a generator expression.
To Reproduce
Steps to reproduce the behavior:
- Save the following example code to "test.py"
defbar(value):
returnvaluefoo= [resultif (result:=bar(v)) elsevforvin (1,2,3)]
- Run command
griffe dump -s . test - Scroll up to the start of the command's output
- See an error like the following:
ERRORFailedtounparsenode<ast.ListCompobjectat0x000001C826AAF4C0>attest.py:4:<class'ast.NamedExpr'>Traceback (mostrecentcalllast):
File"C:\Users\Lucina\PycharmProjects\tanjun\venv\lib\site-packages\griffe\agents\nodes.py", line1240, insafe_get_valuereturnget_value(node)
File"C:\Users\Lucina\PycharmProjects\tanjun\venv\lib\site-packages\griffe\agents\nodes.py", line1226, inget_valuereturn_node_value_map[type(node)](node)
File"C:\Users\Lucina\PycharmProjects\tanjun\venv\lib\site-packages\griffe\agents\nodes.py", line1005, in_get_listcomp_valueelement=_get_value(node.elt)
File"C:\Users\Lucina\PycharmProjects\tanjun\venv\lib\site-packages\griffe\agents\nodes.py", line1212, in_get_valuereturn_node_value_map[type(node)](node)
File"C:\Users\Lucina\PycharmProjects\tanjun\venv\lib\site-packages\griffe\agents\nodes.py", line965, in_get_ifexp_valuereturnf"{_get_value(node.body)} if {_get_value(node.test)} else {_get_value(node.orelse)}"File"C:\Users\Lucina\PycharmProjects\tanjun\venv\lib\site-packages\griffe\agents\nodes.py", line1212, in_get_valuereturn_node_value_map[type(node)](node)
KeyError:<class'ast.NamedExpr'>Expected behavior
This should parse without error as this is valid syntax (which runs fine).
System (please complete the following information):
griffe version: griffe-0.27.1- Python version: 3.10.9
- OS: Windows
Describe the bug
Griffe raises a KeyError when it encounters a walrus operator (NamedExpr) in the output part of a list, set or dict comprehension, or a generator expression.
To Reproduce
Steps to reproduce the behavior:
griffe dump -s . testExpected behavior
This should parse without error as this is valid syntax (which runs fine).
System (please complete the following information):
griffeversion: griffe-0.27.1