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