本文整理汇总了Python中mypy.nodes.Var.is_initialized_in_class方法的典型用法代码示例。如果您正苦于以下问题:Python Var.is_initialized_in_class方法的具体用法?Python Var.is_initialized_in_class怎么用?Python Var.is_initialized_in_class使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mypy.nodes.Var
的用法示例。
在下文中一共展示了Var.is_initialized_in_class方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_field
# 需要导入模块: from mypy.nodes import Var [as 别名]
# 或者: from mypy.nodes.Var import is_initialized_in_class [as 别名]
def add_field(var: Var, is_initialized_in_class: bool = False,
is_property: bool = False) -> None:
var.info = info
var.is_initialized_in_class = is_initialized_in_class
var.is_property = is_property
var._fullname = '%s.%s' % (info.fullname(), var.name())
info.names[var.name()] = SymbolTableNode(MDEF, var)
示例2: analyse_lvalue
# 需要导入模块: from mypy.nodes import Var [as 别名]
# 或者: from mypy.nodes.Var import is_initialized_in_class [as 别名]
def analyse_lvalue(self, lval, nested=False, add_defs=False):
if isinstance(lval, NameExpr):
n = lval
nested_global = not self.locals and self.block_depth > 0 and not self.type
if (add_defs or nested_global) and n.name not in self.globals:
# Define new global name.
v = Var(n.name)
v._full_name = self.qualified_name(n.name)
v.is_ready = False # Type not inferred yet
n.node = v
n.is_def = True
n.kind = GDEF
n.full_name = v._full_name
self.globals[n.name] = SymbolTableNode(GDEF, v, self.cur_mod_id)
elif isinstance(n.node, Var) and n.is_def:
v = n.node
self.module_names[v.name()] = SymbolTableNode(GDEF, v, self.cur_mod_id)
elif self.locals and n.name not in self.locals[-1] and n.name not in self.global_decls[-1]:
# Define new local name.
v = Var(n.name)
n.node = v
n.is_def = True
n.kind = LDEF
self.add_local(v, n)
elif not self.locals and (self.type and n.name not in self.type.vars):
# Define a new attribute.
v = Var(n.name)
v.info = self.type
v.is_initialized_in_class = True
n.node = v
n.is_def = True
self.type.vars[n.name] = v
else:
# Bind to an existing name.
lval.accept(self)
elif isinstance(lval, MemberExpr):
if not add_defs:
self.analyse_member_lvalue(lval)
elif isinstance(lval, IndexExpr):
if not add_defs:
lval.accept(self)
elif isinstance(lval, ParenExpr):
self.analyse_lvalue((lval).expr, nested, add_defs)
elif (isinstance(lval, TupleExpr) or isinstance(lval, ListExpr)) and not nested:
items = (lval).items
for i in items:
self.analyse_lvalue(i, True, add_defs)
else:
self.fail("Invalid assignment target", lval)
示例3: visit_var
# 需要导入模块: from mypy.nodes import Var [as 别名]
# 或者: from mypy.nodes.Var import is_initialized_in_class [as 别名]
def visit_var(self, node: Var) -> Var:
# Note that a Var must be transformed to a Var.
if node in self.var_map:
return self.var_map[node]
new = Var(node.name(), self.optional_type(node.type))
new.line = node.line
new._fullname = node._fullname
new.info = node.info
new.is_self = node.is_self
new.is_ready = node.is_ready
new.is_initialized_in_class = node.is_initialized_in_class
new.is_staticmethod = node.is_staticmethod
new.is_property = node.is_property
new.set_line(node.line)
self.var_map[node] = new
return new