Skip to content

F401 fix causes infinite loop adding duplicates to __all__ #22221

@harupy

Description

@harupy

Summary

How to reproduce:

$ mkdir foo
$ echo '
import foo.bar.module
import foo.baz.module

__all__ = []
' > foo/__init__.py

$ cargo run --bin ruff -- check test_f401_dup/foo/__init__.py --select F401 --preview --fix foo/__init__.py

foo/__init__.py looks like this after the fix is applied:

import foo.bar.module
import foo.baz.module

__all__ = [
    "foo",
    ...,
    "foo",
    "foo",
    "foo",
    "foo",
]

It appears that foo.baz.module is never marked as used, and ruff keeps adding foo in __all__.

Version

da188d5

Context

Ran into this bug when I upgraded ruff to 0.14.10 in mlflow/mlflow

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixesRelated to suggested fixes for violations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions