@@ -198,3 +198,45 @@ def _initialize():
198
198
util .assert_does_not_throw (_initialize )
199
199
assert const_instance .x == x_value
200
200
assert const_instance .s == str (x_value )
201
+
202
+
203
+ def test_new_with_kwargs ():
204
+ @const_class (with_kwargs = True )
205
+ class ConstClassWithKwargs :
206
+ x : int
207
+ s : str
208
+
209
+ def __eq__ (self , other : object ) -> bool :
210
+ return isinstance (other , self .__class__ ) and other .x == self .x and other .s == self .s
211
+
212
+ const_instance = ConstClassWithKwargs (** ATTR_VALS_1 )
213
+
214
+ # should create an exact copy by default
215
+ const_instance_new_default = const_instance .new ()
216
+ assert const_instance_new_default == const_instance
217
+
218
+ const_instance_new = const_instance .new (x = ATTR_VALS_2 [X_ATTR_NAME ])
219
+ assert isinstance (const_instance_new , ConstClassWithKwargs )
220
+ assert const_instance_new .s == const_instance .s
221
+ assert const_instance_new .x == ATTR_VALS_2 [X_ATTR_NAME ]
222
+
223
+
224
+ def test_new_with_args ():
225
+ @const_class (with_kwargs = False )
226
+ class ConstClassWithKwargs :
227
+ x : int
228
+ s : str
229
+
230
+ def __eq__ (self , other : object ) -> bool :
231
+ return isinstance (other , self .__class__ ) and other .x == self .x and other .s == self .s
232
+
233
+ const_instance = ConstClassWithKwargs (* (ATTR_VALS_1 .values ()))
234
+
235
+ # should create an exact copy by default
236
+ const_instance_new_default = const_instance .new ()
237
+ assert const_instance_new_default == const_instance
238
+
239
+ const_instance_new = const_instance .new (x = ATTR_VALS_2 [X_ATTR_NAME ])
240
+ assert isinstance (const_instance_new , ConstClassWithKwargs )
241
+ assert const_instance_new .s == const_instance .s
242
+ assert const_instance_new .x == ATTR_VALS_2 [X_ATTR_NAME ]
0 commit comments