mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-15 18:17:07 +08:00
Use create_simple_object for a lot of use cases
This commit is contained in:
@@ -22,6 +22,15 @@ def builtin_from_name(evaluator, string):
|
|||||||
return create(evaluator, bltn_obj)
|
return create(evaluator, bltn_obj)
|
||||||
|
|
||||||
|
|
||||||
|
def create_simple_object(evaluator, obj):
|
||||||
|
"""
|
||||||
|
Only allows creations of objects that are easily picklable across Python
|
||||||
|
versions.
|
||||||
|
"""
|
||||||
|
assert isinstance(obj, (int, float, str, bytes, slice, complex, type(Ellipsis)))
|
||||||
|
return create(evaluator, obj)
|
||||||
|
|
||||||
|
|
||||||
def create(evaluator, obj):
|
def create(evaluator, obj):
|
||||||
return create_from_access(
|
return create_from_access(
|
||||||
evaluator, create_access(evaluator, obj)
|
evaluator, create_access(evaluator, obj)
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ class AbstractInstanceContext(Context):
|
|||||||
debug.warning('No __getitem__, cannot access the array.')
|
debug.warning('No __getitem__, cannot access the array.')
|
||||||
return NO_CONTEXTS
|
return NO_CONTEXTS
|
||||||
else:
|
else:
|
||||||
index_obj = compiled.create(self.evaluator, index)
|
index_obj = compiled.create_simple_object(self.evaluator, index)
|
||||||
return self.execute_function_slots(names, index_obj)
|
return self.execute_function_slots(names, index_obj)
|
||||||
|
|
||||||
def py__iter__(self):
|
def py__iter__(self):
|
||||||
|
|||||||
@@ -443,7 +443,7 @@ class FakeDict(_FakeArray):
|
|||||||
|
|
||||||
def py__iter__(self):
|
def py__iter__(self):
|
||||||
for key in self._dct:
|
for key in self._dct:
|
||||||
yield LazyKnownContext(compiled.create(self.evaluator, key))
|
yield LazyKnownContext(compiled.create_simple_object(self.evaluator, key))
|
||||||
|
|
||||||
def py__getitem__(self, index):
|
def py__getitem__(self, index):
|
||||||
return self._dct[index].infer()
|
return self._dct[index].infer()
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ class NameFinder(object):
|
|||||||
def _check_getattr(self, inst):
|
def _check_getattr(self, inst):
|
||||||
"""Checks for both __getattr__ and __getattribute__ methods"""
|
"""Checks for both __getattr__ and __getattribute__ methods"""
|
||||||
# str is important, because it shouldn't be `Name`!
|
# str is important, because it shouldn't be `Name`!
|
||||||
name = compiled.create(self._evaluator, self._string_name)
|
name = compiled.create_simple_object(self._evaluator, self._string_name)
|
||||||
|
|
||||||
# This is a little bit special. `__getattribute__` is in Python
|
# This is a little bit special. `__getattribute__` is in Python
|
||||||
# executed before `__getattr__`. But: I know no use case, where
|
# executed before `__getattr__`. But: I know no use case, where
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ def py__getitem__(context, typ, node):
|
|||||||
if isinstance(child, tree.Class))
|
if isinstance(child, tree.Class))
|
||||||
if type_name not in valid_classnames:
|
if type_name not in valid_classnames:
|
||||||
return None
|
return None
|
||||||
compiled_classname = compiled.create(context.evaluator, type_name)
|
compiled_classname = compiled.create_simple_object(context.evaluator, type_name)
|
||||||
|
|
||||||
from jedi.evaluate.context.iterable import FakeSequence
|
from jedi.evaluate.context.iterable import FakeSequence
|
||||||
args = FakeSequence(
|
args = FakeSequence(
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ def eval_atom(context, atom):
|
|||||||
|
|
||||||
elif isinstance(atom, tree.Literal):
|
elif isinstance(atom, tree.Literal):
|
||||||
string = parser_utils.safe_literal_eval(atom.value)
|
string = parser_utils.safe_literal_eval(atom.value)
|
||||||
return ContextSet(compiled.create(context.evaluator, string))
|
return ContextSet(compiled.create_simple_object(context.evaluator, string))
|
||||||
else:
|
else:
|
||||||
c = atom.children
|
c = atom.children
|
||||||
if c[0].type == 'string':
|
if c[0].type == 'string':
|
||||||
@@ -313,7 +313,7 @@ def eval_factor(context_set, operator):
|
|||||||
value = context.py__bool__()
|
value = context.py__bool__()
|
||||||
if value is None: # Uncertainty.
|
if value is None: # Uncertainty.
|
||||||
return
|
return
|
||||||
yield compiled.create(context.evaluator, not value)
|
yield compiled.create_simple_object(context.evaluator, not value)
|
||||||
else:
|
else:
|
||||||
yield context
|
yield context
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user