Skip to content

NonLocalVariableRead

Bases: Read

Class for internal variable reads (GlobalVariable / global Fields).

Attributes:

Name Type Description
symbol GlobalVariable | ClassVariable | InstanceVariable | Import | UnknownSymbol

The symbol that is read.

origin Symbol | NodeID | None

The origin of the read.

Source code in src/library_analyzer/processing/api/purity_analysis/model/_purity.py
@dataclass
class NonLocalVariableRead(Read):
    """Class for internal variable reads (GlobalVariable / global Fields).

    Attributes
    ----------
    symbol :
        The symbol that is read.
    origin :
        The origin of the read.
    """

    symbol: GlobalVariable | ClassVariable | InstanceVariable | Import | UnknownSymbol
    origin: Symbol | NodeID | None = field(default=None)

    def __hash__(self) -> int:
        return hash(str(self))

    def __str__(self) -> str:
        return f"{self.__class__.__name__}: {self.symbol.__class__.__name__}.{self.symbol.name}"

    def to_dict(self) -> dict[str, Any]:
        origin = (
            self.origin.id if isinstance(self.origin, Symbol) else (self.origin if self.origin is not None else None)
        )
        return {
            "origin": f"{origin}",
            "reason": f"{self.symbol.__class__.__name__}.{self.symbol.name}",
        }

origin: Symbol | NodeID | None = field(default=None) class-attribute instance-attribute

symbol: GlobalVariable | ClassVariable | InstanceVariable | Import | UnknownSymbol instance-attribute

__hash__()

Source code in src/library_analyzer/processing/api/purity_analysis/model/_purity.py
def __hash__(self) -> int:
    return hash(str(self))

__init__(symbol, origin=None)

__str__()

Source code in src/library_analyzer/processing/api/purity_analysis/model/_purity.py
def __str__(self) -> str:
    return f"{self.__class__.__name__}: {self.symbol.__class__.__name__}.{self.symbol.name}"

to_dict()

Source code in src/library_analyzer/processing/api/purity_analysis/model/_purity.py
def to_dict(self) -> dict[str, Any]:
    origin = (
        self.origin.id if isinstance(self.origin, Symbol) else (self.origin if self.origin is not None else None)
    )
    return {
        "origin": f"{origin}",
        "reason": f"{self.symbol.__class__.__name__}.{self.symbol.name}",
    }