Move get_special_object

This commit is contained in:
Dave Halter
2017-12-05 00:32:39 +01:00
parent 542644ad19
commit 79071790da
2 changed files with 26 additions and 19 deletions

View File

@@ -1,5 +1,3 @@
import types
from jedi._compatibility import builtins as _builtins
from jedi.evaluate.compiled.context import CompiledObject, CompiledName, \
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):
obj = _SPECIAL_OBJECTS[identifier]
return create(evaluator, obj)
return create_from_access_path(
evaluator,
access.get_special_object(evaluator, identifier)
)
def load_module(evaluator, path=None, name=None):

View File

@@ -55,6 +55,13 @@ ALLOWED_DESCRIPTOR_ACCESS = (
classmethod,
)
def _a_generator(foo):
"""Used to have an object to return for generators."""
yield 42
yield foo
_sentinel = object()
# Maps Python syntax to the operator module.
@@ -378,3 +385,18 @@ def _is_class_instance(obj):
return False
else:
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)