1
1
from __future__ import annotations
2
2
3
3
import typing
4
+ import warnings
4
5
from collections .abc import Callable
5
6
6
7
from mlc ._cython import PyAny , TypeInfo , c_class_core
@@ -21,42 +22,6 @@ def id_(self) -> int:
21
22
def is_ (self , other : Object ) -> bool :
22
23
return isinstance (other , Object ) and self ._mlc_address == other ._mlc_address
23
24
24
- def json (
25
- self ,
26
- fn_opaque_serialize : Callable [[list [typing .Any ]], str ] | None = None ,
27
- ) -> str :
28
- return super ()._mlc_json (fn_opaque_serialize )
29
-
30
- @staticmethod
31
- def from_json (
32
- json_str : str ,
33
- fn_opaque_deserialize : Callable [[str ], list [typing .Any ]] | None = None ,
34
- ) -> Object :
35
- return PyAny ._mlc_from_json (json_str , fn_opaque_deserialize ) # type: ignore[attr-defined]
36
-
37
- def eq_s (
38
- self ,
39
- other : Object ,
40
- * ,
41
- bind_free_vars : bool = True ,
42
- assert_mode : bool = False ,
43
- ) -> bool :
44
- return PyAny ._mlc_eq_s (self , other , bind_free_vars , assert_mode ) # type: ignore[attr-defined]
45
-
46
- def eq_s_fail_reason (
47
- self ,
48
- other : Object ,
49
- * ,
50
- bind_free_vars : bool = True ,
51
- ) -> tuple [bool , str ]:
52
- return PyAny ._mlc_eq_s_fail_reason (self , other , bind_free_vars )
53
-
54
- def hash_s (self ) -> int :
55
- return PyAny ._mlc_hash_s (self ) # type: ignore[attr-defined]
56
-
57
- def eq_ptr (self , other : typing .Any ) -> bool :
58
- return isinstance (other , Object ) and self ._mlc_address == other ._mlc_address
59
-
60
25
def __copy__ (self : Object ) -> Object :
61
26
return PyAny ._mlc_copy_shallow (self ) # type: ignore[attr-defined]
62
27
@@ -74,7 +39,7 @@ def __hash__(self) -> int:
74
39
return hash ((type (self ), self ._mlc_address ))
75
40
76
41
def __eq__ (self , other : typing .Any ) -> bool :
77
- return self . eq_ptr (other )
42
+ return eq_ptr (self , other )
78
43
79
44
def __ne__ (self , other : typing .Any ) -> bool :
80
45
return not self == other
@@ -103,3 +68,112 @@ def swap(self, other: typing.Any) -> None:
103
68
self ._mlc_swap (other )
104
69
else :
105
70
raise TypeError (f"Cannot different types: `{ type (self )} ` and `{ type (other )} `" )
71
+
72
+ @warnings .deprecated (
73
+ "Method `.json` is deprecated. Use `mlc.json_dumps` instead." ,
74
+ stacklevel = 2 ,
75
+ )
76
+ def json (
77
+ self ,
78
+ fn_opaque_serialize : Callable [[list [typing .Any ]], str ] | None = None ,
79
+ ) -> str :
80
+ return json_dumps (self , fn_opaque_serialize )
81
+
82
+ @warnings .deprecated (
83
+ "Method `.from_json` is deprecated. Use `mlc.json_loads` instead." ,
84
+ stacklevel = 2 ,
85
+ )
86
+ @staticmethod
87
+ def from_json (
88
+ json_str : str ,
89
+ fn_opaque_deserialize : Callable [[str ], list [typing .Any ]] | None = None ,
90
+ ) -> Object :
91
+ return json_loads (json_str , fn_opaque_deserialize )
92
+
93
+ @warnings .deprecated (
94
+ "Method `.eq_s` is deprecated. Use `mlc.eq_s` instead." ,
95
+ stacklevel = 2 ,
96
+ )
97
+ def eq_s (
98
+ self ,
99
+ other : Object ,
100
+ * ,
101
+ bind_free_vars : bool = True ,
102
+ assert_mode : bool = False ,
103
+ ) -> bool :
104
+ return eq_s (self , other , bind_free_vars = bind_free_vars , assert_mode = assert_mode )
105
+
106
+ @warnings .deprecated (
107
+ "Method `.eq_s_fail_reason` is deprecated. Use `mlc.eq_s_fail_reason` instead." ,
108
+ stacklevel = 2 ,
109
+ )
110
+ def eq_s_fail_reason (
111
+ self ,
112
+ other : Object ,
113
+ * ,
114
+ bind_free_vars : bool = True ,
115
+ ) -> tuple [bool , str ]:
116
+ return eq_s_fail_reason (self , other , bind_free_vars = bind_free_vars )
117
+
118
+ @warnings .deprecated (
119
+ "Method `.hash_s` is deprecated. Use `mlc.hash_s` instead." ,
120
+ stacklevel = 2 ,
121
+ )
122
+ def hash_s (self ) -> int :
123
+ return hash_s (self )
124
+
125
+ @warnings .deprecated (
126
+ "Method `.eq_ptr` is deprecated. Use `mlc.eq_ptr` instead." ,
127
+ stacklevel = 2 ,
128
+ )
129
+ def eq_ptr (self , other : typing .Any ) -> bool :
130
+ return eq_ptr (self , other )
131
+
132
+
133
+ def json_dumps (
134
+ object : typing .Any ,
135
+ fn_opaque_serialize : Callable [[list [typing .Any ]], str ] | None = None ,
136
+ ) -> str :
137
+ assert isinstance (object , Object ), f"Expected `mlc.Object`, got `{ type (object )} `"
138
+ return object ._mlc_json (fn_opaque_serialize ) # type: ignore[attr-defined]
139
+
140
+
141
+ def json_loads (
142
+ json_str : str ,
143
+ fn_opaque_deserialize : Callable [[str ], list [typing .Any ]] | None = None ,
144
+ ) -> Object :
145
+ return PyAny ._mlc_from_json (json_str , fn_opaque_deserialize ) # type: ignore[attr-defined]
146
+
147
+
148
+ def eq_s (
149
+ lhs : typing .Any ,
150
+ rhs : typing .Any ,
151
+ * ,
152
+ bind_free_vars : bool = True ,
153
+ assert_mode : bool = False ,
154
+ ) -> bool :
155
+ assert isinstance (lhs , Object ), f"Expected `mlc.Object`, got `{ type (lhs )} `"
156
+ assert isinstance (rhs , Object ), f"Expected `mlc.Object`, got `{ type (rhs )} `"
157
+ return PyAny ._mlc_eq_s (lhs , rhs , bind_free_vars , assert_mode ) # type: ignore[attr-defined]
158
+
159
+
160
+ def eq_s_fail_reason (
161
+ lhs : typing .Any ,
162
+ rhs : typing .Any ,
163
+ * ,
164
+ bind_free_vars : bool = True ,
165
+ ) -> tuple [bool , str ]:
166
+ assert isinstance (lhs , Object ), f"Expected `mlc.Object`, got `{ type (lhs )} `"
167
+ assert isinstance (rhs , Object ), f"Expected `mlc.Object`, got `{ type (rhs )} `"
168
+ return PyAny ._mlc_eq_s_fail_reason (lhs , rhs , bind_free_vars )
169
+
170
+
171
+ def hash_s (obj : typing .Any ) -> int :
172
+ assert isinstance (obj , Object ), f"Expected `mlc.Object`, got `{ type (obj )} `"
173
+ return PyAny ._mlc_hash_s (obj ) # type: ignore[attr-defined]
174
+
175
+
176
+ def eq_ptr (lhs : typing .Any , rhs : typing .Any ) -> bool :
177
+ assert isinstance (lhs , Object ), f"Expected `mlc.Object`, got `{ type (lhs )} `"
178
+ assert isinstance (rhs , Object ), f"Expected `mlc.Object`, got `{ type (rhs )} `"
179
+ return lhs ._mlc_address == rhs ._mlc_address
0 commit comments