in tools/generate_taint_models/model.py [0:0]
def __str__(self) -> str:
serialized_parameters = []
name_whitelist = self.whitelist.parameter_name
type_whitelist = self.whitelist.parameter_type
for parameter in self.parameters:
should_annotate = True
if name_whitelist is not None and parameter.name in name_whitelist:
should_annotate = False
if type_whitelist is not None and parameter.annotation in type_whitelist:
should_annotate = False
if should_annotate:
parameter_annotation = self.annotations.parameter_annotation
if parameter_annotation is not None:
taint = parameter_annotation.get(parameter)
else:
taint = None
else:
taint = None
# * parameters indicate kwargs after the parameter position, and can't be
# tainted. Example: `def foo(x, *, y): ...`
if parameter.name != "*" and taint:
serialized_parameters.append(f"{parameter.name}: {taint}")
else:
serialized_parameters.append(parameter.name)
returns = self.annotations.returns
if returns:
return_annotation = f" -> {returns}"
else:
return_annotation = ""
return (
f"def {self.callable_name}({', '.join(serialized_parameters)})"
f"{return_annotation}: ..."
)