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

Function is_async_def

mypy/checkexpr.py:6625–6646  ·  view source on GitHub ↗

Whether t came from a function defined using `async def`.

(t: Type)

Source from the content-addressed store, hash-verified

6623
6624
6625def is_async_def(t: Type) -> bool:
6626 """Whether t came from a function defined using `async def`."""
6627 # In check_func_def(), when we see a function decorated with
6628 # `@typing.coroutine` or `@async.coroutine`, we change the
6629 # return type to typing.AwaitableGenerator[...], so that its
6630 # type is compatible with either Generator or Awaitable.
6631 # But for the check here we need to know whether the original
6632 # function (before decoration) was an `async def`. The
6633 # AwaitableGenerator type conveniently preserves the original
6634 # type as its 4th parameter (3rd when using 0-origin indexing
6635 # :-), so that we can recover that information here.
6636 # (We really need to see whether the original, undecorated
6637 # function was an `async def`, which is orthogonal to its
6638 # decorations.)
6639 t = get_proper_type(t)
6640 if (
6641 isinstance(t, Instance)
6642 and t.type.fullname == "typing.AwaitableGenerator"
6643 and len(t.args) >= 4
6644 ):
6645 t = get_proper_type(t.args[3])
6646 return isinstance(t, Instance) and t.type.fullname == "typing.Coroutine"
6647
6648
6649def is_non_empty_tuple(t: Type) -> bool:

Callers 1

visit_yield_from_exprMethod · 0.85

Calls 3

get_proper_typeFunction · 0.90
isinstanceFunction · 0.85
lenFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…