Skip to content

ReferenceNode

Bases: ABC

Class for reference nodes.

A reference node represents a reference to a list of its referenced symbols.

Attributes:

Name Type Description
node Symbol | Reference

The node that references the symbols.

scope Scope

The scope of the node.

referenced_symbols list[Symbol]

The list of referenced symbols. These are the symbols of the nodes that node references.

Source code in src/library_analyzer/processing/api/purity_analysis/model/_reference.py
@dataclass
class ReferenceNode(ABC):
    """Class for reference nodes.

    A reference node represents a reference to a list of its referenced symbols.


    Attributes
    ----------
    node :
        The node that references the symbols.
    scope :
        The scope of the node.
    referenced_symbols :
        The list of referenced symbols.
        These are the symbols of the nodes that node references.
    """

    node: Symbol | Reference
    scope: Scope
    referenced_symbols: list[Symbol] = field(default_factory=list)

    def __repr__(self) -> str:
        if isinstance(self.node, astroid.Call) and isinstance(self.node.func, astroid.Name):
            return f"{self.node.func.name}.line{self.node.lineno}"
        if isinstance(self.node, MemberAccessTarget | MemberAccessValue):
            return f"{self.node.name}.line{self.node.node.lineno}"
        return f"{self.node.name}.line{self.node.node.lineno}"

node: Symbol | Reference instance-attribute

referenced_symbols: list[Symbol] = field(default_factory=list) class-attribute instance-attribute

scope: Scope instance-attribute

__init__(node, scope, referenced_symbols=list())

__repr__()

Source code in src/library_analyzer/processing/api/purity_analysis/model/_reference.py
def __repr__(self) -> str:
    if isinstance(self.node, astroid.Call) and isinstance(self.node.func, astroid.Name):
        return f"{self.node.func.name}.line{self.node.lineno}"
    if isinstance(self.node, MemberAccessTarget | MemberAccessValue):
        return f"{self.node.name}.line{self.node.node.lineno}"
    return f"{self.node.name}.line{self.node.node.lineno}"