@@ -1290,11 +1290,7 @@ def class_init(self, cls: type[HasTraits], name: str | None) -> None:
1290
1290
class HasDescriptors (metaclass = MetaHasDescriptors ):
1291
1291
"""The base class for all classes that have descriptors."""
1292
1292
1293
- def __new__ (* args : t .Any , ** kwargs : t .Any ) -> t .Any :
1294
- # Pass cls as args[0] to allow "cls" as keyword argument
1295
- cls = args [0 ]
1296
- args = args [1 :]
1297
-
1293
+ def __new__ (cls , / , * args : t .Any , ** kwargs : t .Any ) -> Self :
1298
1294
# This is needed because object.__new__ only accepts
1299
1295
# the cls argument.
1300
1296
new_meth = super (HasDescriptors , cls ).__new__
@@ -1305,13 +1301,10 @@ def __new__(*args: t.Any, **kwargs: t.Any) -> t.Any:
1305
1301
inst .setup_instance (* args , ** kwargs )
1306
1302
return inst
1307
1303
1308
- def setup_instance (* args : t .Any , ** kwargs : t .Any ) -> None :
1304
+ def setup_instance (self , / , * args : t .Any , ** kwargs : t .Any ) -> None :
1309
1305
"""
1310
1306
This is called **before** self.__init__ is called.
1311
1307
"""
1312
- # Pass self as args[0] to allow "self" as keyword argument
1313
- self = args [0 ]
1314
- args = args [1 :]
1315
1308
1316
1309
self ._cross_validation_lock = False
1317
1310
cls = self .__class__
@@ -1333,11 +1326,7 @@ class HasTraits(HasDescriptors, metaclass=MetaHasTraits):
1333
1326
_traits : dict [str , t .Any ]
1334
1327
_all_trait_default_generators : dict [str , t .Any ]
1335
1328
1336
- def setup_instance (* args : t .Any , ** kwargs : t .Any ) -> None :
1337
- # Pass self as args[0] to allow "self" as keyword argument
1338
- self = args [0 ]
1339
- args = args [1 :]
1340
-
1329
+ def setup_instance (self , / , * args : t .Any , ** kwargs : t .Any ) -> None :
1341
1330
# although we'd prefer to set only the initial values not present
1342
1331
# in kwargs, we will overwrite them in `__init__`, and simply making
1343
1332
# a copy of a dict is faster than checking for each key.
0 commit comments