mirror of
https://github.com/davidhalter/jedi.git
synced 2026-02-06 05:07:40 +08:00
Move get_special_object
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user