Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse ellipsis (...) in the old parser #503

Merged
merged 3 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add tests and Update the references
  • Loading branch information
Thirumalai-Shaktivel committed May 18, 2022
commit c57fa7b398ccd3cbda125f59e93bbeaa7fee3749
37 changes: 37 additions & 0 deletions tests/parser/ellipsis1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import numpy as np
from typing import Callable

array = np.random.rand(2, 2, 2, 2)
print(array[..., 0])
print(array[Ellipsis, 0])

def inject(get_next_item: Callable[..., str]) -> None:
...

def foo(x: ...) -> None:
...

class flow:
def __understand__(self, name: str, value: ...) -> None: ...

def foo(x = ...):
return x

def test():
...

class Todo:
...

x = [1, [2, [...], 3]]
l = [..., 1, 2, 3]

if x is ...:
pass

def partial(func: Callable[..., str], *args) -> Callable[..., str]:
pass

class xyz:
abc: str = ...
def __init__(self, name: str=...) -> None: ...
13 changes: 13 additions & 0 deletions tests/reference/ast-ellipsis1-4f6c4dd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "ast-ellipsis1-4f6c4dd",
"cmd": "lpython --show-ast --no-color {infile} -o {outfile}",
"infile": "tests/parser/ellipsis1.py",
"infile_hash": "24df29cba718c679016f3758a2eccafbeb9cfebd56265fd8da16bee1",
"outfile": null,
"outfile_hash": null,
"stdout": "ast-ellipsis1-4f6c4dd.stdout",
"stdout_hash": "99ae0e12fd8efcd71433e66f10ba7ba5b59e165ddd5ded0072593b12",
"stderr": null,
"stderr_hash": null,
"returncode": 0
}
1 change: 1 addition & 0 deletions tests/reference/ast-ellipsis1-4f6c4dd.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(Module [(Import [(numpy np)]) (ImportFrom typing [(Callable ())] 0) (Assign [(Name array Store)] (Call (Attribute (Attribute (Name np Load) random Load) rand Load) [(ConstantInt 2 ()) (ConstantInt 2 ()) (ConstantInt 2 ()) (ConstantInt 2 ())] []) ()) (Expr (Call (Name print Load) [(Subscript (Name array Load) (Tuple [(ConstantEllipsis ()) (ConstantInt 0 ())] Load) Load)] [])) (Expr (Call (Name print Load) [(Subscript (Name array Load) (Tuple [(Name Ellipsis Load) (ConstantInt 0 ())] Load) Load)] [])) (FunctionDef inject ([] [(get_next_item (Subscript (Name Callable Load) (Tuple [(ConstantEllipsis ()) (Name str Load)] Load) Load) ())] [] [] [] [] []) [(Expr (ConstantEllipsis ()))] [] (ConstantNone ()) ()) (FunctionDef foo ([] [(x (ConstantEllipsis ()) ())] [] [] [] [] []) [(Expr (ConstantEllipsis ()))] [] (ConstantNone ()) ()) (ClassDef flow [] [] [(FunctionDef __understand__ ([] [(self () ()) (name (Name str Load) ()) (value (ConstantEllipsis ()) ())] [] [] [] [] []) [(Expr (ConstantEllipsis ()))] [] (ConstantNone ()) ())] []) (FunctionDef foo ([] [(x () ())] [] [] [] [] [(ConstantEllipsis ())]) [(Return (Name x Load))] [] () ()) (FunctionDef test ([] [] [] [] [] [] []) [(Expr (ConstantEllipsis ()))] [] () ()) (ClassDef Todo [] [] [(Expr (ConstantEllipsis ()))] []) (Assign [(Name x Store)] (List [(ConstantInt 1 ()) (List [(ConstantInt 2 ()) (List [(ConstantEllipsis ())] Load) (ConstantInt 3 ())] Load)] Load) ()) (Assign [(Name l Store)] (List [(ConstantEllipsis ()) (ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] Load) ()) (If (Compare (Name x Load) Is [(ConstantEllipsis ())]) [(Pass)] []) (FunctionDef partial ([] [(func (Subscript (Name Callable Load) (Tuple [(ConstantEllipsis ()) (Name str Load)] Load) Load) ())] [(args () ())] [] [] [] []) [(Pass)] [] (Subscript (Name Callable Load) (Tuple [(ConstantEllipsis ()) (Name str Load)] Load) Load) ()) (ClassDef xyz [] [] [(AnnAssign (Name abc Store) (Name str Load) (ConstantEllipsis ()) 1) (FunctionDef __init__ ([] [(self () ()) (name (Name str Load) ())] [] [] [] [] [(ConstantEllipsis ())]) [(Expr (ConstantEllipsis ()))] [] (ConstantNone ()) ())] [])] [])
4 changes: 4 additions & 0 deletions tests/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ ast_new = true
filename = "parser/slice1.py"
ast_new = true

[[test]]
filename = "parser/ellipsis1.py"
ast = true

# tests/errors

[[test]]
Expand Down