700abc65fd2172a2c6809dd9b72cf50fc2407772,allennlp/common/from_params.py,,create_kwargs,#Any#Any#Any#,121

Before Change


    // 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

Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 9

Instances


Project Name: allenai/allennlp
Commit Name: 700abc65fd2172a2c6809dd9b72cf50fc2407772
Time: 2020-02-03
Author: mattg@allenai.org
File Name: allennlp/common/from_params.py
Class Name:
Method Name: create_kwargs


Project Name: Microsoft/nni
Commit Name: 2de52a8976971da4836727ba9242fedcc7474878
Time: 2020-01-16
Author: 656569648@qq.com
File Name: src/sdk/pynni/nni/compression/torch/compressor.py
Class Name: Pruner
Method Name: export_model


Project Name: unitedstates/congress-legislators
Commit Name: 4a317ef89f89e335446bfb9c554d381284873c52
Time: 2016-03-16
Author: jconline@gmail.com
File Name: scripts/house_contacts.py
Class Name:
Method Name: run