Importing a single object from a module results in duplicate imports
See original GitHub issueHello, I love the project. It is the only one that works well out of the box and with minimal configuration.
Currently, importing a single object from a module results in a duplicate import in the dependency graph:
- the parent module
- the child module
E.g.:
# in test_services.py
from telereddit.services.services_wrapper import ServicesWrapper
results in the following dependency graph:
I would expect the graph to not present the services
node, because I’m not importing it.
In general, all modules (even if not imported directly) are present and generate duplicate imports arrows. Am I using it wrong, is this intended behavior or is this a bug?
Issue Analytics
- State:
- Created 3 years ago
- Comments:16 (8 by maintainers)
Top Results From Across the Web
What Happens When a Module Is Imported Twice?
A JavaScript module is evaluated just once. When imported multiple times from the same path, the same module instance is returned.
Read more >no-duplicate-imports - ESLint - Pluggable JavaScript Linter
Rule Details. This rule requires that all imports from a single module that can be merged exist in a single import statement.
Read more >Javascript imports, do they duplicate? - Stack Overflow
I'm trying to find a javascript workflow solution to bundle my code in multiple files. I have a question I can't find the...
Read more >Unnecessary Imports: Be careful what you import - Pluralsight
Qt module is actually redundant and only for convenience. As a result, we actually import a lot of bulky and extraneous modules, such...
Read more >Importing Objects from a Python Module Can Be Risky
Whether you should import a module (import module) or import objects from a module (from module import obj1, obj2) is not a new...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@gsakkis thanks for the input.
pydeps
is internally using a (modified) version of the standard-library modulemodulefinder
which looks for import opcodes in they Python byte code - ie. it neither looks at runtime (e.g. by trying to import the module and look atsys.modules
or install an import-hook) nor the source code. This brings with it some disadvantages (we don’t catch especially dynamic imports) and some advantages (we catch both branches of a python-version switch).Skipping
__init__.py
files can have unintended consequences, and I believe the current flow comes from fixing a problem with thecollections
module being excluded (cf. https://github.com/thebjorn/pydeps/commit/1ab3837be41c87f6af055c56188b5a528c5e587a).I’m pro both configurability and sensible defaults, but I’m not convinced that this behavior (at least not in a simplistic version) is a sensible default.
Removing modules that do not import anything - and have submodules (perhaps provided the removal doesn’t disconnect the graph) would potentially be an interesting flag…
@thebjorn an optional flag for the proposed behavior (either on or off by default) would be great!