mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
allow complex assignment in class definition
This commit is contained in:
parent
438857a1f5
commit
74e31b36ed
@ -41,3 +41,4 @@ The easiest way to test a feature is to [try it on your browser](https://pocketp
|
||||
8. In a starred unpacked assignment, e.g. `a, b, *c = x`, the starred variable can only be presented in the last position. `a, *b, c = x` is not supported.
|
||||
9. A `Tab` is equivalent to 4 spaces. You can mix `Tab` and spaces in indentation, but it is not recommended.
|
||||
10. `%`, `&`, `//`, `^` and `|` for `int` behave the same as C, not python.
|
||||
11. `str.split` and `str.splitlines` will remove all empty entries.
|
||||
|
@ -728,15 +728,8 @@ __EAT_DOTS_END:
|
||||
int n = 0;
|
||||
while(match(TK("="))){
|
||||
EXPR_TUPLE();
|
||||
Expr* _tp = ctx()->s_expr.top().get();
|
||||
if(ctx()->is_compiling_class && _tp->is_tuple()){
|
||||
SyntaxError("can't use unpack tuple in class definition");
|
||||
}
|
||||
n += 1;
|
||||
}
|
||||
if(ctx()->is_compiling_class && n>1){
|
||||
SyntaxError("can't assign to multiple targets in class definition");
|
||||
}
|
||||
// stack size is n+1
|
||||
Expr_ val = ctx()->s_expr.popx();
|
||||
val->emit_(ctx());
|
||||
|
@ -119,3 +119,13 @@ class A:
|
||||
assert A.x == 2
|
||||
assert A.y == 1
|
||||
assert A.z == 3
|
||||
|
||||
class MyClass:
|
||||
a = 1,2,3
|
||||
b, c = 1, 2
|
||||
d = b + c
|
||||
|
||||
assert MyClass.a == (1, 2, 3)
|
||||
assert MyClass.b == 1
|
||||
assert MyClass.c == 2
|
||||
assert MyClass.d == 3
|
||||
|
Loading…
x
Reference in New Issue
Block a user