Skip to content

Commit

Permalink
fix **kwargs: Never calls (#446)
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra committed Jan 27, 2022
1 parent b5c7394 commit 2bb79b7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
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

- Treat `NoReturn` like `Any` in `**kwargs` calls (#446)
- Improve error messages for overloaded calls (#445)
- Infer `NoReturn` instead of `Any` for unreachable code (#443)
- Make `NoReturn` compatible with all other types (#442)
Expand Down
5 changes: 5 additions & 0 deletions pyanalyze/signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -1730,6 +1730,11 @@ def preprocess_args(
elif label is KWARGS:
items = {}
extra_values = []
if arg.value is NO_RETURN_VALUE:
new_value = GenericValue(dict, [TypedValue(str), NO_RETURN_VALUE])
processed_args.append((Composite(new_value), KWARGS))
continue

# We union all the kwargs that may be provided by any union member, so that
# we give an error if
for subval in flatten_values(arg.value, unwrap_annotated=True):
Expand Down
14 changes: 14 additions & 0 deletions pyanalyze/test_never.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,17 @@ def capybara(x: Union[int, str]) -> None:
print("str")
else:
assert_never(x)


class TestNeverCall(TestNameCheckVisitorBase):
@assert_passes()
def test_empty_list(self):
def callee(a: int):
pass

def capybara():
for args in []:
callee(*args)

for kwargs in []:
callee(**kwargs)

0 comments on commit 2bb79b7

Please sign in to comment.