本文整理汇总了Python中mypy.nodes.Node.values方法的典型用法代码示例。如果您正苦于以下问题:Python Node.values方法的具体用法?Python Node.values怎么用?Python Node.values使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mypy.nodes.Node
的用法示例。
在下文中一共展示了Node.values方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: perform_transform
# 需要导入模块: from mypy.nodes import Node [as 别名]
# 或者: from mypy.nodes.Node import values [as 别名]
def perform_transform(self, node: Node, transform: Callable[[Type], Type]) -> None:
"""Apply transform to all types associated with node."""
if isinstance(node, ForStmt):
if node.index_type:
node.index_type = transform(node.index_type)
self.transform_types_in_lvalue(node.index, transform)
if isinstance(node, WithStmt):
node.analyzed_types = [transform(typ) for typ in node.analyzed_types]
for n in node.target:
if isinstance(n, NameExpr) and isinstance(n.node, Var) and n.node.type:
n.node.type = transform(n.node.type)
if isinstance(node, (FuncDef, OverloadedFuncDef, CastExpr, AssignmentStmt,
TypeAliasExpr, Var)):
assert node.type, "Scheduled patch for non-existent type"
node.type = transform(node.type)
if isinstance(node, TypeAlias):
node.target = transform(node.target)
if isinstance(node, NewTypeExpr):
assert node.old_type, "Scheduled patch for non-existent type"
node.old_type = transform(node.old_type)
if node.info:
new_bases = [] # type: List[Instance]
for b in node.info.bases:
new_b = transform(b)
# TODO: this code can be combined with code in second pass.
if isinstance(new_b, Instance):
new_bases.append(new_b)
elif isinstance(new_b, TupleType):
new_bases.append(new_b.partial_fallback)
else:
self.fail("Argument 2 to NewType(...) must be subclassable"
" (got {})".format(new_b), node)
new_bases.append(self.builtin_type('object'))
node.info.bases = new_bases
if isinstance(node, TypeVarExpr):
if node.upper_bound:
node.upper_bound = transform(node.upper_bound)
if node.values:
node.values = [transform(v) for v in node.values]
if isinstance(node, TypedDictExpr):
assert node.info.typeddict_type, "Scheduled patch for non-existent type"
node.info.typeddict_type = cast(TypedDictType,
transform(node.info.typeddict_type))
if isinstance(node, NamedTupleExpr):
assert node.info.tuple_type, "Scheduled patch for non-existent type"
node.info.tuple_type = cast(TupleType,
transform(node.info.tuple_type))
if isinstance(node, TypeApplication):
node.types = [transform(t) for t in node.types]
if isinstance(node, TypeInfo):
for tvar in node.defn.type_vars:
if tvar.upper_bound:
tvar.upper_bound = transform(tvar.upper_bound)
if tvar.values:
tvar.values = [transform(v) for v in tvar.values]
new_bases = []
for base in node.bases:
new_base = transform(base)
if isinstance(new_base, Instance):
new_bases.append(new_base)
else:
# Don't fix the NamedTuple bases, they are Instance's intentionally.
# Patch the 'args' just in case, although generic tuple types are
# not supported yet.
alt_base = Instance(base.type, [transform(a) for a in base.args])
new_bases.append(alt_base)
node.bases = new_bases
if node.tuple_type:
new_tuple_type = transform(node.tuple_type)
assert isinstance(new_tuple_type, TupleType)
node.tuple_type = new_tuple_type