MCPcopy Index your code
hub / github.com/python/mypy / check_awaitable_expr

Method check_awaitable_expr

mypy/checkexpr.py:6308–6329  ·  view source on GitHub ↗

Check the argument to `await` and extract the type of value. Also used by `async for` and `async with`.

(
        self, t: Type, ctx: Context, msg: str | ErrorMessage, ignore_binder: bool = False
    )

Source from the content-addressed store, hash-verified

6306 return ret
6307
6308 def check_awaitable_expr(
6309 self, t: Type, ctx: Context, msg: str | ErrorMessage, ignore_binder: bool = False
6310 ) -> Type:
6311 """Check the argument to `await` and extract the type of value.
6312
6313 Also used by `async for` and `async with`.
6314 """
6315 if not self.chk.check_subtype(
6316 t, self.named_type("typing.Awaitable"), ctx, msg, "actual type", "expected type"
6317 ):
6318 return AnyType(TypeOfAny.special_form)
6319 else:
6320 generator = self.check_method_call_by_name("__await__", t, [], [], ctx)[0]
6321 ret_type = self.chk.get_generator_return_type(generator, False)
6322 ret_type = get_proper_type(ret_type)
6323 if (
6324 not ignore_binder
6325 and isinstance(ret_type, UninhabitedType)
6326 and not ret_type.ambiguous
6327 ):
6328 self.chk.binder.unreachable()
6329 return ret_type
6330
6331 def visit_yield_from_expr(self, e: YieldFromExpr, allow_none_return: bool = False) -> Type:
6332 # NOTE: Whether `yield from` accepts an `async def` decorated

Callers 5

visit_await_exprMethod · 0.95
visit_yield_from_exprMethod · 0.95
check_async_with_itemMethod · 0.80

Calls 8

named_typeMethod · 0.95
AnyTypeClass · 0.90
get_proper_typeFunction · 0.90
isinstanceFunction · 0.85
unreachableMethod · 0.80
check_subtypeMethod · 0.45

Tested by

no test coverage detected