From 6fb42e5f4bbbabd542e7e54bc4986a4e94aafde9 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Sun, 3 Mar 2013 12:37:00 +0100 Subject: [PATCH] Document _import_raw_namespace more --- jedi/api.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/jedi/api.py b/jedi/api.py index a1b67a64..28ba607c 100644 --- a/jedi/api.py +++ b/jedi/api.py @@ -553,22 +553,40 @@ class Interpreter(Script): """ 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 :arg raw_namespace: e.g., the dict given by `locals` """ scope = self._parser.scope for (variable, obj) in raw_namespace.items(): + # Import functions and classes module = getattr(obj, '__module__', None) if module: fakeimport = self._make_fakeimport(module, variable) scope.add_import(fakeimport) continue + # Import modules if getattr(obj, '__file__', None): fakeimport = self._make_fakeimport(obj.__name__) scope.add_import(fakeimport) continue + # Import instances objclass = getattr(obj, '__class__', None) module = getattr(objclass, '__module__', None) if objclass and module: