---
source: crates/ruff_linter/src/rules/flake8_pyi/mod.rs
---
PYI058.py:5:13: PYI058 [*] Use `Iterator` as the return value for simple `__iter__` methods
  |
4 |     class IteratorReturningSimpleGenerator1:
5 |         def __iter__(self) -> Generator:
  |             ^^^^^^^^ PYI058
6 |             ...  # PYI058 (use `Iterator`)
  |
  = help: Convert the return annotation of your `__iter__` method to `Iterator`

ℹ Safe fix
  1 |+from collections.abc import Iterator
1 2 | def scope():
2 3 |     from collections.abc import Generator
3 4 | 
4 5 |     class IteratorReturningSimpleGenerator1:
5   |-        def __iter__(self) -> Generator:
  6 |+        def __iter__(self) -> Iterator:
6 7 |             ...  # PYI058 (use `Iterator`)
7 8 | 
8 9 | 

PYI058.py:13:13: PYI058 [*] Use `Iterator` as the return value for simple `__iter__` methods
   |
12 |     class IteratorReturningSimpleGenerator2:
13 |         def __iter__(self) -> typing.Generator:
   |             ^^^^^^^^ PYI058
14 |             ...  # PYI058 (use `Iterator`)
   |
   = help: Convert the return annotation of your `__iter__` method to `Iterator`

ℹ Safe fix
10 10 |     import typing
11 11 | 
12 12 |     class IteratorReturningSimpleGenerator2:
13    |-        def __iter__(self) -> typing.Generator:
   13 |+        def __iter__(self) -> typing.Iterator:
14 14 |             ...  # PYI058 (use `Iterator`)
15 15 | 
16 16 | 

PYI058.py:21:13: PYI058 [*] Use `Iterator` as the return value for simple `__iter__` methods
   |
20 |     class IteratorReturningSimpleGenerator3:
21 |         def __iter__(self) -> collections.abc.Generator:
   |             ^^^^^^^^ PYI058
22 |             ...  # PYI058 (use `Iterator`)
   |
   = help: Convert the return annotation of your `__iter__` method to `Iterator`

ℹ Safe fix
18 18 |     import collections.abc
19 19 | 
20 20 |     class IteratorReturningSimpleGenerator3:
21    |-        def __iter__(self) -> collections.abc.Generator:
   21 |+        def __iter__(self) -> collections.abc.Iterator:
22 22 |             ...  # PYI058 (use `Iterator`)
23 23 | 
24 24 | 

PYI058.py:30:13: PYI058 [*] Use `Iterator` as the return value for simple `__iter__` methods
   |
29 |     class IteratorReturningSimpleGenerator4:
30 |         def __iter__(self, /) -> collections.abc.Generator[str, Any, None]:
   |             ^^^^^^^^ PYI058
31 |             ...  # PYI058 (use `Iterator`)
   |
   = help: Convert the return annotation of your `__iter__` method to `Iterator`

ℹ Safe fix
27 27 |     from typing import Any
28 28 | 
29 29 |     class IteratorReturningSimpleGenerator4:
30    |-        def __iter__(self, /) -> collections.abc.Generator[str, Any, None]:
   30 |+        def __iter__(self, /) -> collections.abc.Iterator[str]:
31 31 |             ...  # PYI058 (use `Iterator`)
32 32 | 
33 33 | 

PYI058.py:39:13: PYI058 [*] Use `Iterator` as the return value for simple `__iter__` methods
   |
38 |     class IteratorReturningSimpleGenerator5:
39 |         def __iter__(self, /) -> collections.abc.Generator[str, None, typing.Any]:
   |             ^^^^^^^^ PYI058
40 |             ...  # PYI058 (use `Iterator`)
   |
   = help: Convert the return annotation of your `__iter__` method to `Iterator`

ℹ Safe fix
36 36 |     import typing
37 37 | 
38 38 |     class IteratorReturningSimpleGenerator5:
39    |-        def __iter__(self, /) -> collections.abc.Generator[str, None, typing.Any]:
   39 |+        def __iter__(self, /) -> collections.abc.Iterator[str]:
40 40 |             ...  # PYI058 (use `Iterator`)
41 41 | 
42 42 | 

PYI058.py:47:13: PYI058 [*] Use `Iterator` as the return value for simple `__iter__` methods
   |
46 |     class IteratorReturningSimpleGenerator6:
47 |         def __iter__(self, /) -> Generator[str, None, None]:
   |             ^^^^^^^^ PYI058
48 |             ...  # PYI058 (use `Iterator`)
   |
   = help: Convert the return annotation of your `__iter__` method to `Iterator`

ℹ Safe fix
   1  |+from collections.abc import Iterator
1  2  | def scope():
2  3  |     from collections.abc import Generator
3  4  | 
--------------------------------------------------------------------------------
44 45 |     from collections.abc import Generator
45 46 | 
46 47 |     class IteratorReturningSimpleGenerator6:
47    |-        def __iter__(self, /) -> Generator[str, None, None]:
   48 |+        def __iter__(self, /) -> Iterator[str]:
48 49 |             ...  # PYI058 (use `Iterator`)
49 50 | 
50 51 | 

PYI058.py:55:13: PYI058 [*] Use `AsyncIterator` as the return value for simple `__aiter__` methods
   |
54 |     class AsyncIteratorReturningSimpleAsyncGenerator1:
55 |         def __aiter__(
   |             ^^^^^^^^^ PYI058
56 |             self,
57 |         ) -> typing_extensions.AsyncGenerator:
   |
   = help: Convert the return annotation of your `__aiter__` method to `AsyncIterator`

ℹ Safe fix
54 54 |     class AsyncIteratorReturningSimpleAsyncGenerator1:
55 55 |         def __aiter__(
56 56 |             self,
57    |-        ) -> typing_extensions.AsyncGenerator:
   57 |+        ) -> typing_extensions.AsyncIterator:
58 58 |             ...  # PYI058 (Use `AsyncIterator`)
59 59 | 
60 60 | 

PYI058.py:73:13: PYI058 [*] Use `AsyncIterator` as the return value for simple `__aiter__` methods
   |
72 |     class AsyncIteratorReturningSimpleAsyncGenerator3:
73 |         def __aiter__(self, /) -> collections.abc.AsyncGenerator[str, None]:
   |             ^^^^^^^^^ PYI058
74 |             ...  # PYI058 (Use `AsyncIterator`)
   |
   = help: Convert the return annotation of your `__aiter__` method to `AsyncIterator`

ℹ Safe fix
70 70 |     import collections.abc
71 71 | 
72 72 |     class AsyncIteratorReturningSimpleAsyncGenerator3:
73    |-        def __aiter__(self, /) -> collections.abc.AsyncGenerator[str, None]:
   73 |+        def __aiter__(self, /) -> collections.abc.AsyncIterator[str]:
74 74 |             ...  # PYI058 (Use `AsyncIterator`)
75 75 | 
76 76 | 


