mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
add full typehints support
This commit is contained in:
parent
db283d4ba6
commit
492c3fda00
@ -814,6 +814,8 @@ __SUBSCR_END:
|
|||||||
default: {
|
default: {
|
||||||
advance(-1); // do revert since we have pre-called advance() at the beginning
|
advance(-1); // do revert since we have pre-called advance() at the beginning
|
||||||
EXPR_TUPLE();
|
EXPR_TUPLE();
|
||||||
|
// eat variable's type hint
|
||||||
|
if(match(TK(":"))) consume_type_hints();
|
||||||
if(!try_compile_assignment()){
|
if(!try_compile_assignment()){
|
||||||
ctx()->emit_expr();
|
ctx()->emit_expr();
|
||||||
if((mode()==CELL_MODE || mode()==REPL_MODE) && name_scope()==NAME_GLOBAL){
|
if((mode()==CELL_MODE || mode()==REPL_MODE) && name_scope()==NAME_GLOBAL){
|
||||||
@ -827,6 +829,10 @@ __SUBSCR_END:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void consume_type_hints(){
|
||||||
|
EXPR();
|
||||||
|
ctx()->s_expr.pop();
|
||||||
|
}
|
||||||
|
|
||||||
void compile_class(){
|
void compile_class(){
|
||||||
consume(TK("@id"));
|
consume(TK("@id"));
|
||||||
@ -876,7 +882,7 @@ __SUBSCR_END:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// eat type hints
|
// eat type hints
|
||||||
if(enable_type_hints && match(TK(":"))) consume(TK("@id"));
|
if(enable_type_hints && match(TK(":"))) consume_type_hints();
|
||||||
if(state == 0 && curr().type == TK("=")) state = 2;
|
if(state == 0 && curr().type == TK("=")) state = 2;
|
||||||
int index = ctx()->add_varname(name);
|
int index = ctx()->add_varname(name);
|
||||||
switch (state)
|
switch (state)
|
||||||
@ -917,9 +923,7 @@ __SUBSCR_END:
|
|||||||
_compile_f_args(decl, true);
|
_compile_f_args(decl, true);
|
||||||
consume(TK(")"));
|
consume(TK(")"));
|
||||||
}
|
}
|
||||||
if(match(TK("->"))){
|
if(match(TK("->"))) consume_type_hints();
|
||||||
if(!match(TK("None"))) consume(TK("@id"));
|
|
||||||
}
|
|
||||||
compile_block_body();
|
compile_block_body();
|
||||||
pop_context();
|
pop_context();
|
||||||
|
|
||||||
|
@ -42,3 +42,16 @@ def i(x, y: int, *args):
|
|||||||
|
|
||||||
def j(x, y: int, *args: str) -> int:
|
def j(x, y: int, *args: str) -> int:
|
||||||
return x + y + len(args)
|
return x + y + len(args)
|
||||||
|
|
||||||
|
x: int = 1
|
||||||
|
y: 'str' = '2'
|
||||||
|
|
||||||
|
x: 'list[int]' = [1, 2, 3]
|
||||||
|
y: 'list[str]' = ['1', '2', '3']
|
||||||
|
|
||||||
|
def g(x: 'list[int]', y: 'list[str]') -> 'list[int]':
|
||||||
|
return x + y
|
||||||
|
|
||||||
|
def z(x: float):
|
||||||
|
x: int = 1
|
||||||
|
y: 'str' = '2'
|
Loading…
x
Reference in New Issue
Block a user