ruff/crates
Alex Waygood 1ffc738c84
[flake8-pyi] Add autofix for PYI058 (#9355)
## 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`.
2024-01-03 11:11:16 -05:00
..
ruff_benchmark Make all dependencies workspace dependencies (#9333) 2024-01-02 13:41:59 +00:00
ruff_cache Make all dependencies workspace dependencies (#9333) 2024-01-02 13:41:59 +00:00
ruff_cli Bump version to 0.1.11 (#9370) 2024-01-02 17:46:06 -05:00
ruff_dev Make all dependencies workspace dependencies (#9333) 2024-01-02 13:41:59 +00:00
ruff_diagnostics Enable annotation quoting for multi-line expressions (#9142) 2023-12-15 01:03:09 +00:00
ruff_formatter Make all dependencies workspace dependencies (#9333) 2024-01-02 13:41:59 +00:00
ruff_index Make all dependencies workspace dependencies (#9333) 2024-01-02 13:41:59 +00:00
ruff_linter [flake8-pyi] Add autofix for PYI058 (#9355) 2024-01-03 11:11:16 -05:00
ruff_macros remove several uses of unsafe (#8600) 2023-11-28 09:50:03 -05:00
ruff_notebook Make all dependencies workspace dependencies (#9333) 2024-01-02 13:41:59 +00:00
ruff_python_ast Make all dependencies workspace dependencies (#9333) 2024-01-02 13:41:59 +00:00
ruff_python_codegen Remove source path from parser errors (#9322) 2023-12-30 20:33:05 +00:00
ruff_python_formatter Make all dependencies workspace dependencies (#9333) 2024-01-02 13:41:59 +00:00
ruff_python_index Make all dependencies workspace dependencies (#9333) 2024-01-02 13:41:59 +00:00
ruff_python_literal Make all dependencies workspace dependencies (#9333) 2024-01-02 13:41:59 +00:00
ruff_python_parser Make all dependencies workspace dependencies (#9333) 2024-01-02 13:41:59 +00:00
ruff_python_resolver Make all dependencies workspace dependencies (#9333) 2024-01-02 13:41:59 +00:00
ruff_python_semantic Handle raises with implicit alternate branches (#9377) 2024-01-02 22:59:12 -05:00
ruff_python_stdlib Treat all typing_extensions members as typing aliases (#9335) 2023-12-31 14:23:33 -04:00
ruff_python_trivia Use a sorted vector for block comments (#9337) 2023-12-31 19:52:40 +00:00
ruff_shrinking Bump version to 0.1.11 (#9370) 2024-01-02 17:46:06 -05:00
ruff_source_file Use consistent re-export from ruff_source_file (#9320) 2023-12-30 14:48:45 -05:00
ruff_text_size Make all dependencies workspace dependencies (#9333) 2024-01-02 13:41:59 +00:00
ruff_wasm Make all dependencies workspace dependencies (#9333) 2024-01-02 13:41:59 +00:00
ruff_workspace Add paths to toml parse errors (#9358) 2024-01-02 11:56:51 -05:00