Skip to content

Commit 3aa8515

Browse files
Merge pull request #998 from Thirumalai-Shaktivel/fix_dict
2 parents d211ad2 + 89031a0 commit 3aa8515

File tree

5 files changed

+11
-3
lines changed

5 files changed

+11
-3
lines changed

src/lpython/parser/parser.yy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ expr_list
782782
dict
783783
: expr ":" expr { $$ = DICT_EXPR_01($1, $3, @$); }
784784
| expr ":" type_comment expr { $$ = DICT_EXPR_02($1, $3, $4, @$); }
785+
| "**" expr { $$ = DICT_EXPR_01(NONE(@$), $2, @$); }
785786
;
786787

787788
dict_list

src/runtime/lpython_parser.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ def generic_visit(self, node):
7878
else:
7979
if type(item) == str:
8080
new_list.append(item)
81+
elif item is None:
82+
new_list.append(self.visit(python_ast.ConstantNone()))
8183
d[field] = new_list
8284
elif field in ["vararg", "kwarg"]:
8385
if value is None:

tests/parser/dictionary1.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,10 @@ def test():
2323
Text
2424
"""
2525
}
26+
x = { **x,
27+
y: "Text",
28+
**z,
29+
None: "None",
30+
}
2631

2732
test()

tests/reference/ast_new-dictionary1-445e718.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
"basename": "ast_new-dictionary1-445e718",
33
"cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}",
44
"infile": "tests/parser/dictionary1.py",
5-
"infile_hash": "78286c2c3a7c6d9117f44c91c603e6fb1c853ca3d67a4cdb18febb9a",
5+
"infile_hash": "68922e77dbabe06c271463150653684880d3c28d88caa44109b2e202",
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": "ast_new-dictionary1-445e718.stdout",
9-
"stdout_hash": "cb5ae051657fc4158ecfed7d4af3d3f249e58cec2bada5b75863c336",
9+
"stdout_hash": "e9aefdd2d9d42dfe673563ff13d1f91ce6dcd672d1237506f540cb90",
1010
"stderr": null,
1111
"stderr_hash": null,
1212
"returncode": 0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
(Module [(FunctionDef test ([] [] [] [] [] [] []) [(Assign [(Name x Store)] (Dict [] []) ()) (Assign [(Name dict Store)] (Dict [(ConstantStr "brand" ()) (ConstantStr "electric" ()) (ConstantStr "year" ()) (ConstantStr "colors" ())] [(ConstantStr "Ford" ()) (ConstantBool .false. ()) (ConstantInt 1964 ()) (List [(ConstantStr "red" ()) (ConstantStr "white" ())] Load)]) ()) (Assign [(Name num Store)] (Dict [(ConstantInt 1 ()) (ConstantInt 2 ())] [(ConstantInt 2 ()) (ConstantInt 3 ())]) ()) (AnnAssign (Name y Store) (Subscript (Name dict Load) (Tuple [(Name str Load) (Name i32 Load)] Load) Load) () 1) (Assign [(Name y Store)] (Dict [(ConstantStr "a" ()) (ConstantStr "b" ())] [(UnaryOp USub (ConstantInt 1 ())) (UnaryOp USub (ConstantInt 2 ()))]) ()) (Assign [(Name y Store)] (Dict [(ConstantStr "a" ()) (ConstantStr "b" ())] [(UnaryOp USub (ConstantInt 1 ())) (UnaryOp USub (ConstantInt 2 ()))]) ()) (Assign [(Subscript (Name y Load) (ConstantStr "a" ()) Store)] (ConstantInt 123 ()) ()) (Assign [(Name a Store)] (Dict [(ConstantStr "a" ()) (ConstantStr "b" ())] [(ConstantInt 1 ()) (ConstantInt 2 ())]) ()) (Assign [(Name x Store)] (Dict [(ConstantStr "markdown2.tpl" ())] [(ConstantStr "\
22
Text
3-
" ())]) ())] [] () ()) (Expr (Call (Name test Load) [] []))] [(TypeIgnore 0 "")])
3+
" ())]) ()) (Assign [(Name x Store)] (Dict [(ConstantNone ()) (Name y Load) (ConstantNone ()) (ConstantNone ())] [(Name x Load) (ConstantStr "Text" ()) (Name z Load) (ConstantStr "None" ())]) ())] [] () ()) (Expr (Call (Name test Load) [] []))] [(TypeIgnore 0 "")])

0 commit comments

Comments
 (0)