Skip to content

Commit

Permalink
iterator is too much
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra committed Jul 22, 2024
1 parent 49b41bb commit 2c46f4e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Unreleased

- Flag use of iterators that are immediately discarded (#800)
- Flag use of generators that are immediately discarded (#800)
- Fix crash on some occurrences of `ParamSpec` in stub files (#797)
- Fix crash when Pydantic 1 is installed (#793)
- Fix error on use of TypeVar defaults in stubs (PEP 696). The
Expand Down
4 changes: 2 additions & 2 deletions pyanalyze/name_check_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4658,8 +4658,8 @@ def visit_Expr(self, node: ast.Expr) -> Value:
self._show_error_if_checking(
node, error_code=ErrorCode.missing_await, replacement=replacement
)
elif value.is_type(collections.abc.Iterator) or value.is_type(
collections.abc.AsyncIterator
elif value.is_type(collections.abc.Generator) or value.is_type(
collections.abc.AsyncGenerator
):
self._show_error_if_checking(
node,
Expand Down
11 changes: 8 additions & 3 deletions pyanalyze/test_name_check_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2272,7 +2272,12 @@ def capybara() -> None:
gen() # E: must_use

@assert_passes()
def test_iterator(self):
def test_async_generator(self):
from typing import AsyncGenerator

async def gen() -> AsyncGenerator[int, None]:
yield 1
yield 2

def capybara() -> None:
iter([]) # E: must_use
iter({}) # E: must_use
gen() # E: must_use

0 comments on commit 2c46f4e

Please sign in to comment.