Comments (7)
Thank you for the update. Now all works correctly.
from absolufy-imports.
Thanks @AIGeneratedUsername for the report
TBH having a folder which has the same name as a package you're using feels like an anti-pattern
Check that import is a 3rd-party package. Do not make such imports relative.
currently the tool only performs static analysis, so this wouldn't be an option
Another possible solution is to allow to ignore manually specific names. For example, I will ignore names "collections" and "google".
I'd rather not add such complexity
IMO the simplest solution is to change your local file structure
I'd accept a PR to document this gotcha though
from absolufy-imports.
I agree that names shadowing is not nice, but there is a bug in this package.
Consider the following structure:
backend/
src/
__init__.py
spameggs/
__init__.py
foo/
__init__.py
some_file.py
bar/
__init__.py
another_file.py
Imagine that "some_file.py" has content:
from spameggs.abc import something
absolufy-imports thinks that this import is correct and that it is imported a folder above. absolufy-imports is wrong. It is easy to detect that it is wrong. No dynamic imports are required.
absolufy-imports will change it too
from ..abc import something
So, the bug is:
absolufy-imports changes to relative WRONG imports
New (fixed) logic:
- Iterating over directors and files. REMEMBER DIRECTORY DEPTH!
- Can
from spameggs.abc import something
be imported?
YES: refactor the import to be absolute!
NO: it is either a wrong import or external package. IGNORE! DO NOTHING!
I hope my idea explanation is not too cumbersome.
from absolufy-imports.
Thanks for your explanation - do you want to submit a pull request to fix this?
from absolufy-imports.
I need to force relative imports usage in the "src/" directory. I did a research over similar packages and there is no package that do exactly what is required for me. Since my use case is rare, this issue becomes low-priority for you. I did not look at your code, but probably the simplest way to achieve my goal is either to create a pull request or fork the package. I will do this, but I can not give any time estimations (when I will have some time).
from absolufy-imports.
Since my use case is rare, this issue becomes low-priority for you
It's more that I have a full time job and any work I do on this package in purely voluntary
If you submit a pull request I'll review it, else I'll get to this when I get a chance
Thanks anyway for your report!
from absolufy-imports.
I'd like to think this is fixed in version 0.3.1 - could you check please?
from absolufy-imports.
Related Issues (9)
- --keep-relative-imports in __init__.py files only HOT 4
- Provide directory or package as input HOT 2
- Can't parse files with BOM HOT 5
- FR: support usage without pre-commit HOT 1
- Define an authorized level of relativity HOT 1
- Add option to just "absolufy" level-up imports HOT 1
- It doesn't work on the cuda-python repo HOT 3
- BUG from .import mymodule doesn't work
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from absolufy-imports.