Derived from the flake8-pyi linter.
Fix is sometimes available.
What it does#
Checks for simple
__iter__ methods that return
Generator, and for
__aiter__ methods that return
Why is this bad?#
(Async)Iterator for these methods is simpler and more elegant. More
importantly, it also reflects the fact that the precise kind of iterator
returned from an
__iter__ method is usually an implementation detail that
could change at any time. Type annotations help define a contract for a
function; implementation details should not leak into that contract.
This rule tries hard to avoid false-positive errors, and the rule's fix
should always be safe for
.pyi stub files. However, there is a slightly
higher chance that a false positive might be emitted by this rule when
applied to runtime Python (
.py files). As such, the fix is marked as
unsafe for any
__aiter__ method in a
.py file that has
more than two statements (including docstrings) in its body.