def get_attribute_model_from_line()

in scripts/compare_pysa_models_to_json.py [0:0]


def get_attribute_model_from_line(line: str) -> Optional[Tuple[str, TargetModel]]:
    match = PYSA_ATTRIBUTE_MODEL_PATTERN.match(line)
    if not match:
        return None

    result = make_default_target_model()
    attribute_name = "Obj{{{}}}".format(match.group("attribute_name"))
    attribute_model = match.group("attribute_model")
    if not attribute_name or not attribute_model:
        return None

    annotation_match = RETURN_ANNOTATION_PATTERN.match(attribute_model)
    if not annotation_match or None in annotation_match.groups():
        return None

    model_type = ANNOTATION_TO_MODEL_TYPE[annotation_match.group("model_type").strip()]
    attribute_model_leaves = {
        annotation.strip()
        for annotation in annotation_match.group("model_leaves").split(", ")
    }
    if model_type == "sources":
        # pyre-fixme[26]: TypedDict key must be a string literal.
        result["return_model"][model_type].update(attribute_model_leaves)
    else:
        result["parameters"]["$global"][
            # pyre-fixme[26]: TypedDict key must be a string literal.
            model_type
        ].update(attribute_model_leaves)

    return (attribute_name, result)