Skip to content

synt.expr.attribute ¤

Attribute ¤

Bases: Expression

The operation to get a value's attribute.

References

Attribute.

Source code in synt/expr/attribute.py
class Attribute(expr.Expression):
    r"""The operation to get a value's attribute.

    References:
        [Attribute](https://docs.python.org/3/library/ast.html#ast.Attribute).
    """

    target: expr.Expression
    """The target of the operation."""
    attribute_name: str
    """The attribute's name."""

    precedence = expr.ExprPrecedence.Call
    expr_type = expr.ExprType.Attribute

    def __init__(self, target: expr.IntoExpression, attr: str):
        """Initialize an attribute expression.

        Args:
            target: The target of the operation.
            attr: The attribute's name.
        """
        self.target = target.into_expression()
        self.attribute_name = attr

        if self.target.precedence > self.precedence:
            self.target = self.target.wrapped()

    def into_code(self) -> str:
        return f"{self.target.into_code()}.{self.attribute_name}"

precedence class-attribute instance-attribute ¤

precedence = Call

expr_type class-attribute instance-attribute ¤

expr_type = Attribute

target instance-attribute ¤

target: Expression = into_expression()

The target of the operation.

attribute_name instance-attribute ¤

attribute_name: str = attr

The attribute's name.

__init__ ¤

__init__(target: IntoExpression, attr: str)

Initialize an attribute expression.

Parameters:

Name Type Description Default
target IntoExpression

The target of the operation.

required
attr str

The attribute's name.

required
Source code in synt/expr/attribute.py
def __init__(self, target: expr.IntoExpression, attr: str):
    """Initialize an attribute expression.

    Args:
        target: The target of the operation.
        attr: The attribute's name.
    """
    self.target = target.into_expression()
    self.attribute_name = attr

    if self.target.precedence > self.precedence:
        self.target = self.target.wrapped()

into_code ¤

into_code() -> str
Source code in synt/expr/attribute.py
def into_code(self) -> str:
    return f"{self.target.into_code()}.{self.attribute_name}"