Skip to content

Commit

Permalink
Fixed issue identify tuples without brackets (lcompilers#1581)
Browse files Browse the repository at this point in the history
* Fixed issue identify tuples without brackets

* Update Readme.md
  • Loading branch information
harshsingh-24 authored Mar 16, 2023
1 parent 78c8347 commit 12971c1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ inst\bin\lpython examples\expr2.py -o a.out
a.out
```

- After you update a test case file, you also need to update all the reference results associated with that test case:

```
python run_tests.py -u --skip-run-with-dbg
```

- To see all the options associated with LPython test suite, use:
```
python run_tests.py --help
```

## Tests (Linux or MacOs):

Run tests:
Expand Down
2 changes: 1 addition & 1 deletion src/lpython/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ augassign_op

ann_assignment_statement
: expr ":" expr { $$ = ANNASSIGN_01($1, $3, @$); }
| expr ":" expr "=" expr { $$ = ANNASSIGN_02($1, $3, $5, @$); }
| expr ":" expr "=" tuple_list { $$ = ANNASSIGN_02($1, $3, $5, @$); }
;

delete_statement
Expand Down
2 changes: 2 additions & 0 deletions tests/parser/tuple1.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ def test():
x,
y,
)

t : tuple[i32, i32] = 2,3 # Without bracket annotated assignment of tuples
4 changes: 2 additions & 2 deletions tests/reference/ast_new-tuple1-29c08af.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"basename": "ast_new-tuple1-29c08af",
"cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}",
"infile": "tests/parser/tuple1.py",
"infile_hash": "921763bd0566e7c1d7afe5cbf4cd8718721598b557d26e26833e8d97",
"infile_hash": "a598d163f33a7eb37376592c8018780cb4024618f4a8024bd728ff15",
"outfile": null,
"outfile_hash": null,
"stdout": "ast_new-tuple1-29c08af.stdout",
"stdout_hash": "79318056f942a6bfd156eeb50a4b48c025adee99f3a26ba81a5ffef9",
"stdout_hash": "482236abb7d6ae21db152d17a82159181ca800c8ba3e7c604eaaab57",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
2 changes: 1 addition & 1 deletion tests/reference/ast_new-tuple1-29c08af.stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(Module [(Assign [(Name a Store)] (BinOp (Tuple [(ConstantInt 1 ())] Load) Add (ConstantInt 4 ())) ()) (Assign [(Name a Store)] (BinOp (BinOp (ConstantInt 3 ()) Mult (Tuple [(ConstantInt 1 ()) (ConstantInt 2 ())] Load)) Add (ConstantInt 4 ())) ()) (Expr (Call (Name f Load) [(Tuple [(Name x Load) (Name y Load)] Load)] [])) (Expr (Call (Name f Load) [(Tuple [(Name x Load)] Load)] [])) (Assign [(Name a Store)] (Call (Name len Load) [(Tuple [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] Load)] []) ()) (Assign [(Name a4 Store)] (Tuple [(Tuple [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] Load) (Tuple [(ConstantInt 4 ()) (ConstantInt 5 ()) (ConstantInt 6 ())] Load)] Load) ()) (Expr (Tuple [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] Load)) (Expr (Tuple [(ConstantInt 1 ()) (ConstantInt 2 ())] Load)) (Expr (BinOp (Tuple [(ConstantInt 1 ()) (ConstantInt 2 ())] Load) Mult (ConstantInt 3 ()))) (Expr (Call (Name print Load) [(BinOp (ConstantStr "%s%s%s" ()) Mod (Tuple [(Name a Load) (Name b Load) (Name c Load)] Load))] [])) (Expr (Call (Name print Load) [(BinOp (ConstantStr "%s%s%s" ()) Mod (Tuple [(BinOp (ConstantInt 10 ()) Add (Name x Load)) (Name y Load) (BinOp (Name z Load) Add (ConstantInt 20 ()))] Load))] [])) (If (Compare (Attribute (Name sys Load) version_info Load) GtE [(Tuple [(ConstantInt 3 ()) (ConstantInt 9 ())] Load)]) [(Pass)] []) (Assign [(Name NDArray Store)] (Call (Name _GenericAlias Load) [(Attribute (Name np Load) ndarray Load) (Tuple [(Name Any Load) (Name _DType Load)] Load)] []) ()) (FunctionDef test ([] [] [] [] [] [] []) [(Pass)] [(Call (Attribute (Attribute (Name pytest Load) mark Load) parametrize Load) [(ConstantStr "shape" ()) (List [(ConstantInt 5 ()) (Tuple [(ConstantInt 3 ()) (ConstantInt 3 ()) (ConstantInt 3 ())] Load)] Load)] [])] () ()) (Assign [(Name _promotion_table Store)] (Dict [(Tuple [(Name int8 Load) (Name int8 Load)] Load)] [(Name int8 Load)]) ()) (Expr (Tuple [(Name x Load) (Name y Load)] Load)) (Expr (Tuple [(Name x Load) (Name y Load)] Load)) (Expr (Tuple [(Call (Name assert_ Load) [(Call (Attribute (Name np Load) isnan Load) [(Name div Load)] [])] []) (BinOp (ConstantStr "dt: %s, rem: %s" ()) Mod (Tuple [(Name dt Load) (Name rem Load)] Load))] Load)) (Expr (Call (Name sum Load) [(ListComp (Subscript (Tuple [(ConstantInt 1 ()) (UnaryOp USub (ConstantInt 1 ()))] Load) (BinOp (Name i Load) Mod (ConstantInt 2 ())) Load) [((Name i Store) (Name x Load) [] 0)])] [])) (Expr (Call (Name sum Load) [(ListComp (Subscript (Tuple [(ConstantInt 1 ()) (UnaryOp USub (ConstantInt 1 ()))] Load) (BinOp (Name i Load) Mod (ConstantInt 2 ())) Load) [((Name i Store) (Name x Load) [] 0)])] [])) (Assign [(Name a Store)] (Tuple [(Name x Load) (Name y Load)] Load) ())] [(TypeIgnore 0 "")])
(Module [(Assign [(Name a Store)] (BinOp (Tuple [(ConstantInt 1 ())] Load) Add (ConstantInt 4 ())) ()) (Assign [(Name a Store)] (BinOp (BinOp (ConstantInt 3 ()) Mult (Tuple [(ConstantInt 1 ()) (ConstantInt 2 ())] Load)) Add (ConstantInt 4 ())) ()) (Expr (Call (Name f Load) [(Tuple [(Name x Load) (Name y Load)] Load)] [])) (Expr (Call (Name f Load) [(Tuple [(Name x Load)] Load)] [])) (Assign [(Name a Store)] (Call (Name len Load) [(Tuple [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] Load)] []) ()) (Assign [(Name a4 Store)] (Tuple [(Tuple [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] Load) (Tuple [(ConstantInt 4 ()) (ConstantInt 5 ()) (ConstantInt 6 ())] Load)] Load) ()) (Expr (Tuple [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] Load)) (Expr (Tuple [(ConstantInt 1 ()) (ConstantInt 2 ())] Load)) (Expr (BinOp (Tuple [(ConstantInt 1 ()) (ConstantInt 2 ())] Load) Mult (ConstantInt 3 ()))) (Expr (Call (Name print Load) [(BinOp (ConstantStr "%s%s%s" ()) Mod (Tuple [(Name a Load) (Name b Load) (Name c Load)] Load))] [])) (Expr (Call (Name print Load) [(BinOp (ConstantStr "%s%s%s" ()) Mod (Tuple [(BinOp (ConstantInt 10 ()) Add (Name x Load)) (Name y Load) (BinOp (Name z Load) Add (ConstantInt 20 ()))] Load))] [])) (If (Compare (Attribute (Name sys Load) version_info Load) GtE [(Tuple [(ConstantInt 3 ()) (ConstantInt 9 ())] Load)]) [(Pass)] []) (Assign [(Name NDArray Store)] (Call (Name _GenericAlias Load) [(Attribute (Name np Load) ndarray Load) (Tuple [(Name Any Load) (Name _DType Load)] Load)] []) ()) (FunctionDef test ([] [] [] [] [] [] []) [(Pass)] [(Call (Attribute (Attribute (Name pytest Load) mark Load) parametrize Load) [(ConstantStr "shape" ()) (List [(ConstantInt 5 ()) (Tuple [(ConstantInt 3 ()) (ConstantInt 3 ()) (ConstantInt 3 ())] Load)] Load)] [])] () ()) (Assign [(Name _promotion_table Store)] (Dict [(Tuple [(Name int8 Load) (Name int8 Load)] Load)] [(Name int8 Load)]) ()) (Expr (Tuple [(Name x Load) (Name y Load)] Load)) (Expr (Tuple [(Name x Load) (Name y Load)] Load)) (Expr (Tuple [(Call (Name assert_ Load) [(Call (Attribute (Name np Load) isnan Load) [(Name div Load)] [])] []) (BinOp (ConstantStr "dt: %s, rem: %s" ()) Mod (Tuple [(Name dt Load) (Name rem Load)] Load))] Load)) (Expr (Call (Name sum Load) [(ListComp (Subscript (Tuple [(ConstantInt 1 ()) (UnaryOp USub (ConstantInt 1 ()))] Load) (BinOp (Name i Load) Mod (ConstantInt 2 ())) Load) [((Name i Store) (Name x Load) [] 0)])] [])) (Expr (Call (Name sum Load) [(ListComp (Subscript (Tuple [(ConstantInt 1 ()) (UnaryOp USub (ConstantInt 1 ()))] Load) (BinOp (Name i Load) Mod (ConstantInt 2 ())) Load) [((Name i Store) (Name x Load) [] 0)])] [])) (Assign [(Name a Store)] (Tuple [(Name x Load) (Name y Load)] Load) ()) (AnnAssign (Name t Store) (Subscript (Name tuple Load) (Tuple [(Name i32 Load) (Name i32 Load)] Load) Load) (Tuple [(ConstantInt 2 ()) (ConstantInt 3 ())] Load) 1)] [(TypeIgnore 0 "")])

0 comments on commit 12971c1

Please sign in to comment.