mirror of
https://github.com/davidhalter/jedi.git
synced 2026-01-30 20:35:23 +08:00
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)]
|
||||
|
||||
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
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user