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