// constructor.
has_kwargs = False
for param in parameters.values():
if param.kind == param.VAR_KEYWORD:
has_kwargs = True
if has_kwargs:
// "mro" is "method resolution order". The first one is the current class, the next is the
// first superclass, and so on. Taking the first superclass should work in all cases that
// we"re looking for here.
superclass = cls.mro()[1]
superclass_signature = inspect.signature(superclass.__init__) // type: ignore
for param_name, param in superclass_signature.parameters.items():
if param_name == "self":
continue
parameters[param_name] = param
// Iterate over all the constructor parameters and their annotations.
for param_name, param in parameters.items():
// Skip "self". You"re not *required* to call the first parameter "self",
// so in theory this logic is fragile, but if you don"t call the self parameter
// "self" you kind of deserve what happens.
After Change
// with multiple values for a single parameter (e.g., the default value gives you lazy=False
// for a dataset reader inside **kwargs, but a particular dataset reader actually hard-codes
// lazy=True - the superclass sees both lazy=True and lazy=False in its constructor).
if constructed_arg is not param.default:
kwargs[param_name] = constructed_arg
params.assert_empty(cls.__name__)
return kwargs