Class for API purity.
The API purity is used to represent the purity result of an API.
Attributes:
| Name |
Type |
Description |
purity_results |
dict[NodeID, dict[NodeID, PurityResult]]
|
The purity results of all functions of the API.
The key is the NodeID of the module,
the value is a dictionary of the purity results of the functions in the module.
|
Source code in src/library_analyzer/processing/api/purity_analysis/model/_purity.py
| class APIPurity:
"""Class for API purity.
The API purity is used to represent the purity result of an API.
Attributes
----------
purity_results : dict[NodeID, dict[NodeID, PurityResult]]
The purity results of all functions of the API.
The key is the NodeID of the module,
the value is a dictionary of the purity results of the functions in the module.
"""
purity_results: typing.ClassVar[dict[NodeID, dict[NodeID, PurityResult]]] = {}
def to_json_file(self, path: Path, shorten: bool = True) -> None:
ensure_file_exists(path)
with path.open("w") as f:
json.dump(self.to_dict(shorten), f, indent=2)
def to_dict(self, shorten: bool = False) -> dict[str, Any]:
return {
module_name.__str__(): {
function_id.__str__(): purity.to_dict(shorten)
for function_id, purity in purity_result.items()
if not purity.is_class
}
for module_name, purity_result in self.purity_results.items()
}
|
purity_results: dict[NodeID, dict[NodeID, PurityResult]] = {}
class-attribute
to_dict(shorten=False)
Source code in src/library_analyzer/processing/api/purity_analysis/model/_purity.py
| def to_dict(self, shorten: bool = False) -> dict[str, Any]:
return {
module_name.__str__(): {
function_id.__str__(): purity.to_dict(shorten)
for function_id, purity in purity_result.items()
if not purity.is_class
}
for module_name, purity_result in self.purity_results.items()
}
|
to_json_file(path, shorten=True)
Source code in src/library_analyzer/processing/api/purity_analysis/model/_purity.py
| def to_json_file(self, path: Path, shorten: bool = True) -> None:
ensure_file_exists(path)
with path.open("w") as f:
json.dump(self.to_dict(shorten), f, indent=2)
|