Skip to content

Commit 8315bc5

Browse files
authored
Merge pull request #1814 from Shaikh-Ubaid/cpython_class_item
Support syntax for passing struct in CPython
2 parents c45140d + da37514 commit 8315bc5

File tree

5 files changed

+24
-3
lines changed

5 files changed

+24
-3
lines changed

integration_tests/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ RUN(NAME structs_01 LABELS cpython llvm c)
455455
RUN(NAME structs_02 LABELS cpython llvm c)
456456
RUN(NAME structs_03 LABELS llvm c)
457457
RUN(NAME structs_04 LABELS cpython llvm c)
458-
RUN(NAME structs_05 LABELS llvm c)
458+
RUN(NAME structs_05 LABELS cpython llvm c)
459459
RUN(NAME structs_06 LABELS cpython llvm c)
460460
RUN(NAME structs_07 LABELS llvm c
461461
EXTRAFILES structs_07b.c)
@@ -480,6 +480,7 @@ RUN(NAME structs_21 LABELS cpython llvm c)
480480
RUN(NAME structs_22 LABELS cpython llvm c)
481481
RUN(NAME structs_23 LABELS cpython llvm c)
482482
RUN(NAME structs_24 LABELS cpython llvm c)
483+
RUN(NAME structs_25 LABELS cpython llvm c)
483484
RUN(NAME sizeof_01 LABELS llvm c
484485
EXTRAFILES sizeof_01b.c)
485486
RUN(NAME sizeof_02 LABELS cpython llvm c)

integration_tests/structs_05.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ def update_2(s: A[:]):
5050
s[1].c = i8(3)
5151

5252
def g():
53-
# TODO: Enable cpython in integration_tests.
5453
y: A[2] = empty([2], dtype=A)
5554
y[0] = A(1.1, 1, i64(1), f32(1.1), i16(1), i8(1), True)
5655
y[1] = A(2.2, 2, i64(2), f32(2.2), i16(2), i8(2), True)

integration_tests/structs_25.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from lpython import i32, dataclass
2+
from numpy import empty
3+
4+
@dataclass
5+
class Foo:
6+
x: i32
7+
y: i32
8+
9+
def init(foos: Foo[:]) -> None:
10+
foos[0] = Foo(5, 21)
11+
12+
def main0() -> None:
13+
foos: Foo[1] = empty(1, dtype=Foo)
14+
init(foos)
15+
print("foos[0].x =", foos[0].x)
16+
17+
assert foos[0].x == 5
18+
assert foos[0].y == 21
19+
20+
main0()

src/runtime/lpython/lpython.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def __call__(self, arg):
4444
return self._convert(arg)
4545

4646
def dataclass(arg):
47+
arg.__class_getitem__ = lambda self: None
4748
return py_dataclass(arg)
4849

4950
def is_dataclass(obj):

tests/reference/asr-structs_05-fa98307.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"basename": "asr-structs_05-fa98307",
33
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
44
"infile": "tests/../integration_tests/structs_05.py",
5-
"infile_hash": "0ca482232f99c40614dc5b994fa8c9f4865fbe72f5a133b02914b5ad",
5+
"infile_hash": "94d06fb2844e1060d5df5291c3ccc4bd0e2bc8a8a59651814f0c4f0e",
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": "asr-structs_05-fa98307.stdout",

0 commit comments

Comments
 (0)