Skip to content

[F401] missing errors #17295

@tony-sanchez

Description

@tony-sanchez

Summary

Hi,

I'm occasionally struggling with the F401 rule, I managed to reproduce the issue with the following example.

Given this file, named ruff_F401.py:

def my_method():
    import package.a.b.c.d.module_a
    import package.a.b.c.d.module_b
    import package.a.b.e.module_c

When I run ruff --isolated check ruff_F401.py I get the following report:

ruff_F401.py:4:12: F401 [*] `package.a.b.e.module_c` imported but unused
  |
2 |     import package.a.b.c.d.module_a
3 |     import package.a.b.c.d.module_b
4 |     import package.a.b.e.module_c
  |            ^^^^^^^^^^^^^^^^^^^^^^ F401
  |
  = help: Remove unused import: `package.a.b.e.module_c`

Found 1 error.
[*] 1 fixable with the `--fix` option.

If I provide the --fix argument, then the 3 imports are replaced with a pass.

Expected behaviour:

I'd expect a F401 error to be reported for each of the 3 lines.

Version

ruff 0.11.4 (95d6ed4 2025-04-04)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions