forked from VimPlug/jedi
Make get_repr static in access.
This commit is contained in:
@@ -164,7 +164,7 @@ class DirectObjectAccess(object):
|
|||||||
self._obj = obj
|
self._obj = obj
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '%s(%s)' % (self.__class__.__name__, self._obj)
|
return '%s(%s)' % (self.__class__.__name__, self.get_repr())
|
||||||
|
|
||||||
def _create_access(self, obj):
|
def _create_access(self, obj):
|
||||||
return create_access(self._evaluator, obj)
|
return create_access(self._evaluator, obj)
|
||||||
@@ -231,7 +231,16 @@ class DirectObjectAccess(object):
|
|||||||
return [self._create_access_path(base) for base in self._obj.__bases__]
|
return [self._create_access_path(base) for base in self._obj.__bases__]
|
||||||
|
|
||||||
def get_repr(self):
|
def get_repr(self):
|
||||||
return repr(self._obj)
|
# Try to avoid execution of the property.
|
||||||
|
type_ = type(self._obj)
|
||||||
|
if type_ == type:
|
||||||
|
return type.__repr__(self._obj)
|
||||||
|
|
||||||
|
builtins = 'builtins', '__builtin__'
|
||||||
|
if getattr_static(type_, '__module__', default='') in builtins:
|
||||||
|
# Allow direct execution of repr for builtins.
|
||||||
|
return repr(self._obj)
|
||||||
|
return object.__repr__(self._obj)
|
||||||
|
|
||||||
def is_class(self):
|
def is_class(self):
|
||||||
return inspect.isclass(self._obj)
|
return inspect.isclass(self._obj)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ from jedi._compatibility import py_version
|
|||||||
|
|
||||||
_sentinel = object()
|
_sentinel = object()
|
||||||
|
|
||||||
|
|
||||||
def _check_instance(obj, attr):
|
def _check_instance(obj, attr):
|
||||||
instance_dict = {}
|
instance_dict = {}
|
||||||
try:
|
try:
|
||||||
@@ -28,6 +29,7 @@ def _check_class(klass, attr):
|
|||||||
pass
|
pass
|
||||||
return _sentinel
|
return _sentinel
|
||||||
|
|
||||||
|
|
||||||
def _is_type(obj):
|
def _is_type(obj):
|
||||||
try:
|
try:
|
||||||
_static_getmro(obj)
|
_static_getmro(obj)
|
||||||
@@ -143,8 +145,7 @@ def getattr_static(obj, attr, default=_sentinel):
|
|||||||
if not _is_type(obj):
|
if not _is_type(obj):
|
||||||
klass = _get_type(obj)
|
klass = _get_type(obj)
|
||||||
dict_attr = _shadowed_dict(klass)
|
dict_attr = _shadowed_dict(klass)
|
||||||
if (dict_attr is _sentinel or
|
if (dict_attr is _sentinel or type(dict_attr) is types.MemberDescriptorType):
|
||||||
type(dict_attr) is types.MemberDescriptorType):
|
|
||||||
instance_result = _check_instance(obj, attr)
|
instance_result = _check_instance(obj, attr)
|
||||||
else:
|
else:
|
||||||
klass = obj
|
klass = obj
|
||||||
|
|||||||
@@ -256,6 +256,13 @@ class AccessHandle(object):
|
|||||||
def add_subprocess(self, subprocess):
|
def add_subprocess(self, subprocess):
|
||||||
self._subprocess = subprocess
|
self._subprocess = subprocess
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
try:
|
||||||
|
detail = self.access
|
||||||
|
except AttributeError:
|
||||||
|
detail = '#' + str(self.id)
|
||||||
|
return '<%s of %s>' % (self.__class__.__name__, detail)
|
||||||
|
|
||||||
def __getstate__(self):
|
def __getstate__(self):
|
||||||
return self.id
|
return self.id
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user