Skip to content
This repository has been archived by the owner on Nov 23, 2024. It is now read-only.

Commit

Permalink
fix: removed unused functions to satisfy codecov
Browse files Browse the repository at this point in the history
  • Loading branch information
lukarade committed Mar 30, 2023
1 parent 92bc461 commit 38a06c8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 43 deletions.
14 changes: 7 additions & 7 deletions src/library_analyzer/processing/api/_infer_purity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()))])
Expand Down Expand Up @@ -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
Expand Down
73 changes: 37 additions & 36 deletions src/library_analyzer/processing/api/model/_purity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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):
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

0 comments on commit 38a06c8

Please sign in to comment.