def docstring(self, fast=True, raw=True): """ The docstring ``__doc__`` for any object. See :attr:`doc` for example. """ full_doc = '' # Using the first docstring that we see. for context in self._get_contexts(fast=fast): if full_doc: # In case we have multiple contexts, just return all of them # separated by a few dashes. full_doc += '\n' + '-' * 30 + '\n' doc = context.py__doc__() if raw: signature_text = '' else: signature_text = _format_signatures(context) if not doc and context.is_stub(): for c in stub_to_actual_context_set(context): doc = c.py__doc__() if doc: break if signature_text and doc: full_doc += signature_text + '\n\n' + doc else: full_doc += signature_text + doc return full_doc
def _trailer_completions(self, previous_leaf): user_context = get_user_scope(self._module_context, self._position) evaluation_context = self._evaluator.create_context( self._module_context, previous_leaf ) contexts = evaluate_call_of_leaf(evaluation_context, previous_leaf) completion_names = [] debug.dbg('trailer completion contexts: %s', contexts, color='MAGENTA') for context in contexts: for filter in context.get_filters( search_global=False, origin_scope=user_context.tree_node): completion_names += filter.values() for context in contexts: if not context.is_stub(): continue actual_contexts = stub_to_actual_context_set(context, ignore_compiled=True) for c in actual_contexts: for filter in c.get_filters( search_global=False, origin_scope=user_context.tree_node): completion_names += filter.values() return completion_names
def _get_context_filters(self, origin_scope): for f in self._context.get_filters(False, self._position, origin_scope=origin_scope): yield f # This covers the case where a stub files are incomplete. if self._context.is_stub(): contexts = stub_to_actual_context_set(self._context, ignore_compiled=True) for c in contexts: for f in c.get_filters(): yield f
def test_compiled_import_none(monkeypatch, Script): """ Related to #1079. An import might somehow fail and return None. """ script = Script('import sys') monkeypatch.setattr(compiled, 'load_module', lambda *args, **kwargs: None) def_, = script.goto_definitions() assert def_.type == 'module' context, = def_._name.infer() assert not stub_to_actual_context_set(context)
def test_compiled_signature(Script, environment, code, sig, names, op, version): if not op(environment.version_info, version): return # The test right next to it should take over. d, = Script(code).goto_definitions() context, = d._name.infer() compiled, = stub_to_actual_context_set(context) signature, = compiled.get_signatures() assert signature.to_string() == sig assert [n.string_name for n in signature.get_param_names()] == names
def completion_names(self, evaluator, only_modules=False): """ :param only_modules: Indicates wheter it's possible to import a definition that is not defined in a module. """ if not self._inference_possible: return [] names = [] if self.import_path: # flask if self._str_import_path == ('flask', 'ext'): # List Flask extensions like ``flask_foo`` for mod in self._get_module_names(): modname = mod.string_name if modname.startswith('flask_'): extname = modname[len('flask_'):] names.append(ImportName(self.module_context, extname)) # Now the old style: ``flaskext.foo`` for dir in self._sys_path_with_modifications(): flaskext = os.path.join(dir, 'flaskext') if os.path.isdir(flaskext): names += self._get_module_names([flaskext]) contexts = self.follow() for context in contexts: # Non-modules are not completable. if context.api_type != 'module': # not a module continue names += context.sub_modules_dict().values() if not only_modules: from jedi.evaluate.gradual.conversion import stub_to_actual_context_set both_contexts = ContextSet.from_sets( stub_to_actual_context_set(context, ignore_compiled=True) for context in contexts if context.is_stub()) | contexts for c in both_contexts: for filter in c.get_filters(search_global=False): names += filter.values() else: if self.level: # We only get here if the level cannot be properly calculated. names += self._get_module_names(self._fixed_sys_path) else: # This is just the list of global imports. names += self._get_module_names() return names
def test_next_docstr(evaluator): next_ = compiled.builtin_from_name(evaluator, u'next') assert next_.tree_node is not None assert next_.py__doc__() == '' # It's a stub for non_stub in stub_to_actual_context_set(next_): assert non_stub.py__doc__() == next.__doc__