Skip to content

Reference

Represents a node that references a Name.

A Reference is a node that references a Name, e.g., a function call, a variable read, etc.

Attributes:

Name Type Description
node Call | Name | MemberAccessValue

The node that defines the symbol.

id NodeID

The id of that node.

name str

The name of the symbol (for easier access).

Source code in src/library_analyzer/processing/api/purity_analysis/model/_module_data.py
@dataclass
class Reference:
    """Represents a node that references a Name.

    A Reference is a node that references a Name,
    e.g., a function call, a variable read, etc.


    Attributes
    ----------
    node :
        The node that defines the symbol.
    id :
        The id of that node.
    name :
        The name of the symbol (for easier access).
    """

    node: astroid.Call | astroid.Name | MemberAccessValue
    id: NodeID
    name: str

    def __str__(self) -> str:
        if self.id is None:
            return f"{self.__class__.__name__}.{self.name}"
        return f"{self.__class__.__name__}.{self.name}.line{self.id.line}"

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

id: NodeID instance-attribute

name: str instance-attribute

node: astroid.Call | astroid.Name | MemberAccessValue instance-attribute

__hash__()

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

__init__(node, id, name)

__str__()

Source code in src/library_analyzer/processing/api/purity_analysis/model/_module_data.py
def __str__(self) -> str:
    if self.id is None:
        return f"{self.__class__.__name__}.{self.name}"
    return f"{self.__class__.__name__}.{self.name}.line{self.id.line}"