e0afe32be948c78c8fc58b43ed013b88343f73ab,pytext/config/serialize.py,,_union_from_json,#Any#Any#,50

Before Change




def _union_from_json(subclasses, json_obj):
    if type(json_obj) is not dict:
        raise IncorrectTypeError(
            f"incorrect Union value {json_obj} for union {subclasses}"
        )
    type_name = list(json_obj)[0]
    for subclass in subclasses:
        if type(None) != subclass and (
            type_name.lower() == _canonical_typename(subclass).lower()
        ):
            return _value_from_json(subclass, json_obj[type_name])
    raise UnionTypeError(
        f"no suitable type found for {type_name} in union {subclasses}"
    )

After Change


            f"can not find class type in json, trying with first class "
            + f"{type_name} in the union"
        )
    try:
        return _value_from_json(subclasses_dict[type_name], json_obj)
    except Exception as e:
        raise UnionTypeError(
            f"failed to parse union {subclasses} from json payload {json_obj}"
        ) from e


def _is_optional(cls):
    return _get_class_type(cls) == Union and type(None) in cls.__args__

Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 5

Instances


Project Name: facebookresearch/pytext
Commit Name: e0afe32be948c78c8fc58b43ed013b88343f73ab
Time: 2019-05-24
Author: zsc@fb.com
File Name: pytext/config/serialize.py
Class Name:
Method Name: _union_from_json


Project Name: comic/grand-challenge.org
Commit Name: c8f80caf3b3a5707a2d5d2b9dfee1e4e80f1b3be
Time: 2017-05-09
Author: jamesmeakin@gmail.com
File Name: django/comicsite/templatetags/comic_templatetags.py
Class Name: comic_URLNode
Method Name: render


Project Name: MolSSI/QCEngine
Commit Name: 08840e2e0f962987c54faf9736f0896682961399
Time: 2020-06-25
Author: joshy1691@gmail.com
File Name: qcengine/programs/openmm.py
Class Name: OpenMMHarness
Method Name: _generate_openmm_system