forked from VimPlug/jedi
Document _import_raw_namespace more
This commit is contained in:
18
jedi/api.py
18
jedi/api.py
@@ -553,22 +553,40 @@ class Interpreter(Script):
|
|||||||
"""
|
"""
|
||||||
Import interpreted Python objects in a namespace.
|
Import interpreted Python objects in a namespace.
|
||||||
|
|
||||||
|
Three kinds of objects are treated here.
|
||||||
|
|
||||||
|
1. Functions and classes. The objects imported like this::
|
||||||
|
|
||||||
|
from os.path import join
|
||||||
|
|
||||||
|
2. Modules. The objects imported like this::
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
3. Instances. The objects created like this::
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
|
dt = datetime(2013, 1, 1)
|
||||||
|
|
||||||
:type raw_namespace: dict
|
:type raw_namespace: dict
|
||||||
:arg raw_namespace: e.g., the dict given by `locals`
|
:arg raw_namespace: e.g., the dict given by `locals`
|
||||||
"""
|
"""
|
||||||
scope = self._parser.scope
|
scope = self._parser.scope
|
||||||
for (variable, obj) in raw_namespace.items():
|
for (variable, obj) in raw_namespace.items():
|
||||||
|
# Import functions and classes
|
||||||
module = getattr(obj, '__module__', None)
|
module = getattr(obj, '__module__', None)
|
||||||
if module:
|
if module:
|
||||||
fakeimport = self._make_fakeimport(module, variable)
|
fakeimport = self._make_fakeimport(module, variable)
|
||||||
scope.add_import(fakeimport)
|
scope.add_import(fakeimport)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# Import modules
|
||||||
if getattr(obj, '__file__', None):
|
if getattr(obj, '__file__', None):
|
||||||
fakeimport = self._make_fakeimport(obj.__name__)
|
fakeimport = self._make_fakeimport(obj.__name__)
|
||||||
scope.add_import(fakeimport)
|
scope.add_import(fakeimport)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# Import instances
|
||||||
objclass = getattr(obj, '__class__', None)
|
objclass = getattr(obj, '__class__', None)
|
||||||
module = getattr(objclass, '__module__', None)
|
module = getattr(objclass, '__module__', None)
|
||||||
if objclass and module:
|
if objclass and module:
|
||||||
|
|||||||
Reference in New Issue
Block a user