F401 - update documentation and deprecate ignore_init_module_imports (#11436)

## Summary

* Update documentation for F401 following recent PRs
  * #11168
  * #11314
* Deprecate `ignore_init_module_imports`
* Add a deprecation pragma to the option and a "warn user once" message
when the option is used.
* Restore the old behavior for stable (non-preview) mode:
* When `ignore_init_module_imports` is set to `true` (default) there are
no `__init_.py` fixes (but we get nice fix titles!).
* When `ignore_init_module_imports` is set to `false` there are unsafe
`__init__.py` fixes to remove unused imports.
* When preview mode is enabled, it overrides
`ignore_init_module_imports`.
* Fixed a bug in fix titles where `import foo as bar` would recommend
reexporting `bar as bar`. It now says to reexport `foo as foo`. (In this
case we don't issue a fix, fwiw; it was just a fix title bug.)

## Test plan

Added new fixture tests that reuse the existing fixtures for
`__init__.py` files. Each of the three situations listed above has
fixture tests. The F401 "stable" tests cover:

> * When `ignore_init_module_imports` is set to `true` (default) there
are no `__init_.py` fixes (but we get nice fix titles!).

The F401 "deprecated option" tests cover:

> * When `ignore_init_module_imports` is set to `false` there are unsafe
`__init__.py` fixes to remove unused imports.

These complement existing "preview" tests that show the new behavior
which recommends fixes in `__init__.py` according to whether the import
is 1st party and other circumstances (for more on that behavior see:
#11314).
This commit is contained in:
plredmond 2024-05-21 09:23:45 -07:00 committed by GitHub
parent 403f0dccd8
commit 7225732859
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 491 additions and 30 deletions

View file

@ -660,7 +660,12 @@ impl LintConfiguration {
.collect();
#[allow(deprecated)]
let ignore_init_module_imports = options.common.ignore_init_module_imports;
let ignore_init_module_imports = {
if options.common.ignore_init_module_imports.is_some() {
warn_user_once!("The `ignore-init-module-imports` option is deprecated and will be removed in a future release. Ruff's handling of imports in `__init__.py` files has been improved (in preview) and unused imports will always be flagged.");
}
options.common.ignore_init_module_imports
};
Ok(LintConfiguration {
exclude: options.exclude.map(|paths| {