Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
2f0b026a
Commit
2f0b026a
authored
Feb 10, 2014
by
Paul Sokolovsky
Browse files
Clean up handling of function return type annotation.
parent
76f06de9
Changes
3
Hide whitespace changes
Inline
Side-by-side
py/compile.c
View file @
2f0b026a
...
...
@@ -2764,7 +2764,7 @@ void compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) {
apply_to_single_or_list
(
comp
,
pns
->
nodes
[
1
],
PN_typedargslist
,
compile_scope_func_param
);
}
assert
(
MP_PARSE_NODE_IS_NULL
(
pns
->
nodes
[
2
]));
// 2 is something...
// pns->nodes[2] is return/whole function annotation
compile_node
(
comp
,
pns
->
nodes
[
3
]);
// 3 is function body
// emit return if it wasn't the last opcode
...
...
py/grammar.h
View file @
2f0b026a
...
...
@@ -33,8 +33,8 @@ DEF_RULE(decorator, nc, and(4), tok(DEL_AT), rule(dotted_name), opt_rule(trailer
DEF_RULE
(
decorators
,
nc
,
one_or_more
,
rule
(
decorator
))
DEF_RULE
(
decorated
,
c
(
decorated
),
and
(
2
),
rule
(
decorators
),
rule
(
decorated_body
))
DEF_RULE
(
decorated_body
,
nc
,
or
(
2
),
rule
(
classdef
),
rule
(
funcdef
))
DEF_RULE
(
funcdef
,
c
(
funcdef
),
and
(
8
),
tok
(
KW_DEF
),
tok
(
NAME
),
tok
(
DEL_PAREN_OPEN
),
opt_rule
(
typedargslist
),
tok
(
DEL_PAREN_CLOSE
),
opt_rule
(
funcdef
_2
),
tok
(
DEL_COLON
),
rule
(
suite
))
DEF_RULE
(
funcdef
_2
,
nc
,
and
(
2
),
tok
(
DEL_MINUS_MORE
),
rule
(
test
))
DEF_RULE
(
funcdef
,
c
(
funcdef
),
and
(
8
),
tok
(
KW_DEF
),
tok
(
NAME
),
tok
(
DEL_PAREN_OPEN
),
opt_rule
(
typedargslist
),
tok
(
DEL_PAREN_CLOSE
),
opt_rule
(
funcdef
rettype
),
tok
(
DEL_COLON
),
rule
(
suite
))
DEF_RULE
(
funcdef
rettype
,
nc
,
and
(
2
),
tok
(
DEL_MINUS_MORE
),
rule
(
test
))
// TODO typedargslist lets through more than is allowed
DEF_RULE
(
typedargslist
,
nc
,
list_with_end
,
rule
(
typedargslist_item
),
tok
(
DEL_COMMA
))
DEF_RULE
(
typedargslist_item
,
nc
,
or
(
3
),
rule
(
typedargslist_name
),
rule
(
typedargslist_star
),
rule
(
typedargslist_dbl_star
))
...
...
tests/basics/fun-annotations.py
0 → 100644
View file @
2f0b026a
def
foo
(
x
:
int
,
y
:
list
)
->
dict
:
return
{
x
:
y
}
print
(
foo
(
1
,
[
2
,
3
]))
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment