本文整理汇总了Python中mypy.messages.MessageBuilder.incompatible_operator_assignment方法的典型用法代码示例。如果您正苦于以下问题:Python MessageBuilder.incompatible_operator_assignment方法的具体用法?Python MessageBuilder.incompatible_operator_assignment怎么用?Python MessageBuilder.incompatible_operator_assignment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mypy.messages.MessageBuilder
的用法示例。
在下文中一共展示了MessageBuilder.incompatible_operator_assignment方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TypeChecker
# 需要导入模块: from mypy.messages import MessageBuilder [as 别名]
# 或者: from mypy.messages.MessageBuilder import incompatible_operator_assignment [as 别名]
#.........这里部分代码省略.........
return None
actual_item_type = self.accept(s.expr, expected_item_type)
self.check_subtype(actual_item_type, expected_item_type, s)
def visit_if_stmt(self, s):
"""Type check an if statement."""
for e in s.expr:
t = self.accept(e)
self.check_not_void(t, e)
for b in s.body:
self.accept(b)
if s.else_body:
self.accept(s.else_body)
def visit_while_stmt(self, s):
"""Type check a while statement."""
t = self.accept(s.expr)
self.check_not_void(t, s)
self.accept(s.body)
if s.else_body:
self.accept(s.else_body)
def visit_operator_assignment_stmt(self, s):
"""Type check an operator assignment statement, e.g. x += 1."""
lvalue_type = self.accept(s.lvalue)
rvalue_type, method_type = self.expr_checker.check_op(
nodes.op_methods[s.op], lvalue_type, s.rvalue, s)
if isinstance(s.lvalue, IndexExpr):
lv = s.lvalue
self.check_single_assignment(None, lv, s.rvalue, s.rvalue)
else:
if not is_subtype(rvalue_type, lvalue_type):
self.msg.incompatible_operator_assignment(s.op, s)
def visit_assert_stmt(self, s):
self.accept(s.expr)
def visit_raise_stmt(self, s):
"""Type check a raise statement."""
typ = self.accept(s.expr)
self.check_subtype(typ, self.named_type('builtins.BaseException'), s,
messages.INVALID_EXCEPTION_TYPE)
def visit_try_stmt(self, s):
"""Type check a try statement."""
self.accept(s.body)
for i in range(len(s.handlers)):
if s.types[i]:
t = self.exception_type(s.types[i])
if s.vars[i]:
s.vars[i].type = t
self.accept(s.handlers[i])
if s.finally_body:
self.accept(s.finally_body)
if s.else_body:
self.accept(s.else_body)
def exception_type(self, n):
if isinstance(n, NameExpr):
name = n
if isinstance(name.node, TypeInfo):
return self.check_exception_type(name.node, n)
elif isinstance(n, MemberExpr):
m = n
if isinstance(m.node, TypeInfo):