mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-21 03:50:16 +00:00
This commit is contained in:
parent
7bd99279e5
commit
b65cf89d22
@ -1155,6 +1155,17 @@ __EAT_DOTS_END:
|
|||||||
case TK("False"): return VAR(false);
|
case TK("False"): return VAR(false);
|
||||||
case TK("None"): return vm->None;
|
case TK("None"): return vm->None;
|
||||||
case TK("..."): return vm->Ellipsis;
|
case TK("..."): return vm->Ellipsis;
|
||||||
|
case TK("("): {
|
||||||
|
List cpnts;
|
||||||
|
while(true) {
|
||||||
|
cpnts.push_back(read_literal());
|
||||||
|
if(curr().type == TK(")")) break;
|
||||||
|
consume(TK(","));
|
||||||
|
if(curr().type == TK(")")) break;
|
||||||
|
}
|
||||||
|
consume(TK(")"));
|
||||||
|
return VAR(Tuple(std::move(cpnts)));
|
||||||
|
}
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -91,4 +91,31 @@ S, kwargs = g(1, 2, 3, 4, 5, c=4, e=5, f=6)
|
|||||||
# S = 1 + 2 + 4 + 2 + 12 = 21
|
# S = 1 + 2 + 4 + 2 + 12 = 21
|
||||||
|
|
||||||
assert S == 21
|
assert S == 21
|
||||||
assert kwargs == {'e': 5, 'f': 6}
|
assert kwargs == {'e': 5, 'f': 6}
|
||||||
|
|
||||||
|
# test tuple defaults
|
||||||
|
|
||||||
|
def f(a=(1,)):
|
||||||
|
return a
|
||||||
|
assert f() == (1,)
|
||||||
|
|
||||||
|
def f(a=(1,2)):
|
||||||
|
return a
|
||||||
|
assert f() == (1,2)
|
||||||
|
|
||||||
|
def f(a=(1,2,3)):
|
||||||
|
return a
|
||||||
|
assert f() == (1,2,3)
|
||||||
|
|
||||||
|
def f(a=(1,2,3,)):
|
||||||
|
return a
|
||||||
|
assert f() == (1,2,3)
|
||||||
|
|
||||||
|
def f(a=(1,(2,3))):
|
||||||
|
return a
|
||||||
|
assert f() == (1,(2,3))
|
||||||
|
|
||||||
|
def f(a=((1,2),3), b=(4,)):
|
||||||
|
return a, b
|
||||||
|
|
||||||
|
assert f() == (((1,2),3), (4,))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user