mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-10 15:51:51 +08:00
temporary import work
This commit is contained in:
19
imports.py
19
imports.py
@@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import pkgutil
|
import pkgutil
|
||||||
import imp
|
import imp
|
||||||
|
import sys
|
||||||
|
|
||||||
import builtin
|
import builtin
|
||||||
import modules
|
import modules
|
||||||
@@ -48,6 +49,10 @@ class ImportPath(object):
|
|||||||
and len(self.import_stmt.namespace.names) > 1
|
and len(self.import_stmt.namespace.names) > 1
|
||||||
|
|
||||||
def get_nested_import(self, parent):
|
def get_nested_import(self, parent):
|
||||||
|
"""
|
||||||
|
See documentation of `self.is_nested_import`.
|
||||||
|
Generates an Import statement, that can be used to fake nested imports.
|
||||||
|
"""
|
||||||
i = self.import_stmt
|
i = self.import_stmt
|
||||||
# This is not an existing Import statement. Therefore, set position to
|
# This is not an existing Import statement. Therefore, set position to
|
||||||
# None.
|
# None.
|
||||||
@@ -79,6 +84,7 @@ class ImportPath(object):
|
|||||||
|
|
||||||
def follow(self):
|
def follow(self):
|
||||||
"""
|
"""
|
||||||
|
Returns the imported modules.
|
||||||
"""
|
"""
|
||||||
if self.import_path:
|
if self.import_path:
|
||||||
scope, rest = self.follow_file_system()
|
scope, rest = self.follow_file_system()
|
||||||
@@ -109,15 +115,21 @@ class ImportPath(object):
|
|||||||
def follow_str(ns, string):
|
def follow_str(ns, string):
|
||||||
debug.dbg('follow_module', ns, string)
|
debug.dbg('follow_module', ns, string)
|
||||||
if ns:
|
if ns:
|
||||||
path = [ns[1]]
|
try:
|
||||||
|
return imp.find_module(string, [ns[1]])
|
||||||
|
except ImportError:
|
||||||
|
return imp.find_module(string, builtin.module_find_path)
|
||||||
else:
|
else:
|
||||||
path = None
|
path = None
|
||||||
debug.dbg('search_module', string, path, self.file_path)
|
debug.dbg('search_module', string, path, self.file_path)
|
||||||
|
#sys.path, temp = builtin.module_find_path, sys.path
|
||||||
try:
|
try:
|
||||||
i = imp.find_module(string, path)
|
i = imp.find_module(string, builtin.module_find_path)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# find builtins (ommit path):
|
# find builtins (ommit path):
|
||||||
i = imp.find_module(string, builtin.module_find_path)
|
#i = imp.find_module(string)
|
||||||
|
raise
|
||||||
|
#sys.path = temp
|
||||||
return i
|
return i
|
||||||
|
|
||||||
# TODO handle relative paths - they are included in the import object
|
# TODO handle relative paths - they are included in the import object
|
||||||
@@ -176,7 +188,6 @@ def strip_imports(scopes):
|
|||||||
result.append(s)
|
result.append(s)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def remove_star_imports(scope):
|
def remove_star_imports(scope):
|
||||||
"""
|
"""
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
a = list
|
a = list
|
||||||
|
|
||||||
|
from math import *
|
||||||
|
|||||||
@@ -43,12 +43,19 @@ def scope_nested():
|
|||||||
#? list
|
#? list
|
||||||
import_tree.pkg.a
|
import_tree.pkg.a
|
||||||
|
|
||||||
|
#? ['sqrt']
|
||||||
|
import_tree.pkg.sqrt
|
||||||
|
|
||||||
#? ['a', 'pkg']
|
#? ['a', 'pkg']
|
||||||
import_tree.
|
import_tree.
|
||||||
|
|
||||||
#? float()
|
#? float()
|
||||||
import_tree.pkg.mod1.a
|
import_tree.pkg.mod1.a
|
||||||
|
|
||||||
|
import import_tree.random
|
||||||
|
#? set
|
||||||
|
import_tree.random.a
|
||||||
|
|
||||||
# -----------------
|
# -----------------
|
||||||
# std lib modules
|
# std lib modules
|
||||||
# -----------------
|
# -----------------
|
||||||
|
|||||||
2
test/completion/thirdparty/pylab.py
vendored
2
test/completion/thirdparty/pylab.py
vendored
@@ -22,3 +22,5 @@ numpy.random_integers
|
|||||||
|
|
||||||
#? ['random_integers']
|
#? ['random_integers']
|
||||||
numpy.random.random_integers
|
numpy.random.random_integers
|
||||||
|
#? ['sample']
|
||||||
|
numpy.random.sample
|
||||||
|
|||||||
Reference in New Issue
Block a user