forked from VimPlug/jedi
Move some of the compiled.create calls to compiled.builtin_from_name
This commit is contained in:
@@ -312,14 +312,14 @@ class CompiledObjectFilter(AbstractFilter):
|
|||||||
return [self._create_name(name)]
|
return [self._create_name(name)]
|
||||||
|
|
||||||
def values(self):
|
def values(self):
|
||||||
|
from jedi.evaluate.compiled import builtin_from_name
|
||||||
names = []
|
names = []
|
||||||
for name in self._compiled_object.access.dir():
|
for name in self._compiled_object.access.dir():
|
||||||
names += self.get(name)
|
names += self.get(name)
|
||||||
|
|
||||||
# ``dir`` doesn't include the type names.
|
# ``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():
|
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()
|
names += filter.values()
|
||||||
return names
|
return names
|
||||||
|
|
||||||
|
|||||||
@@ -146,7 +146,8 @@ class FunctionExecutionContext(TreeContext):
|
|||||||
try:
|
try:
|
||||||
children = r.children
|
children = r.children
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
context_set |= ContextSet(compiled.create(self.evaluator, None))
|
ctx = compiled.builtin_from_name(self.evaluator, 'None')
|
||||||
|
context_set |= ContextSet(ctx)
|
||||||
else:
|
else:
|
||||||
context_set |= self.eval_node(children[1])
|
context_set |= self.eval_node(children[1])
|
||||||
if check is flow_analysis.REACHABLE:
|
if check is flow_analysis.REACHABLE:
|
||||||
@@ -157,7 +158,8 @@ class FunctionExecutionContext(TreeContext):
|
|||||||
def _eval_yield(self, yield_expr):
|
def _eval_yield(self, yield_expr):
|
||||||
if yield_expr.type == 'keyword':
|
if yield_expr.type == 'keyword':
|
||||||
# `yield` just yields None.
|
# `yield` just yields None.
|
||||||
yield LazyKnownContext(compiled.create(self.evaluator, None))
|
ctx = compiled.builtin_from_name(self.evaluator, 'None')
|
||||||
|
yield LazyKnownContext(ctx)
|
||||||
return
|
return
|
||||||
|
|
||||||
node = yield_expr.children[1]
|
node = yield_expr.children[1]
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ class AbstractInstanceContext(Context):
|
|||||||
if isinstance(obj, AbstractInstanceContext):
|
if isinstance(obj, AbstractInstanceContext):
|
||||||
return self.execute_function_slots(names, obj, obj.class_context)
|
return self.execute_function_slots(names, obj, obj.class_context)
|
||||||
else:
|
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)
|
return self.execute_function_slots(names, none_obj, obj)
|
||||||
else:
|
else:
|
||||||
return ContextSet(self)
|
return ContextSet(self)
|
||||||
|
|||||||
@@ -139,14 +139,14 @@ class ClassContext(use_metaclass(CachedMetaClass, TreeContext)):
|
|||||||
args = arguments.TreeArguments(self.evaluator, self, arglist)
|
args = arguments.TreeArguments(self.evaluator, self, arglist)
|
||||||
return [value for key, value in args.unpack() if key is None]
|
return [value for key, value in args.unpack() if key is None]
|
||||||
else:
|
else:
|
||||||
return [LazyKnownContext(compiled.create(self.evaluator, object))]
|
return [LazyKnownContext(compiled.builtin_from_name(self.evaluator, 'object'))]
|
||||||
|
|
||||||
def py__call__(self, params):
|
def py__call__(self, params):
|
||||||
from jedi.evaluate.context import TreeInstance
|
from jedi.evaluate.context import TreeInstance
|
||||||
return ContextSet(TreeInstance(self.evaluator, self.parent_context, self, params))
|
return ContextSet(TreeInstance(self.evaluator, self.parent_context, self, params))
|
||||||
|
|
||||||
def py__class__(self):
|
def py__class__(self):
|
||||||
return compiled.create(self.evaluator, type)
|
return compiled.builtin_from_name(self.evaluator, 'type')
|
||||||
|
|
||||||
def get_params(self):
|
def get_params(self):
|
||||||
from jedi.evaluate.context import AnonymousInstance
|
from jedi.evaluate.context import AnonymousInstance
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ class _ModuleAttributeName(AbstractNameDefinition):
|
|||||||
self.string_name = string_name
|
self.string_name = string_name
|
||||||
|
|
||||||
def infer(self):
|
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):
|
class ModuleName(ContextNameMixin, AbstractNameDefinition):
|
||||||
|
|||||||
@@ -223,7 +223,8 @@ def builtins_isinstance(evaluator, objects, types, arguments):
|
|||||||
# This is temporary. Everything should have a class attribute in
|
# This is temporary. Everything should have a class attribute in
|
||||||
# Python?! Maybe we'll leave it here, because some numpy objects or
|
# Python?! Maybe we'll leave it here, because some numpy objects or
|
||||||
# whatever might not.
|
# whatever might not.
|
||||||
return ContextSet(compiled.create(evaluator, True), compiled.create(evaluator, False))
|
bool_results = set([True, False])
|
||||||
|
break
|
||||||
|
|
||||||
mro = mro_func()
|
mro = mro_func()
|
||||||
|
|
||||||
@@ -247,7 +248,10 @@ def builtins_isinstance(evaluator, objects, types, arguments):
|
|||||||
'not %s.' % cls_or_tup
|
'not %s.' % cls_or_tup
|
||||||
analysis.add(lazy_context._context, 'type-error-isinstance', node, message)
|
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):
|
def collections_namedtuple(evaluator, obj, arguments):
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ def eval_node(context, element):
|
|||||||
# In Python 2 ellipsis is coded as three single dot tokens, not
|
# In Python 2 ellipsis is coded as three single dot tokens, not
|
||||||
# as one token 3 dot token.
|
# as one token 3 dot token.
|
||||||
assert element.value in ('.', '...')
|
assert element.value in ('.', '...')
|
||||||
return ContextSet(compiled.create(evaluator, Ellipsis))
|
return ContextSet(compiled.builtin_from_name(evaluator, 'Ellipsis'))
|
||||||
elif typ == 'dotted_name':
|
elif typ == 'dotted_name':
|
||||||
context_set = eval_atom(context, element.children[0])
|
context_set = eval_atom(context, element.children[0])
|
||||||
for next_name in element.children[2::2]:
|
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'
|
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):
|
def _eval_comparison_part(evaluator, context, left, operator, right):
|
||||||
l_is_num = is_number(left)
|
l_is_num = is_number(left)
|
||||||
r_is_num = is_number(right)
|
r_is_num = is_number(right)
|
||||||
@@ -382,7 +386,6 @@ def _eval_comparison_part(evaluator, context, left, operator, right):
|
|||||||
# `int() % float()`.
|
# `int() % float()`.
|
||||||
return ContextSet(left)
|
return ContextSet(left)
|
||||||
elif operator in COMPARISON_OPERATORS:
|
elif operator in COMPARISON_OPERATORS:
|
||||||
print(operator, left, right)
|
|
||||||
if is_compiled(left) and is_compiled(right):
|
if is_compiled(left) and is_compiled(right):
|
||||||
# Possible, because the return is not an option. Just compare.
|
# Possible, because the return is not an option. Just compare.
|
||||||
try:
|
try:
|
||||||
@@ -394,9 +397,9 @@ def _eval_comparison_part(evaluator, context, left, operator, right):
|
|||||||
if operator in ('is', '!=', '==', 'is not'):
|
if operator in ('is', '!=', '==', 'is not'):
|
||||||
operation = COMPARISON_OPERATORS[operator]
|
operation = COMPARISON_OPERATORS[operator]
|
||||||
bool_ = operation(left, right)
|
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':
|
elif operator == 'in':
|
||||||
return NO_CONTEXTS
|
return NO_CONTEXTS
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user