本文整理汇总了Python中mypy.nodes.TypeInfo.mro方法的典型用法代码示例。如果您正苦于以下问题:Python TypeInfo.mro方法的具体用法?Python TypeInfo.mro怎么用?Python TypeInfo.mro使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mypy.nodes.TypeInfo
的用法示例。
在下文中一共展示了TypeInfo.mro方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: visit_type_info
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import mro [as 别名]
def visit_type_info(self, info: TypeInfo) -> None:
save_info = self.current_info
try:
self.current_info = info
if info.defn:
info.defn.accept(self)
if info.names:
self.visit_symbol_table(info.names)
if info.bases:
for base in info.bases:
base.accept(self.type_fixer)
if info._promote:
info._promote.accept(self.type_fixer)
if info.tuple_type:
info.tuple_type.accept(self.type_fixer)
if info.typeddict_type:
info.typeddict_type.accept(self.type_fixer)
if info.declared_metaclass:
info.declared_metaclass.accept(self.type_fixer)
if info.metaclass_type:
info.metaclass_type.accept(self.type_fixer)
if info._mro_refs:
info.mro = [lookup_qualified_typeinfo(self.modules, name, self.quick_and_dirty)
for name in info._mro_refs]
info._mro_refs = None
finally:
self.current_info = save_info
示例2: make_type_info
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import mro [as 别名]
def make_type_info(name: str,
is_abstract: bool = False,
mro: List[TypeInfo] = None,
bases: List[Instance] = None,
typevars: List[str] = None) -> TypeInfo:
"""Make a TypeInfo suitable for use in unit tests."""
class_def = ClassDef(name, Block([]), None, [])
class_def.fullname = name
if typevars:
v = [] # type: List[TypeVarDef]
id = 1
for n in typevars:
v.append(TypeVarDef(n, id, None))
id += 1
class_def.type_vars = v
info = TypeInfo(SymbolTable(), class_def)
if mro is None:
mro = []
info.mro = [info] + mro
if bases is None:
if mro:
# By default, assume that there is a single non-generic base.
bases = [Instance(mro[0], [])]
else:
bases = []
info.bases = bases
return info
示例3: stale_info
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import mro [as 别名]
def stale_info() -> TypeInfo:
suggestion = "<stale cache: consider running mypy without --quick>"
dummy_def = ClassDef(suggestion, Block([]))
dummy_def.fullname = suggestion
info = TypeInfo(SymbolTable(), dummy_def, "<stale>")
info.mro = [info]
info.bases = []
return info
示例4: stale_info
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import mro [as 别名]
def stale_info(modules: Dict[str, MypyFile]) -> TypeInfo:
suggestion = "<stale cache: consider running mypy without --quick>"
dummy_def = ClassDef(suggestion, Block([]))
dummy_def.fullname = suggestion
info = TypeInfo(SymbolTable(), dummy_def, "<stale>")
obj_type = lookup_qualified(modules, 'builtins.object', False)
assert isinstance(obj_type, TypeInfo)
info.bases = [Instance(obj_type, [])]
info.mro = [info, obj_type]
return info
示例5: add_info_hook
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import mro [as 别名]
def add_info_hook(ctx) -> None:
class_def = ClassDef(ctx.name, Block([]))
class_def.fullname = ctx.api.qualified_name(ctx.name)
info = TypeInfo(SymbolTable(), class_def, ctx.api.cur_mod_id)
class_def.info = info
obj = ctx.api.builtin_type('builtins.object')
info.mro = [info, obj.type]
info.bases = [obj]
ctx.api.add_symbol_table_node(ctx.name, SymbolTableNode(GDEF, info))
info.metadata['magic'] = True
示例6: calculate_mro
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import mro [as 别名]
def calculate_mro(info: TypeInfo, obj_type: Optional[Callable[[], Instance]] = None) -> None:
"""Calculate and set mro (method resolution order).
Raise MroError if cannot determine mro.
"""
mro = linearize_hierarchy(info, obj_type)
assert mro, "Could not produce a MRO at all for %s" % (info,)
info.mro = mro
# The property of falling back to Any is inherited.
info.fallback_to_any = any(baseinfo.fallback_to_any for baseinfo in info.mro)
TypeState.reset_all_subtype_caches_for(info)
示例7: missing_info
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import mro [as 别名]
def missing_info(modules: Dict[str, MypyFile]) -> TypeInfo:
suggestion = "<missing info: *should* have gone away during fine-grained update>"
dummy_def = ClassDef(suggestion, Block([]))
dummy_def.fullname = suggestion
info = TypeInfo(SymbolTable(), dummy_def, "<missing>")
obj_type = lookup_qualified(modules, 'builtins.object', False)
assert isinstance(obj_type, TypeInfo)
info.bases = [Instance(obj_type, [])]
info.mro = [info, obj_type]
return info
示例8: make_type_info
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import mro [as 别名]
def make_type_info(self, name: str,
module_name: Optional[str] = None,
is_abstract: bool = False,
mro: Optional[List[TypeInfo]] = None,
bases: Optional[List[Instance]] = None,
typevars: Optional[List[str]] = None,
variances: Optional[List[int]] = None) -> TypeInfo:
"""Make a TypeInfo suitable for use in unit tests."""
class_def = ClassDef(name, Block([]), None, [])
class_def.fullname = name
if module_name is None:
if '.' in name:
module_name = name.rsplit('.', 1)[0]
else:
module_name = '__main__'
if typevars:
v = [] # type: List[TypeVarDef]
for id, n in enumerate(typevars, 1):
if variances:
variance = variances[id - 1]
else:
variance = COVARIANT
v.append(TypeVarDef(n, n, id, [], self.o, variance=variance))
class_def.type_vars = v
info = TypeInfo(SymbolTable(), class_def, module_name)
if mro is None:
mro = []
if name != 'builtins.object':
mro.append(self.oi)
info.mro = [info] + mro
if bases is None:
if mro:
# By default, assume that there is a single non-generic base.
bases = [Instance(mro[0], [])]
else:
bases = []
info.bases = bases
return info
示例9: strip_type_info
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import mro [as 别名]
def strip_type_info(self, info: TypeInfo) -> List[SymbolNode]:
info.type_vars = []
info.bases = []
info.is_abstract = False
info.abstract_attributes = []
info.mro = []
info.add_type_vars()
info.tuple_type = None
info.typeddict_type = None
info.tuple_type = None
TypeState.reset_subtype_caches_for(info)
info.declared_metaclass = None
info.metaclass_type = None
# We need to delete any entries that were generated by plugins,
# since they will get regenerated.
to_delete = [(k, v) for k, v in info.names.items() if v.plugin_generated]
for k, _ in to_delete:
del info.names[k]
return [v.node for k, v in to_delete if v.node]