diff --git a/jedi/evaluate/compiled/context.py b/jedi/evaluate/compiled/context.py index f9263635..43c63970 100644 --- a/jedi/evaluate/compiled/context.py +++ b/jedi/evaluate/compiled/context.py @@ -312,14 +312,14 @@ class CompiledObjectFilter(AbstractFilter): return [self._create_name(name)] def values(self): + from jedi.evaluate.compiled import builtin_from_name names = [] for name in self._compiled_object.access.dir(): names += self.get(name) # ``dir`` doesn't include the type names. - from jedi.evaluate.compiled import create if not self._is_instance and self._compiled_object.access.needs_type_completions(): - for filter in create(self._evaluator, type).get_filters(): + for filter in builtin_from_name(self._evaluator, 'type').get_filters(): names += filter.values() return names diff --git a/jedi/evaluate/context/function.py b/jedi/evaluate/context/function.py index 0dba9c91..7af1a438 100644 --- a/jedi/evaluate/context/function.py +++ b/jedi/evaluate/context/function.py @@ -146,7 +146,8 @@ class FunctionExecutionContext(TreeContext): try: children = r.children except AttributeError: - context_set |= ContextSet(compiled.create(self.evaluator, None)) + ctx = compiled.builtin_from_name(self.evaluator, 'None') + context_set |= ContextSet(ctx) else: context_set |= self.eval_node(children[1]) if check is flow_analysis.REACHABLE: @@ -157,7 +158,8 @@ class FunctionExecutionContext(TreeContext): def _eval_yield(self, yield_expr): if yield_expr.type == 'keyword': # `yield` just yields None. - yield LazyKnownContext(compiled.create(self.evaluator, None)) + ctx = compiled.builtin_from_name(self.evaluator, 'None') + yield LazyKnownContext(ctx) return node = yield_expr.children[1] diff --git a/jedi/evaluate/context/instance.py b/jedi/evaluate/context/instance.py index 6bf8069a..ca92b012 100644 --- a/jedi/evaluate/context/instance.py +++ b/jedi/evaluate/context/instance.py @@ -95,7 +95,7 @@ class AbstractInstanceContext(Context): if isinstance(obj, AbstractInstanceContext): return self.execute_function_slots(names, obj, obj.class_context) else: - none_obj = compiled.create(self.evaluator, None) + none_obj = compiled.builtin_from_name(self.evaluator, 'None') return self.execute_function_slots(names, none_obj, obj) else: return ContextSet(self) diff --git a/jedi/evaluate/context/klass.py b/jedi/evaluate/context/klass.py index b7d61d3e..c96873e3 100644 --- a/jedi/evaluate/context/klass.py +++ b/jedi/evaluate/context/klass.py @@ -139,14 +139,14 @@ class ClassContext(use_metaclass(CachedMetaClass, TreeContext)): args = arguments.TreeArguments(self.evaluator, self, arglist) return [value for key, value in args.unpack() if key is None] else: - return [LazyKnownContext(compiled.create(self.evaluator, object))] + return [LazyKnownContext(compiled.builtin_from_name(self.evaluator, 'object'))] def py__call__(self, params): from jedi.evaluate.context import TreeInstance return ContextSet(TreeInstance(self.evaluator, self.parent_context, self, params)) def py__class__(self): - return compiled.create(self.evaluator, type) + return compiled.builtin_from_name(self.evaluator, 'type') def get_params(self): from jedi.evaluate.context import AnonymousInstance diff --git a/jedi/evaluate/context/module.py b/jedi/evaluate/context/module.py index 5ba92cdb..3083b46f 100644 --- a/jedi/evaluate/context/module.py +++ b/jedi/evaluate/context/module.py @@ -25,7 +25,8 @@ class _ModuleAttributeName(AbstractNameDefinition): self.string_name = string_name def infer(self): - return compiled.create(self.parent_context.evaluator, str).execute_evaluated() + ctx = compiled.builtin_from_name(self.parent_context.evaluator, 'str') + return ctx.execute_evaluated() class ModuleName(ContextNameMixin, AbstractNameDefinition): diff --git a/jedi/evaluate/stdlib.py b/jedi/evaluate/stdlib.py index 1296c168..f9d70298 100644 --- a/jedi/evaluate/stdlib.py +++ b/jedi/evaluate/stdlib.py @@ -223,7 +223,8 @@ def builtins_isinstance(evaluator, objects, types, arguments): # This is temporary. Everything should have a class attribute in # Python?! Maybe we'll leave it here, because some numpy objects or # whatever might not. - return ContextSet(compiled.create(evaluator, True), compiled.create(evaluator, False)) + bool_results = set([True, False]) + break mro = mro_func() @@ -247,7 +248,10 @@ def builtins_isinstance(evaluator, objects, types, arguments): 'not %s.' % cls_or_tup analysis.add(lazy_context._context, 'type-error-isinstance', node, message) - return ContextSet.from_iterable(compiled.create(evaluator, x) for x in bool_results) + return ContextSet.from_iterable( + compiled.builtin_from_name(evaluator, str(b)) + for b in bool_results + ) def collections_namedtuple(evaluator, obj, arguments): diff --git a/jedi/evaluate/syntax_tree.py b/jedi/evaluate/syntax_tree.py index 8c777db6..f23dff87 100644 --- a/jedi/evaluate/syntax_tree.py +++ b/jedi/evaluate/syntax_tree.py @@ -101,7 +101,7 @@ def eval_node(context, element): # In Python 2 ellipsis is coded as three single dot tokens, not # as one token 3 dot token. assert element.value in ('.', '...') - return ContextSet(compiled.create(evaluator, Ellipsis)) + return ContextSet(compiled.builtin_from_name(evaluator, 'Ellipsis')) elif typ == 'dotted_name': context_set = eval_atom(context, element.children[0]) for next_name in element.children[2::2]: @@ -360,6 +360,10 @@ def _is_list(context): return isinstance(context, iterable.AbstractIterable) and context.array_type == 'list' +def _bool_to_context(evaluator, bool_): + return compiled.builtin_from_name(evaluator, str(bool_)) + + def _eval_comparison_part(evaluator, context, left, operator, right): l_is_num = is_number(left) r_is_num = is_number(right) @@ -382,7 +386,6 @@ def _eval_comparison_part(evaluator, context, left, operator, right): # `int() % float()`. return ContextSet(left) elif operator in COMPARISON_OPERATORS: - print(operator, left, right) if is_compiled(left) and is_compiled(right): # Possible, because the return is not an option. Just compare. try: @@ -394,9 +397,9 @@ def _eval_comparison_part(evaluator, context, left, operator, right): if operator in ('is', '!=', '==', 'is not'): operation = COMPARISON_OPERATORS[operator] bool_ = operation(left, right) - return ContextSet(compiled.create(evaluator, bool_)) + return ContextSet(_bool_to_context(evaluator, bool_)) - return ContextSet(compiled.create(evaluator, True), compiled.create(evaluator, False)) + return ContextSet(_bool_to_context(evaluator, True), _bool_to_context(evaluator, False)) elif operator == 'in': return NO_CONTEXTS