Skip to content

Commit

Permalink
feat: support for __next__
Browse files Browse the repository at this point in the history
  • Loading branch information
15r10nk committed Sep 24, 2023
1 parent c668b55 commit 81888a3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion executing/_position_node_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ def node_match(node_type: Union[Type, Tuple[Type, ...]], **kwargs: Any) -> bool:

if node_match(
(ast.ListComp, ast.SetComp, ast.DictComp, ast.GeneratorExp, ast.For)
) and inst_match("GET_ITER"):
) and inst_match(("GET_ITER", "FOR_ITER")):
return

if sys.version_info >= (3, 12):
Expand Down
11 changes: 8 additions & 3 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,12 +581,18 @@ def test_iter(self):
class iter_test:
def __init__(self, typ):
self.typ = typ
self.it = iter([1, 2])

def __iter__(self):
assert isinstance(calling_expression(), self.typ)
return iter([1, 2])
return self

iter(iter_test(ast.Call))
def __next__(self):
assert isinstance(calling_expression(), self.typ)
return next(self.it)

assert list(iter_test(ast.Call)) == [1, 2]
assert next(iter(iter_test(ast.Call))) == 1

if sys.version_info >= (3, 11):

Expand All @@ -598,7 +604,6 @@ def __iter__(self):
for i in iter_test(ast.For):
assert i in (1, 2)


def test_decorator_cache_instruction(self):
frame = inspect.currentframe()

Expand Down

0 comments on commit 81888a3

Please sign in to comment.