Skip to content

Configurable should warn on unrecognized arguments #926

Description

@krassowski

Currently direct HasTraits subclasses warn when they receive unrecognized arguments:

def test_super_bad_args():
class SuperHasTraits(HasTraits):
a = Integer()
w = ["Passing unrecognized arguments"]
with expected_warnings(w):
obj = SuperHasTraits(a=1, b=2)
assert obj.a == 1
assert not hasattr(obj, "b")

However, this does not work with Configurable and its subclasses, although it is a subclass of HasTraits:

class Configurable(HasTraits):

Image

Context

This is implemented in:

try:
super().__init__(*super_args, **super_kwargs)
except TypeError as e:
arg_s_list = [repr(arg) for arg in super_args]
for k, v in super_kwargs.items():
arg_s_list.append(f"{k}={v!r}")
arg_s = ", ".join(arg_s_list)
warn(
"Passing unrecognized arguments to super({classname}).__init__({arg_s}).\n"
"{error}\n"
"This is deprecated in traitlets 4.2."
"This error will be raised in a future release of traitlets.".format(
arg_s=arg_s,
classname=self.__class__.__name__,
error=e,
),
DeprecationWarning,
stacklevel=2,
)

Related to #145.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions