本文整理汇总了Python中mypy.messages.MessageBuilder.duplicate_interfaces方法的典型用法代码示例。如果您正苦于以下问题:Python MessageBuilder.duplicate_interfaces方法的具体用法?Python MessageBuilder.duplicate_interfaces怎么用?Python MessageBuilder.duplicate_interfaces使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mypy.messages.MessageBuilder
的用法示例。
在下文中一共展示了MessageBuilder.duplicate_interfaces方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TypeChecker
# 需要导入模块: from mypy.messages import MessageBuilder [as 别名]
# 或者: from mypy.messages.MessageBuilder import duplicate_interfaces [as 别名]
#.........这里部分代码省略.........
if not is_equivalent(coriginal.arg_types[i],
coverride.arg_types[i]):
self.msg.argument_incompatible_with_supertype(
i + 1, name, supertype, node)
if not is_subtype(coverride.ret_type, coriginal.ret_type):
self.msg.return_type_incompatible_with_supertype(
name, supertype, node)
def visit_type_def(self, defn):
"""Type check a type definition (class or interface)."""
typ = self.lookup(defn.name, GDEF).node
self.errors.set_type(defn.name, defn.is_interface)
self.check_unique_interface_implementations(typ)
self.check_interface_errors(typ)
self.check_no_constructor_if_interface(typ)
self.accept(defn.defs)
self.errors.set_type(None, False)
def check_no_constructor_if_interface(self, typ):
if not typ.is_interface:
return
ctor = typ.get_method('__init__')
if ctor is None:
return
self.msg.interface_has_constructor(ctor)
def check_unique_interface_implementations(self, typ):
"""Check that each interface is implemented only once."""
ifaces = typ.interfaces[:]
dup = find_duplicate(ifaces)
if dup:
self.msg.duplicate_interfaces(typ, dup)
return
base = typ.base
while base:
# Avoid duplicate error messages.
if find_duplicate(base.interfaces):
return
ifaces.extend(base.interfaces)
dup = find_duplicate(ifaces)
if dup:
self.msg.duplicate_interfaces(typ, dup)
return
base = base.base
def check_interface_errors(self, typ):
interfaces = typ.all_directly_implemented_interfaces()
for iface in interfaces:
for n in iface.methods.keys():
if not typ.has_method(n):
self.msg.interface_member_not_implemented(typ, iface, n)
#
# Statements
#
def visit_block(self, b):
for s in b.body:
self.accept(s)
def visit_assignment_stmt(self, s):
"""Type check an assignment statement.