mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
Create better class filters
This commit is contained in:
@@ -201,6 +201,13 @@ class ClassMixin(object):
|
||||
def py__mro__(self):
|
||||
return py__mro__(self)
|
||||
|
||||
def _create_class_filter(self, cls, origin_scope, is_instance):
|
||||
return ClassFilter(
|
||||
self.evaluator, self, node_context=cls,
|
||||
origin_scope=origin_scope,
|
||||
is_instance=is_instance
|
||||
)
|
||||
|
||||
def get_filters(self, search_global=False, until_position=None,
|
||||
origin_scope=None, is_instance=False):
|
||||
if search_global:
|
||||
@@ -216,11 +223,7 @@ class ClassMixin(object):
|
||||
for filter in cls.get_filters(is_instance=is_instance):
|
||||
yield filter
|
||||
else:
|
||||
yield ClassFilter(
|
||||
self.evaluator, self, node_context=cls,
|
||||
origin_scope=origin_scope,
|
||||
is_instance=is_instance
|
||||
)
|
||||
yield self._create_class_filter(cls, origin_scope, is_instance)
|
||||
if not is_instance and self:
|
||||
# Return completions of the meta class.
|
||||
from jedi.evaluate.compiled import builtin_from_name
|
||||
|
||||
@@ -496,8 +496,29 @@ class AbstractAnnotatedClass(ClassMixin, ContextWrapper):
|
||||
def get_type_var_filter(self):
|
||||
return TypeVarFilter(self.get_given_types(), self.list_type_vars())
|
||||
|
||||
def _create_class_filter(self, cls, origin_scope, is_instance):
|
||||
filter_ = super(AbstractAnnotatedClass, self)._create_class_filter(
|
||||
cls, origin_scope, is_instance
|
||||
)
|
||||
try:
|
||||
stub_context = cls.stub_context
|
||||
except AttributeError:
|
||||
return filter_
|
||||
else:
|
||||
return stub_context.get_stub_only_filter(
|
||||
# Take the first filter, which is here to filter module contents
|
||||
# and wrap it.
|
||||
[filter_],
|
||||
search_global=False,
|
||||
origin_scope=origin_scope,
|
||||
)
|
||||
|
||||
def get_filters(self, search_global=False, *args, **kwargs):
|
||||
for f in super(AbstractAnnotatedClass, self).get_filters(search_global, *args, **kwargs):
|
||||
filters = super(AbstractAnnotatedClass, self).get_filters(
|
||||
search_global,
|
||||
*args, **kwargs
|
||||
)
|
||||
for f in filters:
|
||||
yield f
|
||||
|
||||
if search_global:
|
||||
|
||||
Reference in New Issue
Block a user