mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 06:44:46 +08:00
@@ -223,9 +223,17 @@ class Importer(object):
|
||||
import_path = []
|
||||
# TODO add import error.
|
||||
debug.warning('Attempted relative import beyond top-level package.')
|
||||
# If no path is defined in the module we have no ideas where we
|
||||
# are in the file system. Therefore we cannot know what to do.
|
||||
# In this case we just let the path there and ignore that it's
|
||||
# a relative path. Not sure if that's a good idea.
|
||||
else:
|
||||
# Here we basically rewrite the level to 0.
|
||||
import_path = tuple(base) + tuple(import_path)
|
||||
base = tuple(base)
|
||||
if level > 1:
|
||||
base = base[:-level + 1]
|
||||
|
||||
import_path = base + tuple(import_path)
|
||||
self.import_path = import_path
|
||||
|
||||
@property
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
a = 1.0
|
||||
|
||||
from ..random import foobar
|
||||
|
||||
@@ -2,3 +2,5 @@
|
||||
Here because random is also a builtin module.
|
||||
"""
|
||||
a = set
|
||||
|
||||
foobar = 0
|
||||
|
||||
@@ -49,7 +49,7 @@ def scope_nested():
|
||||
|
||||
#? float()
|
||||
import_tree.pkg.mod1.a
|
||||
#? ['a', '__name__', '__package__', '__file__', '__doc__']
|
||||
#? ['a', 'foobar', '__name__', '__package__', '__file__', '__doc__']
|
||||
a = import_tree.pkg.mod1.
|
||||
|
||||
import import_tree.random
|
||||
@@ -283,3 +283,13 @@ def underscore():
|
||||
# Does that also work for the our own module?
|
||||
#? ['__file__']
|
||||
__file__
|
||||
|
||||
|
||||
# -----------------
|
||||
# complex relative imports #784
|
||||
# -----------------
|
||||
def relative():
|
||||
#? ['foobar']
|
||||
from import_tree.pkg.mod1 import foobar
|
||||
#? int()
|
||||
foobar
|
||||
|
||||
@@ -65,9 +65,9 @@ import datetime.date
|
||||
|
||||
#? 21 ['import']
|
||||
from import_tree.pkg import pkg
|
||||
#? 49 ['a', '__name__', '__doc__', '__file__', '__package__']
|
||||
#? 49 ['a', 'foobar', '__name__', '__doc__', '__file__', '__package__']
|
||||
from import_tree.pkg.mod1 import not_existant, # whitespace before
|
||||
#? ['a', '__name__', '__doc__', '__file__', '__package__']
|
||||
#? ['a', 'foobar', '__name__', '__doc__', '__file__', '__package__']
|
||||
from import_tree.pkg.mod1 import not_existant,
|
||||
#? 22 ['mod1']
|
||||
from import_tree.pkg. import mod1
|
||||
|
||||
Reference in New Issue
Block a user