Skip to content

Commit

Permalink
handle NoReturn in async def (#427)
Browse files Browse the repository at this point in the history
Fixes #414
  • Loading branch information
JelleZijlstra authored Jan 16, 2022
1 parent e836b43 commit 3a3a7d1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Handle `NoReturn` in `async def` functions (#427)
- Support PEP 673 (`typing_extensions.Self`) (#423)
- Updates for compatibility with recent changes in typeshed (#421):
- Fix override compatibility check for unknown callables
Expand Down
5 changes: 4 additions & 1 deletion pyanalyze/name_check_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2993,7 +2993,10 @@ def visit_Index(self, node: ast.Index) -> Value:

def visit_Await(self, node: ast.Await) -> Value:
composite = self.composite_from_node(node.value)
return self.unpack_awaitable(composite, node.value)
return_value = self.unpack_awaitable(composite, node.value)
if return_value is NO_RETURN_VALUE:
self._set_name_in_scope(LEAVES_SCOPE, node, AnyValue(AnySource.marker))
return return_value

def unpack_awaitable(self, composite: Composite, node: ast.AST) -> Value:
tv_map = AwaitableValue.can_assign(composite.value, self)
Expand Down
26 changes: 26 additions & 0 deletions pyanalyze/test_async_await.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,29 @@ async def f():

async def g():
assert_is_value(f(), GenericValue(Awaitable, [KnownValue(42)]))


class TestNoReturn(TestNameCheckVisitorBase):
@assert_passes()
def test(self):
from typing import NoReturn

async def noret() -> NoReturn:
raise NotImplementedError

async def capybara(cond) -> int:
if cond:
return 3
else:
await noret()

async def pacarana(cond) -> int: # E: missing_return
if cond:
return 3
else:
x = noret()
print(x)

async def hutia(cond) -> int: # E: missing_return
if cond:
return 3

0 comments on commit 3a3a7d1

Please sign in to comment.