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

Relative upper-level imports are improperly linked [python] #36

Open
webknjaz opened this issue Jan 19, 2018 · 7 comments
Open

Relative upper-level imports are improperly linked [python] #36

webknjaz opened this issue Jan 19, 2018 · 7 comments
Labels

Comments

@webknjaz
Copy link

Consider this code:

from ..models.alphaname import Alphaname
from ..forms.alphaname import AlphanameForm

from ..tasks import submitAlphanameInstantly

Module Linker creates references to:

instead of referring upper-level packages/modules.

However it successfully recognises same-package imports, like:

from .models.campaign import Campaign
from .models.task import Task
from .models.alphaname import Alphaname
from .models.message import Message
@fiatjaf
Copy link
Owner

fiatjaf commented Jan 19, 2018

Ok, I guess there's no support for double dots. Are there more than 2 dots in Python relative imports anywhere?

@fiatjaf fiatjaf added the python label Jan 19, 2018
@webknjaz
Copy link
Author

Short answer is yes, it's been copied from the working code.

One can import from higher-level packages provided that the current package is not the root. This can depend on PYTHONPATH and __init__.py.

@webknjaz
Copy link
Author

Oh, I misread your question :)

No, three dots is not supported. It's like in relative paths in fs: two dots is a parent dir, single dot is current dir.

@webknjaz
Copy link
Author

Looking at https://github.com/fiatjaf/module-linker/blob/d8e2601/languages/python.js#L62-L80 I'd say it should support two dots, meaning there's a bug somewhere. I've checked that regexps above work well.

@webknjaz
Copy link
Author

Also, this https://github.com/fiatjaf/module-linker/blob/d8e2601/languages/python.js#L36-L39 condition looks invalid: it's never true, the code checks that the string is both empty and starts with a dot.

@fiatjaf
Copy link
Owner

fiatjaf commented Jan 20, 2018

Thank you very much for the effort, @webknjaz. I'm a little embarrassed by that never-true condition, but anyway, I'll try to fix this as soon as possible.

@klntsky
Copy link

klntsky commented Feb 18, 2019

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

No branches or pull requests

3 participants