mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 14:54:47 +08:00
Refactor some more typing related things
This commit is contained in:
@@ -128,14 +128,13 @@ class AbstractInstanceContext(Context):
|
|||||||
yield InstanceClassFilter(self.evaluator, self, cls, origin_scope)
|
yield InstanceClassFilter(self.evaluator, self, cls, origin_scope)
|
||||||
|
|
||||||
def py__getitem__(self, index_context_set, contextualized_node):
|
def py__getitem__(self, index_context_set, contextualized_node):
|
||||||
try:
|
names = self.get_function_slot_names(u'__getitem__')
|
||||||
names = self.get_function_slot_names(u'__getitem__')
|
if not names:
|
||||||
except KeyError:
|
|
||||||
debug.warning('No __getitem__, cannot access the array.')
|
debug.warning('No __getitem__, cannot access the array.')
|
||||||
return NO_CONTEXTS
|
return NO_CONTEXTS
|
||||||
else:
|
|
||||||
args = ValuesArguments([index_context_set])
|
args = ValuesArguments([index_context_set])
|
||||||
return ContextSet.from_sets(name.infer().execute(args) for name in names)
|
return ContextSet.from_sets(name.infer().execute(args) for name in names)
|
||||||
|
|
||||||
def py__iter__(self):
|
def py__iter__(self):
|
||||||
iter_slot_names = self.get_function_slot_names(u'__iter__')
|
iter_slot_names = self.get_function_slot_names(u'__iter__')
|
||||||
|
|||||||
@@ -32,6 +32,14 @@ class _BaseTypingContext(Context):
|
|||||||
)
|
)
|
||||||
self._name = name
|
self._name = name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def tree_node(self):
|
||||||
|
return self._name.tree_name
|
||||||
|
|
||||||
|
def get_filters(self, *args, **kwargs):
|
||||||
|
# TODO this is obviously wrong.
|
||||||
|
return iter([])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
return TypingName(self, self._name)
|
return TypingName(self, self._name)
|
||||||
@@ -147,14 +155,6 @@ class TypingContext(_BaseTypingContext):
|
|||||||
|
|
||||||
|
|
||||||
class TypingClassMixin(object):
|
class TypingClassMixin(object):
|
||||||
@property
|
|
||||||
def tree_node(self):
|
|
||||||
return self.name.tree_name
|
|
||||||
|
|
||||||
def get_filters(self, *args, **kwargs):
|
|
||||||
# TODO this is obviously wrong.
|
|
||||||
return iter([])
|
|
||||||
|
|
||||||
def py__mro__(self):
|
def py__mro__(self):
|
||||||
return (self,)
|
return (self,)
|
||||||
|
|
||||||
@@ -176,10 +176,6 @@ def _iter_over_arguments(maybe_tuple_context):
|
|||||||
|
|
||||||
|
|
||||||
class _ContainerBase(_WithIndexBase):
|
class _ContainerBase(_WithIndexBase):
|
||||||
def get_filters(self, *args, **kwargs):
|
|
||||||
# TODO this is obviously wrong.
|
|
||||||
return iter([])
|
|
||||||
|
|
||||||
def _get_getitem_contexts(self, index):
|
def _get_getitem_contexts(self, index):
|
||||||
for i, contexts in enumerate(_iter_over_arguments(self._index_context)):
|
for i, contexts in enumerate(_iter_over_arguments(self._index_context)):
|
||||||
if i == index:
|
if i == index:
|
||||||
|
|||||||
@@ -311,7 +311,7 @@ class StubModuleContext(_StubContextFilterMixin, ModuleContext):
|
|||||||
|
|
||||||
class StubClassContext(_StubContextFilterMixin, ClassContext):
|
class StubClassContext(_StubContextFilterMixin, ClassContext):
|
||||||
def __getattribute__(self, name):
|
def __getattribute__(self, name):
|
||||||
if name == ('py__getitem__', 'py__bases__'):
|
if name == ('py__getitem__', 'py__simple_getitem__', 'py__bases__'):
|
||||||
# getitem is always done in the stub class.
|
# getitem is always done in the stub class.
|
||||||
return getattr(self.stub_context, name)
|
return getattr(self.stub_context, name)
|
||||||
return super(StubClassContext, self).__getattribute__(name)
|
return super(StubClassContext, self).__getattribute__(name)
|
||||||
|
|||||||
Reference in New Issue
Block a user