Skip to content

MemberAccess

Bases: NodeNG

Represents a member access.

Superclass for MemberAccessTarget and MemberAccessValue. Represents a member access, e.g. a.b or a.b.c.

Attributes:

Name Type Description
node Attribute | AssignAttr

The original node that represents the member access. Needed as fallback when determining the parent node if the receiver is None.

receiver MemberAccess | NodeNG | None

The receiver is the node that is accessed, it can be nested, e.g. a in a.b or a.b in a.b.c. The receiver can be nested. Is None if the receiver is not of type Name, Call or Attribute

member str

The member is the name of the node that accesses the receiver, e.g. b in a.b.

parent NodeNG | None

The parent node of the member access.

name str

The name of the member access, e.g. a.b. Is set in post_init, after the member access has been created. If the MemberAccess is nested, the name of the receiver will be set to "UNKNOWN" since it is hard to determine correctly for all possible cases, and we do not need it for the analysis.

Source code in src/library_analyzer/processing/api/purity_analysis/model/_module_data.py
@dataclass
class MemberAccess(astroid.NodeNG):
    """Represents a member access.

    Superclass for MemberAccessTarget and MemberAccessValue.
    Represents a member access, e.g. `a.b` or `a.b.c`.

    Attributes
    ----------
    node :
        The original node that represents the member access.
        Needed as fallback when determining the parent node if the receiver is None.
    receiver :
        The receiver is the node that is accessed, it can be nested, e.g. `a` in `a.b` or `a.b` in `a.b.c`.
        The receiver can be nested.
        Is None if the receiver is not of type Name, Call or Attribute
    member :
        The member is the name of the node that accesses the receiver, e.g. `b` in `a.b`.
    parent : astroid.NodeNG | None
        The parent node of the member access.
    name :
        The name of the member access, e.g. `a.b`.
        Is set in __post_init__, after the member access has been created.
        If the MemberAccess is nested, the name of the receiver will be set to "UNKNOWN" since it is hard to determine
        correctly for all possible cases, and we do not need it for the analysis.
    """

    node: astroid.Attribute | astroid.AssignAttr
    receiver: MemberAccess | astroid.NodeNG | None
    member: str
    parent: astroid.NodeNG | None = field(default=None)
    name: str = field(init=False)

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

    def __post_init__(self) -> None:
        if isinstance(self.receiver, astroid.AssignAttr | astroid.Attribute):
            self.name = f"{self.receiver.attrname}.{self.member}"
        elif isinstance(self.receiver, astroid.Name):
            self.name = f"{self.receiver.name}.{self.member}"
        else:
            self.name = f"UNKNOWN.{self.member}"

member: str instance-attribute

name: str = field(init=False) class-attribute instance-attribute

node: astroid.Attribute | astroid.AssignAttr instance-attribute

parent: astroid.NodeNG | None = field(default=None) class-attribute instance-attribute

receiver: MemberAccess | astroid.NodeNG | None instance-attribute

__init__(node, receiver, member, parent=None)

__post_init__()

Source code in src/library_analyzer/processing/api/purity_analysis/model/_module_data.py
def __post_init__(self) -> None:
    if isinstance(self.receiver, astroid.AssignAttr | astroid.Attribute):
        self.name = f"{self.receiver.attrname}.{self.member}"
    elif isinstance(self.receiver, astroid.Name):
        self.name = f"{self.receiver.name}.{self.member}"
    else:
        self.name = f"UNKNOWN.{self.member}"

__str__()

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