forked from VimPlug/jedi
Move get_special_object
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
import types
|
|
||||||
|
|
||||||
from jedi._compatibility import builtins as _builtins
|
from jedi._compatibility import builtins as _builtins
|
||||||
from jedi.evaluate.compiled.context import CompiledObject, CompiledName, \
|
from jedi.evaluate.compiled.context import CompiledObject, CompiledName, \
|
||||||
CompiledObjectFilter, CompiledContextName, create_from_access_path
|
CompiledObjectFilter, CompiledContextName, create_from_access_path
|
||||||
@@ -26,24 +24,11 @@ def create(evaluator, obj):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _a_generator(foo):
|
|
||||||
"""Used to have an object to return for generators."""
|
|
||||||
yield 42
|
|
||||||
yield foo
|
|
||||||
|
|
||||||
|
|
||||||
_SPECIAL_OBJECTS = {
|
|
||||||
'FUNCTION_CLASS': types.FunctionType,
|
|
||||||
'METHOD_CLASS': type(CompiledObject.is_class),
|
|
||||||
'MODULE_CLASS': types.ModuleType,
|
|
||||||
'GENERATOR_OBJECT': _a_generator(1.0),
|
|
||||||
'BUILTINS': _builtins,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def get_special_object(evaluator, identifier):
|
def get_special_object(evaluator, identifier):
|
||||||
obj = _SPECIAL_OBJECTS[identifier]
|
return create_from_access_path(
|
||||||
return create(evaluator, obj)
|
evaluator,
|
||||||
|
access.get_special_object(evaluator, identifier)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def load_module(evaluator, path=None, name=None):
|
def load_module(evaluator, path=None, name=None):
|
||||||
|
|||||||
@@ -55,6 +55,13 @@ ALLOWED_DESCRIPTOR_ACCESS = (
|
|||||||
classmethod,
|
classmethod,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _a_generator(foo):
|
||||||
|
"""Used to have an object to return for generators."""
|
||||||
|
yield 42
|
||||||
|
yield foo
|
||||||
|
|
||||||
|
|
||||||
_sentinel = object()
|
_sentinel = object()
|
||||||
|
|
||||||
# Maps Python syntax to the operator module.
|
# Maps Python syntax to the operator module.
|
||||||
@@ -378,3 +385,18 @@ def _is_class_instance(obj):
|
|||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return cls != type and not issubclass(cls, NOT_CLASS_TYPES)
|
return cls != type and not issubclass(cls, NOT_CLASS_TYPES)
|
||||||
|
|
||||||
|
|
||||||
|
_SPECIAL_OBJECTS = {
|
||||||
|
'FUNCTION_CLASS': types.FunctionType,
|
||||||
|
'METHOD_CLASS': type(DirectObjectAccess.py__bool__),
|
||||||
|
'MODULE_CLASS': types.ModuleType,
|
||||||
|
'GENERATOR_OBJECT': _a_generator(1.0),
|
||||||
|
'BUILTINS': builtins,
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_special_object(evaluator, identifier):
|
||||||
|
obj = _SPECIAL_OBJECTS[identifier]
|
||||||
|
return create_access_path(evaluator, obj)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user