本文整理汇总了Python中mypy.nodes.ClassDef.defs方法的典型用法代码示例。如果您正苦于以下问题:Python ClassDef.defs方法的具体用法?Python ClassDef.defs怎么用?Python ClassDef.defs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mypy.nodes.ClassDef
的用法示例。
在下文中一共展示了ClassDef.defs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: transform_class_def
# 需要导入模块: from mypy.nodes import ClassDef [as 别名]
# 或者: from mypy.nodes.ClassDef import defs [as 别名]
def transform_class_def(self, tdef: ClassDef) -> List[Node]:
"""Transform a type definition.
The result may be one or two definitions. The first is the
transformation of the original ClassDef. The second is a
wrapper type, which is generated for generic types only.
"""
defs = [] # type: List[Node]
if tdef.info.type_vars:
# This is a generic type. Insert type variable slots in
# the class definition for new type variables, i.e. type
# variables not mapped to superclass type variables.
defs.extend(self.make_tvar_representation(tdef.info))
# Iterate over definitions and transform each of them.
vars = set() # type: Set[Var]
for d in tdef.defs.body:
if isinstance(d, FuncDef):
# Implicit cast from FuncDef[] to Node[] is safe below.
defs.extend(Any(self.func_tf.transform_method(d)))
elif isinstance(d, VarDef):
defs.extend(self.transform_var_def(d))
for n in d.items:
vars.add(n)
elif isinstance(d, AssignmentStmt):
self.transform_assignment(d)
defs.append(d)
# Add accessors for implicitly defined attributes.
for node in tdef.info.names.values():
if isinstance(node.node, Var):
v = cast(Var, node.node)
if v.info == tdef.info and v not in vars:
defs.extend(self.make_accessors(v))
# For generic classes, add an implicit __init__ wrapper.
defs.extend(self.make_init_wrapper(tdef))
if tdef.is_generic() or (tdef.info.bases and
tdef.info.mro[1].is_generic()):
self.make_instance_tvar_initializer(
cast(FuncDef, tdef.info.get_method('__init__')))
if not defs:
defs.append(PassStmt())
if tdef.is_generic():
gen_wrapper = self.generic_class_wrapper(tdef)
tdef.defs = Block(defs)
dyn_wrapper = self.make_type_object_wrapper(tdef)
if not tdef.is_generic():
return [tdef, dyn_wrapper]
else:
return [tdef, dyn_wrapper, gen_wrapper]