Skip to content

Commit 4a10c8b

Browse files
committed
TEST: Add for dataclass field()
1 parent b02eca1 commit 4a10c8b

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

integration_tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,7 @@ RUN(NAME structs_31 LABELS cpython llvm c)
685685
RUN(NAME structs_32 LABELS cpython llvm c)
686686
RUN(NAME structs_33 LABELS cpython llvm c)
687687
RUN(NAME structs_34 LABELS cpython llvm c)
688+
RUN(NAME structs_35 LABELS cpython llvm c)
688689

689690
RUN(NAME symbolics_01 LABELS cpython_sym c_sym llvm_sym NOFAST)
690691
RUN(NAME symbolics_02 LABELS cpython_sym c_sym llvm_sym NOFAST)

integration_tests/structs_35.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from lpython import dataclass, field, i32
2+
from numpy import array
3+
4+
@dataclass
5+
class X:
6+
a: i32 = 123
7+
b: bool = True
8+
c: list[i32] = field(default_factory=lambda: [1, 2, 3])
9+
d: i32[3] = field(default_factory=lambda: array([4, 5, 6]))
10+
e: i32 = field(default=-5)
11+
12+
def main0():
13+
x: X = X()
14+
print(x)
15+
assert x.a == 123
16+
assert x.b == True
17+
assert x.c[0] == 1
18+
assert x.d[1] == 5
19+
assert x.e == -5
20+
x.c[0] = 3
21+
x.d[0] = 3
22+
print(x)
23+
assert x.c[0] == 3
24+
assert x.d[0] == 3
25+
26+
main0()

0 commit comments

Comments
 (0)