mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 04:45:01 +00:00
![]() ## Summary This PR adds an autofix for the newly added PYI058 rule (added in #9313). ~~The PR's current implementation is that the fix is only available if the fully qualified name of `Generator` or `AsyncGenerator` is being used:~~ - ~~`-> typing.Generator` is converted to `-> typing.Iterator`;~~ - ~~`-> collections.abc.AsyncGenerator[str, Any]` is converted to `-> collections.abc.AsyncIterator[str]`;~~ - ~~but `-> Generator` is _not_ converted to `-> Iterator`. (It would require more work to figure out if `Iterator` was already imported or not. And if it wasn't, where should we import it from? `typing`, `typing_extensions`, or `collections.abc`? It seems much more complicated.)~~ The fix is marked as always safe for `__iter__` or `__aiter__` methods in `.pyi` files, but unsafe for all such methods in `.py` files that have more than one statement in the method body. This felt slightly fiddly to accomplish, but I couldn't _see_ any utilities in https://github.com/astral-sh/ruff/tree/main/crates/ruff_linter/src/fix that would have made it simpler to implement. Lmk if I'm missing something, though -- my first time implementing an autofix! :) ## Test Plan `cargo test` / `cargo insta review`. |
||
---|---|---|
.. | ||
resources/test | ||
src | ||
Cargo.toml |