ruff icon indicating copy to clipboard operation
ruff copied to clipboard

RUF100 and E401 with auto-fix seem inconsistent

Open JannKleen opened this issue 2 years ago • 4 comments

I have a Django app config that relies on importing some files on initialisation to get various functions in there registered. Having RUF100 enabled and running ruff with --fix, the following happens. The original looks like this:

        import api.checks  # noqa: F401
        import api.signals  # noqa: F401
        import app.celery  # noqa: F401
        import tools.something  # noqa: F401

Running ruff will 'fix' it to the following, which seems incorrect (api.checks isn't used in this file) but will work and stay like that across multiple ruff runs:

        import api.checks
        import api.signals  # noqa: F401
        import app.celery  # noqa: F401
        import tools.something  # noqa: F401

However if I modify it further to:

        import api.checks
        import api.signals
        import app.celery  # noqa: F401
        import tools.something  # noqa: F401

Both lines will get deleted the next time I run ruff and I end up with:

        import app.celery  # noqa: F401
        import tools.something  # noqa: F401

JannKleen avatar May 25 '23 11:05 JannKleen

Pyflakes has the same behavior. I need to look back at our code to understand why. It has to do with submodule imports, which are kind of complicated (e.g., import api.checks in lieu of from api import checks).

charliermarsh avatar May 25 '23 13:05 charliermarsh

I think we can probably flag both of these as unused if api is never used.

charliermarsh avatar May 25 '23 14:05 charliermarsh

import api.checks  # noqa: F401
import api.signals as signals  # noqa: F401

Aliasing works (not sure why though)

dhruvmanila avatar May 26 '23 12:05 dhruvmanila

Related: #60

dhruvmanila avatar Jun 10 '23 16:06 dhruvmanila