MCPcopy Create free account
hub / github.com/python/mypy / visit_unary_expr

Method visit_unary_expr

mypy/checkexpr.py:4476–4487  ·  view source on GitHub ↗

Type check an unary operation ('not', '-', '+' or '~').

(self, e: UnaryExpr)

Source from the content-addressed store, hash-verified

4474 return value
4475
4476 def visit_unary_expr(self, e: UnaryExpr) -> Type:
4477 """Type check an unary operation ('not', '-', '+' or '~')."""
4478 operand_type = self.accept(e.expr)
4479 op = e.op
4480 if op == "not":
4481 result: Type = self.bool_type()
4482 self.chk.check_for_truthy_type(operand_type, e.expr)
4483 else:
4484 method = operators.unary_op_methods[op]
4485 result, method_type = self.check_method_call_by_name(method, operand_type, [], [], e)
4486 e.method_type = method_type
4487 return result
4488
4489 def visit_index_expr(self, e: IndexExpr) -> Type:
4490 """Type check an index expression (base[index]).

Callers

nothing calls this directly

Calls 4

acceptMethod · 0.95
bool_typeMethod · 0.95
check_for_truthy_typeMethod · 0.80

Tested by

no test coverage detected