Whether t came from a function defined using `async def`.
(t: Type)
| 6623 | |
| 6624 | |
| 6625 | def 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 | |
| 6649 | def is_non_empty_tuple(t: Type) -> bool: |
no test coverage detected
searching dependent graphs…