diff --git a/src/library_analyzer/processing/api/_infer_purity.py b/src/library_analyzer/processing/api/_infer_purity.py index 6fa600f2..eee7c65b 100644 --- a/src/library_analyzer/processing/api/_infer_purity.py +++ b/src/library_analyzer/processing/api/_infer_purity.py @@ -130,11 +130,12 @@ def enter_call(self, node: astroid.Call) -> None: pass elif isinstance(node.func, astroid.Name): if node.func.name in BUILTIN_FUNCTIONS: - if isinstance(node.args[0], astroid.Name): - impurity_indicator = check_builtin_function(node, node.func.name, node.args[0].name, True) + value = node.args[0] + if isinstance(value, astroid.Name): + impurity_indicator = check_builtin_function(node, node.func.name, value.name, True) self.append_reason(impurity_indicator) else: - impurity_indicator = check_builtin_function(node, node.func.name, node.args[0].value) + impurity_indicator = check_builtin_function(node, node.func.name, value.value) self.append_reason(impurity_indicator) self.append_reason([Call(Reference(node.as_string()))]) @@ -220,10 +221,9 @@ def determine_open_mode(args: list[str]) -> OpenMode: if len(args) == 1: return OpenMode.READ - if isinstance(args[1], astroid.Const): - mode = args[1].value - else: - mode = args[1] + mode = args[1] + if isinstance(mode, astroid.Const): + mode = mode.value if mode in read_mode: return OpenMode.READ diff --git a/src/library_analyzer/processing/api/model/_purity.py b/src/library_analyzer/processing/api/model/_purity.py index e0ba7023..d01d26fc 100644 --- a/src/library_analyzer/processing/api/model/_purity.py +++ b/src/library_analyzer/processing/api/model/_purity.py @@ -9,9 +9,10 @@ # Type of access class Expression(astroid.NodeNG, ABC): - @abstractmethod - def __hash__(self) -> int: - pass + # @abstractmethod + # def __hash__(self) -> int: + # pass + ... @dataclass @@ -20,8 +21,8 @@ class AttributeAccess(Expression): name: str - def __hash__(self) -> int: - return hash(self.name) + # def __hash__(self) -> int: + # return hash(self.name) @dataclass @@ -31,8 +32,8 @@ class GlobalAccess(Expression): name: str module: str = "None" - def __hash__(self) -> int: - return hash(self.name) + # def __hash__(self) -> int: + # return hash(self.name) @dataclass @@ -42,8 +43,8 @@ class ParameterAccess(Expression): name: str function: str - def __hash__(self) -> int: - return hash(self.name) + # def __hash__(self) -> int: + # return hash(self.name) @dataclass @@ -53,24 +54,24 @@ class InstanceAccess(Expression): receiver: Expression target: Expression - def __hash__(self) -> int: - return hash((self.receiver, self.target)) + # def __hash__(self) -> int: + # return hash((self.receiver, self.target)) @dataclass class StringLiteral(Expression): value: str - def __hash__(self) -> int: - return hash(self.value) + # def __hash__(self) -> int: + # return hash(self.value) @dataclass class Reference(Expression): name: str - def __hash__(self) -> int: - return hash(self.name) + # def __hash__(self) -> int: + # return hash(self.name) class ImpurityCertainty(Enum): @@ -83,9 +84,9 @@ class ImpurityCertainty(Enum): class ImpurityIndicator(ABC): certainty: ImpurityCertainty - @abstractmethod - def __hash__(self) -> int: - pass + # @abstractmethod + # def __hash__(self) -> int: + # pass @abstractmethod def is_side_effect(self) -> bool: @@ -94,8 +95,8 @@ def is_side_effect(self) -> bool: @dataclass class ConcreteImpurityIndicator(ImpurityIndicator): - def __hash__(self) -> int: - return hash(self.certainty) + # def __hash__(self) -> int: + # return hash(self.certainty) def is_side_effect(self) -> bool: return False @@ -106,8 +107,8 @@ class VariableRead(ImpurityIndicator): expression: Expression certainty = ImpurityCertainty.MAYBE_IMPURE - def __hash__(self) -> int: - return hash(self.expression) + # def __hash__(self) -> int: + # return hash(self.expression) def is_side_effect(self) -> bool: return False @@ -118,8 +119,8 @@ class VariableWrite(ImpurityIndicator): expression: Expression certainty = ImpurityCertainty.MAYBE_IMPURE - def __hash__(self) -> int: - return hash(self.expression) + # def __hash__(self) -> int: + # return hash(self.expression) def is_side_effect(self) -> bool: return True @@ -130,8 +131,8 @@ class FileRead(ImpurityIndicator): source: Expression certainty = ImpurityCertainty.DEFINITELY_IMPURE - def __hash__(self) -> int: - return hash(self.source) + # def __hash__(self) -> int: + # return hash(self.source) def is_side_effect(self) -> bool: return False @@ -142,8 +143,8 @@ class FileWrite(ImpurityIndicator): source: Expression certainty = ImpurityCertainty.DEFINITELY_IMPURE - def __hash__(self) -> int: - return hash(self.source) + # def __hash__(self) -> int: + # return hash(self.source) def is_side_effect(self) -> bool: return True @@ -154,8 +155,8 @@ class UnknownCallTarget(ImpurityIndicator): expression: Expression certainty = ImpurityCertainty.DEFINITELY_IMPURE - def __hash__(self) -> int: - return hash(self.expression) + # def __hash__(self) -> int: + # return hash(self.expression) def is_side_effect(self) -> bool: return True # TODO: improve this to make analysis more precise @@ -166,8 +167,8 @@ class Call(ImpurityIndicator): expression: Expression certainty = ImpurityCertainty.DEFINITELY_IMPURE - def __hash__(self) -> int: - return hash(self.expression) + # def __hash__(self) -> int: + # return hash(self.expression) def is_side_effect(self) -> bool: return True # TODO: improve this to make analysis more precise @@ -177,8 +178,8 @@ def is_side_effect(self) -> bool: class SystemInteraction(ImpurityIndicator): certainty = ImpurityCertainty.DEFINITELY_IMPURE - def __hash__(self) -> int: - return hash("SystemInteraction") + # def __hash__(self) -> int: + # return hash("SystemInteraction") def is_side_effect(self) -> bool: return True @@ -192,8 +193,8 @@ class BuiltInFunction(ImpurityIndicator): indicator: ImpurityIndicator # this should be a list to handle multiple reasons certainty: ImpurityCertainty - def __hash__(self) -> int: - return hash(self.indicator) + # def __hash__(self) -> int: + # return hash(self.indicator) def is_side_effect(self) -> bool: return False