Skip to content

Commit f492fde

Browse files
committed
Refactor __new__ method in HasDescriptors to accept cls as a keyword argument
1 parent 60819d7 commit f492fde

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

traitlets/traitlets.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,10 +1290,8 @@ def class_init(self, cls: type[HasTraits], name: str | None) -> None:
12901290
class HasDescriptors(metaclass=MetaHasDescriptors):
12911291
"""The base class for all classes that have descriptors."""
12921292

1293-
def __new__(*args: t.Any, **kwargs: t.Any) -> Self: # type:ignore[misc, type-var]
1294-
# Pass cls as args[0] to allow "cls" as keyword argument
1295-
cls = args[0]
1296-
args = args[1:]
1293+
def __new__(cls, /, *args: t.Any, **kwargs: t.Any) -> Self:
1294+
12971295

12981296
# This is needed because object.__new__ only accepts
12991297
# the cls argument.
@@ -1303,7 +1301,7 @@ def __new__(*args: t.Any, **kwargs: t.Any) -> Self: # type:ignore[misc, type-va
13031301
else:
13041302
inst = new_meth(cls, *args, **kwargs)
13051303
inst.setup_instance(*args, **kwargs)
1306-
return inst # type:ignore[no-any-return]
1304+
return inst
13071305

13081306
def setup_instance(*args: t.Any, **kwargs: t.Any) -> None:
13091307
"""

0 commit comments

Comments
 (0)