Return the literal kind for an expression.
(e: Expression)
| 116 | |
| 117 | |
| 118 | def literal(e: Expression) -> int: |
| 119 | """Return the literal kind for an expression.""" |
| 120 | |
| 121 | if isinstance(e, ComparisonExpr): |
| 122 | return min(literal(o) for o in e.operands) |
| 123 | |
| 124 | elif isinstance(e, OpExpr): |
| 125 | return min(literal(e.left), literal(e.right)) |
| 126 | |
| 127 | elif isinstance(e, (MemberExpr, UnaryExpr, StarExpr)): |
| 128 | return literal(e.expr) |
| 129 | |
| 130 | elif isinstance(e, AssignmentExpr): |
| 131 | return literal(e.target) |
| 132 | |
| 133 | elif isinstance(e, IndexExpr): |
| 134 | if literal(e.index) == LITERAL_YES: |
| 135 | return literal(e.base) |
| 136 | else: |
| 137 | return LITERAL_NO |
| 138 | |
| 139 | elif isinstance(e, NameExpr): |
| 140 | if isinstance(e.node, Var) and e.node.is_final and e.node.final_value is not None: |
| 141 | return LITERAL_YES |
| 142 | return LITERAL_TYPE |
| 143 | |
| 144 | if isinstance(e, (IntExpr, FloatExpr, ComplexExpr, StrExpr, BytesExpr)): |
| 145 | return LITERAL_YES |
| 146 | |
| 147 | if literal_hash(e): |
| 148 | return LITERAL_YES |
| 149 | |
| 150 | return LITERAL_NO |
| 151 | |
| 152 | |
| 153 | def subkeys(key: Key) -> Iterable[Key]: |
no test coverage detected
searching dependent graphs…