Bases: PurityResult
Class for pure results.
A function is pure if it has no (External-, Internal-)Read nor (External-, Internal-)Write side effects.
A pure function must also have no unknown reasons.
Attributes:
| Name |
Type |
Description |
is_class |
bool
|
Whether the result is for a class or not.
|
Source code in src/library_analyzer/processing/api/purity_analysis/model/_purity.py
| @dataclass
class Pure(PurityResult):
"""Class for pure results.
A function is pure if it has no (External-, Internal-)Read nor (External-, Internal-)Write side effects.
A pure function must also have no unknown reasons.
Attributes
----------
is_class :
Whether the result is for a class or not.
"""
is_class: bool = False
def update(self, other: PurityResult | None) -> PurityResult:
"""Update the current result with another result.
Parameters
----------
other :
The result to update with.
Returns
-------
PurityResult
The updated result.
Raises
------
TypeError
If the result cannot be updated with the given result.
"""
if other is None:
return self.clone()
elif isinstance(self, Pure):
if isinstance(other, Pure):
return self.clone()
elif isinstance(other, Impure):
return other.clone()
elif isinstance(self, Impure):
if isinstance(other, Pure):
return self.clone()
elif isinstance(other, Impure):
return Impure(reasons=self.reasons | other.reasons).clone()
raise TypeError(f"Cannot update {self} with {other}")
@staticmethod
def clone() -> Pure:
return Pure()
def to_dict(self, shorten: bool = False) -> dict[str, Any]: # noqa: ARG002
return {"purity": self.__class__.__name__}
def __hash__(self) -> int:
return hash(str(self))
def __str__(self) -> str:
return f"{self.__class__.__name__}"
|
is_class: bool = False
class-attribute
instance-attribute
__hash__()
Source code in src/library_analyzer/processing/api/purity_analysis/model/_purity.py
| def __hash__(self) -> int:
return hash(str(self))
|
__str__()
Source code in src/library_analyzer/processing/api/purity_analysis/model/_purity.py
| def __str__(self) -> str:
return f"{self.__class__.__name__}"
|
clone()
staticmethod
Source code in src/library_analyzer/processing/api/purity_analysis/model/_purity.py
| @staticmethod
def clone() -> Pure:
return Pure()
|
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]: # noqa: ARG002
return {"purity": self.__class__.__name__}
|
update(other)
Update the current result with another result.
Parameters:
| Name |
Type |
Description |
Default |
other |
PurityResult | None
|
The result to update with.
|
required
|
Returns:
Raises:
| Type |
Description |
TypeError
|
If the result cannot be updated with the given result.
|
Source code in src/library_analyzer/processing/api/purity_analysis/model/_purity.py
| def update(self, other: PurityResult | None) -> PurityResult:
"""Update the current result with another result.
Parameters
----------
other :
The result to update with.
Returns
-------
PurityResult
The updated result.
Raises
------
TypeError
If the result cannot be updated with the given result.
"""
if other is None:
return self.clone()
elif isinstance(self, Pure):
if isinstance(other, Pure):
return self.clone()
elif isinstance(other, Impure):
return other.clone()
elif isinstance(self, Impure):
if isinstance(other, Pure):
return self.clone()
elif isinstance(other, Impure):
return Impure(reasons=self.reasons | other.reasons).clone()
raise TypeError(f"Cannot update {self} with {other}")
|