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
In my top-level __init__.py file, I define the __all__ variable to mark some imported objects as "public" or "re-exported".
from __future__ importannotationsfrompkg.submoduleimportA, B, C__all__: list[str] = ["A", "B", "C"]
When auto-fixing this code with Ruff 0.0.281, Ruff moves all imports under an if TYPE_CHECKING condition, probably because they appear unused, and because I import annotations from __future__ . If I don't import future annotations, Ruff does not refactor the code (I'm targeting Python 3.8).
Moving these public imports under the TYPE_CHECKING condition actually breaks the API, since the objects are not available from the top-level module anymore at runtime.
I would like Ruff to check if an object is added to the module's __all__ list before moving it under TYPE_CHECKING.
This __all__ variable is a sequence of strings, tuple or list, and can unfortunately be constructed dynamically, so this complicates things: __all__ = ["A", *other_list] + list(some_tuple). If supporting dynamically constructed lists is too hard, for a first version Ruff could only support statically defined lists/tuples.
In the meantime, and as explained above, I can simply stop importing future annotations, and Ruff will not refactor anything.
The text was updated successfully, but these errors were encountered:
In my top-level
__init__.py
file, I define the__all__
variable to mark some imported objects as "public" or "re-exported".When auto-fixing this code with Ruff 0.0.281, Ruff moves all imports under an
if TYPE_CHECKING
condition, probably because they appear unused, and because I importannotations
from__future__
. If I don't import future annotations, Ruff does not refactor the code (I'm targeting Python 3.8).Moving these public imports under the
TYPE_CHECKING
condition actually breaks the API, since the objects are not available from the top-level module anymore at runtime.I would like Ruff to check if an object is added to the module's
__all__
list before moving it underTYPE_CHECKING
.This
__all__
variable is a sequence of strings, tuple or list, and can unfortunately be constructed dynamically, so this complicates things:__all__ = ["A", *other_list] + list(some_tuple)
. If supporting dynamically constructed lists is too hard, for a first version Ruff could only support statically defined lists/tuples.In the meantime, and as explained above, I can simply stop importing future annotations, and Ruff will not refactor anything.
The text was updated successfully, but these errors were encountered: