mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 05:54:25 +08:00
Cleanup some callbacks
This commit is contained in:
@@ -397,26 +397,27 @@ class CompiledObjectFilter(AbstractFilter):
|
||||
def get(self, name):
|
||||
return self._get(
|
||||
name,
|
||||
lambda: self.compiled_object.access_handle.is_allowed_getattr(force_unicode(name)),
|
||||
lambda: self.compiled_object.access_handle.dir(),
|
||||
lambda name: self.compiled_object.access_handle.is_allowed_getattr(name),
|
||||
lambda name: name in self.compiled_object.access_handle.dir(),
|
||||
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.
|
||||
"""
|
||||
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.
|
||||
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)]
|
||||
|
||||
if self.is_instance and name not in dir_callback():
|
||||
if self.is_instance and not in_dir_callback(name):
|
||||
return []
|
||||
return [self._get_cached_name(name)]
|
||||
|
||||
@@ -434,8 +435,8 @@ class CompiledObjectFilter(AbstractFilter):
|
||||
for name in dir_infos:
|
||||
names += self._get(
|
||||
name,
|
||||
lambda: dir_infos[name],
|
||||
lambda: dir_infos.keys(),
|
||||
lambda name: dir_infos[name],
|
||||
lambda name: name in dir_infos,
|
||||
)
|
||||
|
||||
# ``dir`` doesn't include the type names.
|
||||
|
||||
Reference in New Issue
Block a user