本文整理汇总了Python中mypy.nodes.Var.is_classmethod方法的典型用法代码示例。如果您正苦于以下问题:Python Var.is_classmethod方法的具体用法?Python Var.is_classmethod怎么用?Python Var.is_classmethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mypy.nodes.Var
的用法示例。
在下文中一共展示了Var.is_classmethod方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_method
# 需要导入模块: from mypy.nodes import Var [as 别名]
# 或者: from mypy.nodes.Var import is_classmethod [as 别名]
def add_method(funcname: str,
ret: Type,
args: List[Argument],
name: Optional[str] = None,
is_classmethod: bool = False,
is_new: bool = False,
) -> None:
if is_classmethod or is_new:
first = [Argument(Var('cls'), TypeType.make_normalized(selftype), None, ARG_POS)]
else:
first = [Argument(Var('self'), selftype, None, ARG_POS)]
args = first + args
types = [arg.type_annotation for arg in args]
items = [arg.variable.name() for arg in args]
arg_kinds = [arg.kind for arg in args]
assert None not in types
signature = CallableType(cast(List[Type], types), arg_kinds, items, ret,
function_type)
signature.variables = [tvd]
func = FuncDef(funcname, args, Block([]))
func.info = info
func.is_class = is_classmethod
func.type = set_callable_name(signature, func)
func._fullname = info.fullname() + '.' + funcname
if is_classmethod:
v = Var(funcname, func.type)
v.is_classmethod = True
v.info = info
v._fullname = func._fullname
dec = Decorator(func, [NameExpr('classmethod')], v)
info.names[funcname] = SymbolTableNode(MDEF, dec)
else:
info.names[funcname] = SymbolTableNode(MDEF, func)
示例2: visit_var
# 需要导入模块: from mypy.nodes import Var [as 别名]
# 或者: from mypy.nodes.Var import is_classmethod [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_classmethod = node.is_classmethod
new.is_property = node.is_property
new.set_line(node.line)
self.var_map[node] = new
return new