You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
F401 creates infinite loop in preview mode when autofixing an unused first-party submodule import in an __init__.py file that has an __all__ definition
#12513
Closed
rshanker779 opened this issue
Jul 25, 2024
· 2 comments
· Fixed by #12569
When having an __init__ file with an __all__ and an import that does not appear in __all__, an inifinte loop occurs as ruff tries to add the import to __all__. Full recreation details are below
List of keywords you searched for before creating this issue. Write them down here so that others can find this issue more easily and help provide feedback.
__all__ init bug
A minimal code snippet that reproduces the bug.
I think the issue is that the F401 fix is trying to add "custom_module.a" to __all__ for the autofix -- but it shouldn't be, because "custom_module.a" isn't a valid identifier. That means that when it comes around on the next loop, it finds that there the custom_module.a binding created by the import still isn't used at all (normally including it in __all__ would mean that it's now counted as used, but here it doesn't because the inclusion in __all__ is invalid). So it again tries to add "custom_module.a" to __all__ to fix it not being used. And so on and so on, ad infinitum.
AlexWaygood
changed the title
[Infinite loop] F401 and RUF022 causing a loop in __all__
F401 fix causes an infinite loop when an unused first-party import in an __init__.py file isn't a valid identifier
Jul 29, 2024
AlexWaygood
changed the title
F401 fix causes an infinite loop when an unused first-party import in an __init__.py file isn't a valid identifier
F401 creates infinite loop when autofixing an unused first-party submodule import in an __init__.py file that has an __all__ definition
Jul 29, 2024
AlexWaygood
changed the title
F401 creates infinite loop when autofixing an unused first-party submodule import in an __init__.py file that has an __all__ definition
F401 creates infinite loop in preview mode when autofixing an unused first-party submodule import in an __init__.py file that has an __all__ definition
Jul 29, 2024
When having an
__init__
file with an__all__
and an import that does not appear in__all__
, an inifinte loop occurs as ruff tries to add the import to__all__
. Full recreation details are belowList of keywords you searched for before creating this issue. Write them down here so that others can find this issue more easily and help provide feedback.
__all__
init bugA minimal code snippet that reproduces the bug.
This is with module structure
Running
Causes ruff to repeatedly add
custom_module.a
to the__all__
until it errorsThe final output is
Ruff settings
Ruff version
The text was updated successfully, but these errors were encountered: