in scripts/compare_pysa_models_to_json.py [0:0]
def get_callable_model_from_line(line: str) -> Optional[Tuple[str, TargetModel]]:
match = PYSA_CALLABLE_MODEL_PATTERN.match(line)
if not match:
return None
result = make_default_target_model()
callable_name = match.group("callable_name")
parameters = match.group("parameters")
return_model = match.group("return_model")
if not callable_name and (not parameters and not return_model):
return None
annotated_parameters = PARAMETERS_ANNOTATION_PATTERN.findall(parameters)
for (
parameter_name,
model_annotation,
leaves,
_,
_,
) in annotated_parameters:
if not parameter_name or not model_annotation or not leaves:
continue
model_type = ANNOTATION_TO_MODEL_TYPE[model_annotation]
parameter_model = {annotation.strip() for annotation in leaves.split(",")}
# pyre-fixme[26]: TypedDict key must be a string literal.
result["parameters"][parameter_name][model_type].update(parameter_model)
if return_model:
annotation_match = RETURN_ANNOTATION_PATTERN.match(return_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()
]
return_model = {
annotation.strip()
for annotation in annotation_match.group("model_leaves").split(",")
}
# pyre-fixme[26]: TypedDict key must be a string literal.
result["return_model"][model_type].update(return_model)
return (callable_name, result)