question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Packages and Python built-in imports are not supported when the project has somewhere a folder with the same name

See original GitHub issue

Bugs:

# Original (correct) import
from collections.abc import Iterable

# Changed automatically to a wrong
from ..abc import Iterable
# Original (correct) import
from google.cloud import vision

# Changed automatically to a wrong
from .cloud import vision

Project structure:

project/
    src/
        collections/
            foo/
            bar/
        google/
            spam/
            eggs/

As you see, if a sub-directory matches 3rd-party package or Python module, the ‘absolufy-imports’ makes mistakes.

Possible solutions

  • Check that import is a 3rd-party package. Do not make such imports relative.
  • Another possible solution is to allow to ignore manually specific names. For example, I will ignore names “collections” and “google”.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
AIGeneratedUsernamecommented, Jan 20, 2022

Thank you for the update. Now all works correctly.

0reactions
MarcoGorellicommented, Jan 20, 2022

I’d like to think this is fixed in version 0.3.1 - could you check please?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Importing from builtin library when module with same name ...
No, this probably wouldn't work because python caches the module name in sys. modules , and it will not import a module with...
Read more >
5. The import system — Python 3.11.1 documentation
When a regular package is imported, this __init__.py file is implicitly executed, and the objects it defines are bound to names in the...
Read more >
Absolute vs Relative Imports in Python
This is a cache of all modules that have been previously imported. If the name isn't found in the module cache, Python will...
Read more >
Local imports not resolving correctly · Issue #68 - GitHub
I presume you are using absolute imports. Python 2 allowed absolute imports to be resolved from the same directory as the importing file,...
Read more >
how the Python import system works - Ten thousand meters
Built-in modules are C modules compiled into the python executable. ... Note that the module variable is not available after the import as ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found