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

Forbid to import symbols from a wrong place #1195

Closed
orsinium opened this issue Feb 27, 2020 · 1 comment
Closed

Forbid to import symbols from a wrong place #1195

orsinium opened this issue Feb 27, 2020 · 1 comment
Labels
rule request Adding a new rule

Comments

@orsinium
Copy link
Collaborator

Rule request

Thesis

In python, you can import from a module any symbol that defined for it.

from typing import collections

Let's forbid indirect imports, except facades.

Implementation

We should allow import symbols:

  1. From where they are defined.
  2. From __init__.py (facade).

Cases, when the facade isn't __init__.py, are rare (do you have examples?).

Reasoning

  1. Too many ways to import one thing
  2. Difficult to refactor. You remove import something from a module that imported it for internal usage, and suddenly something else is broken.

Moved from #1092 (comment)

@orsinium orsinium added the rule request Adding a new rule label Feb 27, 2020
@sobolevn
Copy link
Member

This is covered by mypy: see implicit_reexport from https://mypy.readthedocs.io/en/stable/config_file.html

We cannot handle this violation, because we cannot know what's behind import something
Since we do not resolve packages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule request Adding a new rule
Projects
None yet
Development

No branches or pull requests

2 participants