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

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

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

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

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

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

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

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