本文整理汇总了Python中mypy.nodes.TypeInfo.bases方法的典型用法代码示例。如果您正苦于以下问题:Python TypeInfo.bases方法的具体用法?Python TypeInfo.bases怎么用?Python TypeInfo.bases使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mypy.nodes.TypeInfo
的用法示例。
在下文中一共展示了TypeInfo.bases方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_type_info
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import bases [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
示例2: stale_info
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import bases [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
示例3: stale_info
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import bases [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
示例4: add_info_hook
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import bases [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
示例5: missing_info
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import bases [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
示例6: make_type_info
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import bases [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
示例7: strip_type_info
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import bases [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]
示例8: make_type_info
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import bases [as 别名]
self.m1i = make_type_info('M1', (INTERFACES, [self.gfi]),
(BASE_DEFS, [Instance(self.gfi, [self.a])]))
self.gfa = Instance(self.gfi, [self.a]) # GF<A>
self.gfb = Instance(self.gfi, [self.b]) # GF<B>
self.m1 = Instance(self.m1i, []) # M1
TypeInfo make_type_info(any name, any *args):
"""Make a TypeInfo suitable for use in unit tests."""
map = dict(args)
type_def = TypeDef(name, Block([]), None, [])
type_def.fullname = name
if VARS in map:
TypeVarDef[] v = []
id = 1
for n in map[VARS]:
v.append(TypeVarDef(n, id))
id += 1
type_def.type_vars = TypeVars(v)
info = TypeInfo(SymbolTable(), type_def)
info.base = map.get(BASE, None)
info.bases = map.get(BASE_DEFS, [])
info.interfaces = map.get(INTERFACES, []) # TODO fix
return info