MCPcopy
hub / github.com/python/mypy / visit_yield_expr

Method visit_yield_expr

mypy/checkexpr.py:6273–6292  ·  view source on GitHub ↗
(self, e: YieldExpr)

Source from the content-addressed store, hash-verified

6271 self.chk.handle_cannot_determine_type(name, context)
6272
6273 def visit_yield_expr(self, e: YieldExpr) -> Type:
6274 return_type = self.chk.return_types[-1]
6275 expected_item_type = self.chk.get_generator_yield_type(return_type, False)
6276 if e.expr is None:
6277 if (
6278 not isinstance(get_proper_type(expected_item_type), (NoneType, AnyType))
6279 and self.chk.in_checked_function()
6280 ):
6281 self.chk.fail(message_registry.YIELD_VALUE_EXPECTED, e)
6282 else:
6283 actual_item_type = self.accept(e.expr, expected_item_type)
6284 self.chk.check_subtype(
6285 actual_item_type,
6286 expected_item_type,
6287 e,
6288 message_registry.INCOMPATIBLE_TYPES_IN_YIELD,
6289 "actual type",
6290 "expected type",
6291 )
6292 return self.chk.get_generator_receive_type(return_type, False)
6293
6294 def visit_await_expr(self, e: AwaitExpr, allow_none_return: bool = False) -> Type:
6295 expected_type = self.type_context[-1]

Callers

nothing calls this directly

Calls 8

acceptMethod · 0.95
get_proper_typeFunction · 0.90
isinstanceFunction · 0.85
in_checked_functionMethod · 0.45
failMethod · 0.45
check_subtypeMethod · 0.45

Tested by

no test coverage detected