---
source: crates/ruff_linter/src/rules/flake8_pyi/mod.rs
---
PYI058 [*] Use `Iterator` as the return value for simple `__iter__` methods
 --> PYI058.pyi:5:13
  |
4 |     class IteratorReturningSimpleGenerator1:
5 |         def __iter__(self) -> Generator: ...  # PYI058 (use `Iterator`)
  |             ^^^^^^^^
6 |
7 | def scope():
  |
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: ...  # PYI058 (use `Iterator`)
6 +         def __iter__(self) -> Iterator: ...  # PYI058 (use `Iterator`)
7 |
  |

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

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

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

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

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

PYI058 [*] Use `AsyncIterator` as the return value for simple `__aiter__` methods
  --> PYI058.pyi:43:13
   |
42 |     class AsyncIteratorReturningSimpleAsyncGenerator1:
43 |         def __aiter__(self,) -> typing_extensions.AsyncGenerator: ...  # PYI058 (Use `AsyncIterator`)
   |             ^^^^^^^^^
44 |
45 | def scope():
   |
help: Convert the return annotation of your `__aiter__` method to `AsyncIterator`
   |
42 |     class AsyncIteratorReturningSimpleAsyncGenerator1:
   -         def __aiter__(self,) -> typing_extensions.AsyncGenerator: ...  # PYI058 (Use `AsyncIterator`)
43 +         def __aiter__(self,) -> typing_extensions.AsyncIterator: ...  # PYI058 (Use `AsyncIterator`)
44 |
   |

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

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