Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule suggestion: Use most specific public import #8581

Closed
chbndrhnns opened this issue Nov 9, 2023 · 1 comment
Closed

Rule suggestion: Use most specific public import #8581

chbndrhnns opened this issue Nov 9, 2023 · 1 comment

Comments

@chbndrhnns
Copy link

I'd like to see ruff convert imports from private modules to imports from the parent package if the member is declared in __all__.

Maybe an example makes it clearer:

# ./client.py
from .myp._private import Member
from .myp._private import OtherMember

assert Member

# ./myp/__init__.py
__all__ = ["Member"]

from ._private import Member

# ./myp/_private.py
class Member: ...

class OtherMember: ...

I consider modules starting with an underscore private. Based on the rule, ruff would fix this snippet to:

# ./client.py
from .myp import Member
from .myp._private import OtherMember

assert Member

# ./myp/__init__.py
__all__ = ["Member"]

from ._private import Member

# ./myp/_private.py
class Member: ...

class OtherMember: ...
@chbndrhnns chbndrhnns changed the title Rule suggestion: Convert imports from private modules Rule suggestion: Use most specific public import Nov 9, 2023
@charliermarsh
Copy link
Member

Thanks for writing this up! I think it's roughly equivalent to #1107.

@charliermarsh charliermarsh closed this as not planned Won't fix, can't repro, duplicate, stale Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants