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

Fix issue-920 #933

Merged
merged 1 commit into from
Aug 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions src/lpython/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ dot_list

import_statement
: KW_IMPORT module_item_list { $$ = IMPORT_01($2, @$); }
| KW_IMPORT module_item_list TK_TYPE_COMMENT { $$ = IMPORT_01($2, @$); }
| KW_FROM module KW_IMPORT module_item_list {
$$ = IMPORT_02($2, $4, @$); }
| KW_FROM module KW_IMPORT "(" module_item_list comma_opt ")" {
Expand Down Expand Up @@ -667,6 +668,12 @@ function_def
| decorators_opt KW_DEF id "(" parameter_list_opt ")" "->" expr ":"
TK_TYPE_COMMENT TK_NEWLINE statements {
$$ = FUNCTION_04($1, $3, $5, $8, $12, $10, @$); }
| decorators_opt KW_DEF id "(" parameter_list_opt ")" ":"
TK_NEWLINE TK_TYPE_COMMENT TK_NEWLINE statements {
$$ = FUNCTION_03($1, $3, $5, $11, $9, @$); }
| decorators_opt KW_DEF id "(" parameter_list_opt ")" "->" expr ":"
TK_NEWLINE TK_TYPE_COMMENT TK_NEWLINE statements {
$$ = FUNCTION_04($1, $3, $5, $8, $13, $11, @$); }
;

class_def
Expand Down
5 changes: 5 additions & 0 deletions tests/parser/type_comment1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import pytest # type: ignore

def ndarray_func(x):
# type: (np.ndarray) -> np.ndarray
return x
13 changes: 13 additions & 0 deletions tests/reference/ast_new-type_comment1-710ea6c.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "ast_new-type_comment1-710ea6c",
"cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}",
"infile": "tests/parser/type_comment1.py",
"infile_hash": "cdc0bdd0faec912e7f3db4e71c4a14aa281828e8b68faac91f5a78ee",
"outfile": null,
"outfile_hash": null,
"stdout": "ast_new-type_comment1-710ea6c.stdout",
"stdout_hash": "98ccc7f80021238fff1a1a1395e64b5d2097f025e60e47821ec76fdb",
"stderr": null,
"stderr_hash": null,
"returncode": 0
}
1 change: 1 addition & 0 deletions tests/reference/ast_new-type_comment1-710ea6c.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(Module [(Import [(pytest ())]) (FunctionDef ndarray_func ([] [(x () ())] [] [] [] [] []) [(Return (Name x Load))] [] () "(np.ndarray) -> np.ndarray")] [])
4 changes: 4 additions & 0 deletions tests/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,10 @@ ast_new = true
filename = "parser/tuple1.py"
ast_new = true

[[test]]
filename = "parser/type_comment1.py"
ast_new = true

# tests/errors

[[test]]
Expand Down