An attribute reference, such as ``x.y``. Note that in the case of ``x.y.z``, the outer attribute will have an attr of ``z`` and the value will be another :class:`Attribute` referencing the ``y`` attribute on ``x``:: Attribute( value=Attribute( v
| 1620 | @add_slots |
| 1621 | @dataclass(frozen=True) |
| 1622 | class Attribute(BaseAssignTargetExpression, BaseDelTargetExpression): |
| 1623 | """ |
| 1624 | An attribute reference, such as ``x.y``. |
| 1625 | |
| 1626 | Note that in the case of ``x.y.z``, the outer attribute will have an attr of ``z`` |
| 1627 | and the value will be another :class:`Attribute` referencing the ``y`` attribute on |
| 1628 | ``x``:: |
| 1629 | |
| 1630 | Attribute( |
| 1631 | value=Attribute( |
| 1632 | value=Name("x") |
| 1633 | attr=Name("y") |
| 1634 | ), |
| 1635 | attr=Name("z"), |
| 1636 | ) |
| 1637 | """ |
| 1638 | |
| 1639 | #: An expression which, when evaluated, will produce an object with ``attr`` as an |
| 1640 | #: attribute. |
| 1641 | value: BaseExpression |
| 1642 | |
| 1643 | #: The name of the attribute being accessed on the ``value`` object. |
| 1644 | attr: Name |
| 1645 | |
| 1646 | #: A separating dot. If there's whitespace between the ``value`` and ``attr``, this |
| 1647 | #: dot owns it. |
| 1648 | dot: Dot = Dot() |
| 1649 | |
| 1650 | lpar: Sequence[LeftParen] = () |
| 1651 | #: Sequence of parenthesis for precedence dictation. |
| 1652 | rpar: Sequence[RightParen] = () |
| 1653 | |
| 1654 | def _visit_and_replace_children(self, visitor: CSTVisitorT) -> "Attribute": |
| 1655 | return Attribute( |
| 1656 | lpar=visit_sequence(self, "lpar", self.lpar, visitor), |
| 1657 | value=visit_required(self, "value", self.value, visitor), |
| 1658 | dot=visit_required(self, "dot", self.dot, visitor), |
| 1659 | attr=visit_required(self, "attr", self.attr, visitor), |
| 1660 | rpar=visit_sequence(self, "rpar", self.rpar, visitor), |
| 1661 | ) |
| 1662 | |
| 1663 | def _safe_to_use_with_word_operator(self, position: ExpressionPosition) -> bool: |
| 1664 | if super(Attribute, self)._safe_to_use_with_word_operator(position): |
| 1665 | return True |
| 1666 | return self._check_left_right_word_concatenation_safety( |
| 1667 | position, self.value, self.attr |
| 1668 | ) |
| 1669 | |
| 1670 | def _codegen_impl(self, state: CodegenState) -> None: |
| 1671 | with self._parenthesize(state): |
| 1672 | self.value._codegen(state) |
| 1673 | self.dot._codegen(state) |
| 1674 | self.attr._codegen(state) |
| 1675 | |
| 1676 | |
| 1677 | class BaseSlice(CSTNode, ABC): |
no test coverage detected
searching dependent graphs…