mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Cleanup some callbacks
This commit is contained in:
@@ -397,26 +397,27 @@ class CompiledObjectFilter(AbstractFilter):
|
|||||||
def get(self, name):
|
def get(self, name):
|
||||||
return self._get(
|
return self._get(
|
||||||
name,
|
name,
|
||||||
lambda: self.compiled_object.access_handle.is_allowed_getattr(force_unicode(name)),
|
lambda name: self.compiled_object.access_handle.is_allowed_getattr(name),
|
||||||
lambda: self.compiled_object.access_handle.dir(),
|
lambda name: name in self.compiled_object.access_handle.dir(),
|
||||||
check_has_attribute=True
|
check_has_attribute=True
|
||||||
)
|
)
|
||||||
|
|
||||||
def _get(self, name, allowed_getattr_callback, dir_callback, check_has_attribute=False):
|
def _get(self, name, allowed_getattr_callback, in_dir_callback, check_has_attribute=False):
|
||||||
"""
|
"""
|
||||||
To remove quite a few access calls we introduced the callback here.
|
To remove quite a few access calls we introduced the callback here.
|
||||||
"""
|
"""
|
||||||
has_attribute, is_descriptor = allowed_getattr_callback()
|
|
||||||
if check_has_attribute and not has_attribute:
|
|
||||||
return []
|
|
||||||
|
|
||||||
# Always use unicode objects in Python 2 from here.
|
# Always use unicode objects in Python 2 from here.
|
||||||
name = force_unicode(name)
|
name = force_unicode(name)
|
||||||
|
|
||||||
if (is_descriptor and not self._inference_state.allow_descriptor_getattr) or not has_attribute:
|
has_attribute, is_descriptor = allowed_getattr_callback(name)
|
||||||
|
if check_has_attribute and not has_attribute:
|
||||||
|
return []
|
||||||
|
|
||||||
|
if (is_descriptor and not self._inference_state.allow_descriptor_getattr) \
|
||||||
|
or not has_attribute:
|
||||||
return [self._get_cached_name(name, is_empty=True)]
|
return [self._get_cached_name(name, is_empty=True)]
|
||||||
|
|
||||||
if self.is_instance and name not in dir_callback():
|
if self.is_instance and not in_dir_callback(name):
|
||||||
return []
|
return []
|
||||||
return [self._get_cached_name(name)]
|
return [self._get_cached_name(name)]
|
||||||
|
|
||||||
@@ -434,8 +435,8 @@ class CompiledObjectFilter(AbstractFilter):
|
|||||||
for name in dir_infos:
|
for name in dir_infos:
|
||||||
names += self._get(
|
names += self._get(
|
||||||
name,
|
name,
|
||||||
lambda: dir_infos[name],
|
lambda name: dir_infos[name],
|
||||||
lambda: dir_infos.keys(),
|
lambda name: name in dir_infos,
|
||||||
)
|
)
|
||||||
|
|
||||||
# ``dir`` doesn't include the type names.
|
# ``dir`` doesn't include the type names.
|
||||||
|
|||||||
Reference in New Issue
Block a user