Fix all remaining static analysis tests. This time we have just hacked around and added proper contexts to the iterables. It's not as clean as it could be.

This commit is contained in:
Dave Halter
2016-12-15 00:34:14 +01:00
parent 3a84e04df7
commit edf1c319c6
+8 -4
View File
@@ -623,13 +623,15 @@ def unpack_tuple_to_dict(evaluator, types, exprlist):
try: try:
part = next(parts) part = next(parts)
except StopIteration: except StopIteration:
analysis.add(evaluator, 'value-error-too-many-values', part, # TODO this context is probably not right.
analysis.add(next(iter(types)), 'value-error-too-many-values', part,
message="ValueError: too many values to unpack (expected %s)" % n) message="ValueError: too many values to unpack (expected %s)" % n)
else: else:
dct.update(unpack_tuple_to_dict(evaluator, lazy_context.infer(), part)) dct.update(unpack_tuple_to_dict(evaluator, lazy_context.infer(), part))
has_parts = next(parts, None) has_parts = next(parts, None)
if types and has_parts is not None: if types and has_parts is not None:
analysis.add(evaluator, 'value-error-too-few-values', has_parts, # TODO this context is probably not right.
analysis.add(next(iter(types)), 'value-error-too-few-values', has_parts,
message="ValueError: need more than %s values to unpack" % n) message="ValueError: need more than %s values to unpack" % n)
return dct return dct
elif exprlist.type == 'power' or exprlist.type == 'atom_expr': elif exprlist.type == 'power' or exprlist.type == 'atom_expr':
@@ -651,7 +653,8 @@ def py__iter__(evaluator, types, node=None):
iter_method = typ.py__iter__ iter_method = typ.py__iter__
except AttributeError: except AttributeError:
if node is not None: if node is not None:
analysis.add(evaluator, 'type-error-not-iterable', node, # TODO this context is probably not right.
analysis.add(typ, 'type-error-not-iterable', node,
message="TypeError: '%s' object is not iterable" % typ) message="TypeError: '%s' object is not iterable" % typ)
else: else:
type_iters.append(iter_method()) type_iters.append(iter_method())
@@ -709,7 +712,8 @@ def py__getitem__(evaluator, context, types, trailer):
try: try:
getitem = typ.py__getitem__ getitem = typ.py__getitem__
except AttributeError: except AttributeError:
analysis.add(evaluator, 'type-error-not-subscriptable', trailer_op, # TODO this context is probably not right.
analysis.add(context, 'type-error-not-subscriptable', trailer_op,
message="TypeError: '%s' object is not subscriptable" % typ) message="TypeError: '%s' object is not subscriptable" % typ)
else: else:
try: try: