本文整理汇总了Python中mypy.messages.MessageBuilder.incompatible_value_count_in_assignment方法的典型用法代码示例。如果您正苦于以下问题:Python MessageBuilder.incompatible_value_count_in_assignment方法的具体用法?Python MessageBuilder.incompatible_value_count_in_assignment怎么用?Python MessageBuilder.incompatible_value_count_in_assignment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mypy.messages.MessageBuilder
的用法示例。
在下文中一共展示了MessageBuilder.incompatible_value_count_in_assignment方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TypeChecker
# 需要导入模块: from mypy.messages import MessageBuilder [as 别名]
# 或者: from mypy.messages.MessageBuilder import incompatible_value_count_in_assignment [as 别名]
#.........这里部分代码省略.........
def expand_lvalues(self, n):
if isinstance(n, TupleExpr):
return self.expr_checker.unwrap_list((n).items)
elif isinstance(n, ListExpr):
return self.expr_checker.unwrap_list((n).items)
elif isinstance(n, ParenExpr):
return self.expand_lvalues((n).expr)
else:
return [n]
def infer_variable_type(self, names, lvalues, init_type, context):
"""Infer the type of initialized variables from initializer type."""
if isinstance(init_type, Void):
self.check_not_void(init_type, context)
elif not self.is_valid_inferred_type(init_type):
# We cannot use the type of the initialization expression for type
# inference (it's not specific enough).
self.fail(messages.NEED_ANNOTATION_FOR_VAR, context)
else:
# Infer type of the target.
# Make the type more general (strip away function names etc.).
init_type = strip_type(init_type)
if len(names) > 1:
if isinstance(init_type, TupleType):
tinit_type = init_type
# Initializer with a tuple type.
if len(tinit_type.items) == len(names):
for i in range(len(names)):
self.set_inferred_type(names[i], lvalues[i],
tinit_type.items[i])
else:
self.msg.incompatible_value_count_in_assignment(
len(names), len(tinit_type.items), context)
elif (isinstance(init_type, Instance) and
(init_type).type.full_name() ==
'builtins.list'):
# Initializer with an array type.
item_type = (init_type).args[0]
for i in range(len(names)):
self.set_inferred_type(names[i], lvalues[i], item_type)
elif isinstance(init_type, Any):
for i in range(len(names)):
self.set_inferred_type(names[i], lvalues[i], Any())
else:
self.fail(messages.INCOMPATIBLE_TYPES_IN_ASSIGNMENT,
context)
else:
for v in names:
self.set_inferred_type(v, lvalues[0], init_type)
def set_inferred_type(self, var, lvalue, type):
"""Store inferred variable type.
Store the type to both the variable node and the expression node that
refers to the variable (lvalue). If var is None, do nothing.
"""
if var:
var.type = type
self.store_type(lvalue, type)
def is_valid_inferred_type(self, typ):
"""Is an inferred type invalid?
Examples include the None type or a type with a None component.