forked from VimPlug/jedi
Refactor allowed_getattr_callback a bit to not raise random errors.
This commit is contained in:
@@ -275,17 +275,18 @@ class DirectObjectAccess(object):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def is_allowed_getattr(self, name):
|
def is_allowed_getattr(self, name):
|
||||||
|
# TODO this API is ugly.
|
||||||
try:
|
try:
|
||||||
attr, is_get_descriptor = getattr_static(self._obj, name)
|
attr, is_get_descriptor = getattr_static(self._obj, name)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
raise
|
return False, False
|
||||||
else:
|
else:
|
||||||
if is_get_descriptor \
|
if is_get_descriptor \
|
||||||
and not type(attr) in ALLOWED_DESCRIPTOR_ACCESS:
|
and not type(attr) in ALLOWED_DESCRIPTOR_ACCESS:
|
||||||
# In case of descriptors that have get methods we cannot return
|
# In case of descriptors that have get methods we cannot return
|
||||||
# it's value, because that would mean code execution.
|
# it's value, because that would mean code execution.
|
||||||
return False
|
return True, True
|
||||||
return True
|
return True, False
|
||||||
|
|
||||||
def getattr(self, name, default=_sentinel):
|
def getattr(self, name, default=_sentinel):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -310,12 +310,13 @@ class CompiledObjectFilter(AbstractFilter):
|
|||||||
"""
|
"""
|
||||||
To remove quite a few access calls we introduced the callback here.
|
To remove quite a few access calls we introduced the callback here.
|
||||||
"""
|
"""
|
||||||
try:
|
has_attribute, is_descriptor = allowed_getattr_callback()
|
||||||
if not allowed_getattr_callback():
|
if not has_attribute:
|
||||||
return [self._get_cached_name(name, is_empty=True)]
|
|
||||||
except AttributeError:
|
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
if is_descriptor:
|
||||||
|
return [self._get_cached_name(name, is_empty=True)]
|
||||||
|
|
||||||
if self._is_instance and name not in dir_callback():
|
if self._is_instance and name not in dir_callback():
|
||||||
return []
|
return []
|
||||||
return [self._get_cached_name(name)]
|
return [self._get_cached_name(name)]
|
||||||
|
|||||||
Reference in New Issue
Block a user