Skip to content

Commit 8c42eaf

Browse files
authored
Merge pull request #2285 from Shaikh-Ubaid/remove_dataclass_emulation
Remove dataclass emulation
2 parents 984ca76 + 8759288 commit 8c42eaf

File tree

5 files changed

+12
-19
lines changed

5 files changed

+12
-19
lines changed

integration_tests/bindc_08.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# file: main.py
2-
from lpython import CPtr, i32, dataclass, c_p_pointer, Pointer, empty_c_void_p, p_c_pointer
2+
from lpython import CPtr, i32, dataclass, c_p_pointer, Pointer, empty_c_void_p, p_c_pointer, Array
33

44
from numpy import empty, array
55

@@ -9,11 +9,11 @@ class Foo:
99
y: i32
1010

1111
def init(foos_ptr: CPtr) -> None:
12-
foos: Pointer[Foo[:]] = c_p_pointer(foos_ptr, Foo[:], array([1]))
12+
foos: Pointer[Array[Foo, :]] = c_p_pointer(foos_ptr, Array[Foo, :], array([1]))
1313
foos[0] = Foo(3, 2)
1414

1515
def main() -> None:
16-
foos: Foo[1] = empty(1, dtype=Foo)
16+
foos: Array[Foo, 1] = empty(1, dtype=Foo)
1717
foos_ptr: CPtr = empty_c_void_p()
1818
foos[0] = Foo(0, 1)
1919
p_c_pointer(foos, foos_ptr)

integration_tests/structs_05.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from lpython import i32, f64, i64, i16, i8, f32, dataclass, InOut
1+
from lpython import i32, f64, i64, i16, i8, f32, dataclass, InOut, Array
22
from numpy import empty
33

44
@dataclass
@@ -11,7 +11,7 @@ class A:
1111
c: i8
1212
d: bool
1313

14-
def verify(s: A[:], x1: i32, y1: f64, x2: i32, y2: f64):
14+
def verify(s: Array[A, :], x1: i32, y1: f64, x2: i32, y2: f64):
1515
eps: f64 = 1e-12
1616
s0: A = s[0]
1717
print(s0.x, s0.y, s0.z, s0.a, s0.b, s0.c, s0.d)
@@ -41,7 +41,7 @@ def update_1(s: InOut[A]):
4141
s.b = i16(2)
4242
s.c = i8(2)
4343

44-
def update_2(s: A[:]):
44+
def update_2(s: Array[A, :]):
4545
s[1].x = 3
4646
s[1].y = 2.3
4747
s[1].z = i64(3)
@@ -50,7 +50,7 @@ def update_2(s: A[:]):
5050
s[1].c = i8(3)
5151

5252
def g():
53-
y: A[2] = empty([2], dtype=A)
53+
y: Array[A, 2] = empty([2], dtype=A)
5454
y[0] = A(1.1, 1, i64(1), f32(1.1), i16(1), i8(1), True)
5555
y[1] = A(2.2, 2, i64(2), f32(2.2), i16(2), i8(2), True)
5656
verify(y, 1, 1.1, 2, 2.2)

integration_tests/structs_25.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
from lpython import i32, dataclass
1+
from lpython import i32, dataclass, Array
22
from numpy import empty
33

44
@dataclass
55
class Foo:
66
x: i32
77
y: i32
88

9-
def init(foos: Foo[:]) -> None:
9+
def init(foos: Array[Foo, :]) -> None:
1010
foos[0] = Foo(5, 21)
1111

1212
def main0() -> None:
13-
foos: Foo[1] = empty(1, dtype=Foo)
13+
foos: Array[Foo, 1] = empty(1, dtype=Foo)
1414
init(foos)
1515
print("foos[0].x =", foos[0].x)
1616

src/runtime/lpython/lpython.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
import ctypes
44
import platform
5-
from dataclasses import dataclass as py_dataclass, is_dataclass as py_is_dataclass, field
5+
from dataclasses import dataclass, field, is_dataclass as py_is_dataclass
66
import functools
77

88

@@ -48,13 +48,6 @@ def __getitem__(self, params):
4848
def __call__(self, arg):
4949
return self._convert(arg)
5050

51-
def dataclass(arg):
52-
def __class_getitem__(key):
53-
return Array(arg, key)
54-
arg.__class_getitem__ = __class_getitem__
55-
56-
return py_dataclass(arg)
57-
5851
def is_ctypes_Structure(obj):
5952
return (isclass(obj) and issubclass(obj, ctypes.Structure))
6053

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": "5c587158fe09782d15aa8f5f9c24468c62795e9f537a9eb439d8e8a4",
5+
"infile_hash": "ef1037b0936a63be679efd366920a94463900e80630a070ba440aa78",
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": "asr-structs_05-fa98307.stdout",

0 commit comments

Comments
 (0)