Skip to content

[FEATURE] Do not remove explicitly re-exported imports even if unused #205

@gandhis1

Description

@gandhis1

Mypy will prevent users from doing implicit re-exports. So if in module a you do from b import obj, and attempt to do from a import obj elsewhere, that will error. See https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-no-implicit-reexport for more context.

There are two ways in which you can explicitly re-export. They are:

  1. When you import and set the __all__ attribute in an __init__.py. pycln as far as I remember has no problem with this.
  2. When you use the explicit re-export syntax that is supported by Mypy, which is from b import obj as obj. This signals to Mypy that you are intentionally, deliberately re-exporting this, and are permitting imports of obj through module a.

It appears that 2 is not respected by pycln. It will remove these re-exports, because they are unused. So the feature request here is that pycln respects this convention and does not remove these. I understand that these are easily silenced through the comment directives, but the ask here is to make that superfluous.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions