Fix subscriptlist unpacking in Generics

This commit is contained in:
Dave Halter
2018-08-30 00:52:22 +02:00
parent 18e6a784e8
commit 1fce0b45f4
4 changed files with 21 additions and 6 deletions

View File

@@ -220,6 +220,9 @@ class ClassContext(use_metaclass(CachedMetaClass, TreeContext)):
def name(self): def name(self):
return ContextName(self, self.tree_node.name) return ContextName(self, self.tree_node.name)
def py__name__(self):
return self.name.string_name
def py__getitem__(self, index_context_set, contextualized_node): def py__getitem__(self, index_context_set, contextualized_node):
from jedi.evaluate.context.typing import TypingClassMixin, AnnotatedClass from jedi.evaluate.context.typing import TypingClassMixin, AnnotatedClass
for cls in self.py__mro__(): for cls in self.py__mro__():

View File

@@ -481,12 +481,22 @@ class _AbstractAnnotatedClass(ClassContext):
if node.type == 'atom_expr': if node.type == 'atom_expr':
trailer = node.children[1] trailer = node.children[1]
if trailer.type == 'trailer' and trailer.children[0] == '[': if trailer.type == 'trailer' and trailer.children[0] == '[':
type_var_set = self.parent_context.eval_node(trailer.children[1]) for subscript_node in self._unpack_subscriptlist(trailer.children[1]):
type_var_set = self.parent_context.eval_node(subscript_node)
for type_var in type_var_set: for type_var in type_var_set:
if isinstance(type_var, TypeVar) and type_var not in found: if isinstance(type_var, TypeVar) and type_var not in found:
found.append(type_var) found.append(type_var)
return found return found
def _unpack_subscriptlist(self, subscriptlist):
if subscriptlist.type == 'subscriptlist':
for subscript in subscriptlist.children[::2]:
if subscript.type != 'subscript':
yield subscript
else:
if subscriptlist.type != 'subscript':
yield subscriptlist
def get_given_types(self): def get_given_types(self):
raise NotImplementedError raise NotImplementedError

View File

@@ -503,7 +503,9 @@ def _eval_comparison_part(evaluator, context, left, operator, right):
analysis.add(context, 'type-error-operation', operator, analysis.add(context, 'type-error-operation', operator,
message % (left, right)) message % (left, right))
return ContextSet(left, right) result = ContextSet(left, right)
debug.dbg('Used operator %s resulting in %s', result)
return result
def _remove_statements(evaluator, context, stmt, name): def _remove_statements(evaluator, context, stmt, name):

View File

@@ -209,7 +209,7 @@ def optional(p):
as being of that type. Jedi doesn't do anything with the extra into that as being of that type. Jedi doesn't do anything with the extra into that
it can be None as well it can be None as well
""" """
#? int() #? int() None
p p
class ForwardReference: class ForwardReference: