- ruff v0.0.269
- CPython 3.10.9
Issue
ruff flags a false positive F401 for imports that are used in __all__ that is guarded by a conditional statement.
Running ruff with --fix on will result in broken imports.
MRE
import random
def some_dependency_check():
return random.uniform(0.0, 1.0) > 0.49999
if some_dependency_check():
import math
__all__ = ["math"]
else:
__all__ = []
-> ruff mre.py
mre.py:9:12: F401 [*] `math` imported but unused
Found 1 error.
[*] 1 potentially fixable with the --fix option.