本文整理汇总了Python中mypy.nodes.TypeInfo.get方法的典型用法代码示例。如果您正苦于以下问题:Python TypeInfo.get方法的具体用法?Python TypeInfo.get怎么用?Python TypeInfo.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mypy.nodes.TypeInfo
的用法示例。
在下文中一共展示了TypeInfo.get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: lookup_member_var_or_accessor
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import get [as 别名]
def lookup_member_var_or_accessor(info: TypeInfo, name: str, is_lvalue: bool) -> SymbolNode:
"""Find the attribute/accessor node that refers to a member of a type."""
# TODO handle lvalues
node = info.get(name)
if node:
return node.node
else:
return None
示例2: get_member_flags
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import get [as 别名]
def get_member_flags(name: str, info: TypeInfo) -> Set[int]:
"""Detect whether a member 'name' is settable, whether it is an
instance or class variable, and whether it is class or static method.
The flags are defined as following:
* IS_SETTABLE: whether this attribute can be set, not set for methods and
non-settable properties;
* IS_CLASSVAR: set if the variable is annotated as 'x: ClassVar[t]';
* IS_CLASS_OR_STATIC: set for methods decorated with @classmethod or
with @staticmethod.
"""
method = info.get_method(name)
setattr_meth = info.get_method('__setattr__')
if method:
# this could be settable property
if method.is_property:
assert isinstance(method, OverloadedFuncDef)
dec = method.items[0]
assert isinstance(dec, Decorator)
if dec.var.is_settable_property or setattr_meth:
return {IS_SETTABLE}
return set()
node = info.get(name)
if not node:
if setattr_meth:
return {IS_SETTABLE}
return set()
v = node.node
if isinstance(v, Decorator):
if v.var.is_staticmethod or v.var.is_classmethod:
return {IS_CLASS_OR_STATIC}
# just a variable
if isinstance(v, Var):
flags = {IS_SETTABLE}
if v.is_classvar:
flags.add(IS_CLASSVAR)
return flags
return set()