Comparison expression (e.g. a < b > c < d).
| 2705 | |
| 2706 | |
| 2707 | class ComparisonExpr(Expression): |
| 2708 | """Comparison expression (e.g. a < b > c < d).""" |
| 2709 | |
| 2710 | __slots__ = ("operators", "operands", "method_types") |
| 2711 | |
| 2712 | __match_args__ = ("operands", "operators") |
| 2713 | |
| 2714 | operators: list[str] |
| 2715 | operands: list[Expression] |
| 2716 | # Inferred type for the operator methods (when relevant; None for 'is'). |
| 2717 | method_types: list[mypy.types.Type | None] |
| 2718 | |
| 2719 | def __init__(self, operators: list[str], operands: list[Expression]) -> None: |
| 2720 | super().__init__() |
| 2721 | self.operators = operators |
| 2722 | self.operands = operands |
| 2723 | self.method_types = [] |
| 2724 | |
| 2725 | def pairwise(self) -> Iterator[tuple[str, Expression, Expression]]: |
| 2726 | """If this comparison expr is "a < b is c == d", yields the sequence |
| 2727 | ("<", a, b), ("is", b, c), ("==", c, d) |
| 2728 | """ |
| 2729 | for i, operator in enumerate(self.operators): |
| 2730 | yield operator, self.operands[i], self.operands[i + 1] |
| 2731 | |
| 2732 | def accept(self, visitor: ExpressionVisitor[T]) -> T: |
| 2733 | return visitor.visit_comparison_expr(self) |
| 2734 | |
| 2735 | |
| 2736 | class SliceExpr(Expression): |
no outgoing calls
no test coverage detected
searching dependent graphs…