本文整理汇总了Python中mypy.messages.MessageBuilder.note方法的典型用法代码示例。如果您正苦于以下问题:Python MessageBuilder.note方法的具体用法?Python MessageBuilder.note怎么用?Python MessageBuilder.note使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mypy.messages.MessageBuilder
的用法示例。
在下文中一共展示了MessageBuilder.note方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: analyze_member_access
# 需要导入模块: from mypy.messages import MessageBuilder [as 别名]
# 或者: from mypy.messages.MessageBuilder import note [as 别名]
def analyze_member_access(name: str,
typ: Type,
node: Context,
is_lvalue: bool,
is_super: bool,
is_operator: bool,
builtin_type: Callable[[str], Instance],
not_ready_callback: Callable[[str, Context], None],
msg: MessageBuilder, *,
original_type: Type,
override_info: TypeInfo = None,
chk: 'mypy.checker.TypeChecker' = None) -> Type:
"""Return the type of attribute `name` of typ.
This is a general operation that supports various different variations:
1. lvalue or non-lvalue access (i.e. setter or getter access)
2. supertype access (when using super(); is_super == True and
override_info should refer to the supertype)
original_type is the most precise inferred or declared type of the base object
that we have available. typ is generally a supertype of original_type.
When looking for an attribute of typ, we may perform recursive calls targeting
the fallback type, for example.
original_type is always the type used in the initial call.
"""
if isinstance(typ, Instance):
if name == '__init__' and not is_super:
# Accessing __init__ in statically typed code would compromise
# type safety unless used via super().
msg.fail(messages.CANNOT_ACCESS_INIT, node)
return AnyType()
# The base object has an instance type.
info = typ.type
if override_info:
info = override_info
if (experiments.find_occurrences and
info.name() == experiments.find_occurrences[0] and
name == experiments.find_occurrences[1]):
msg.note("Occurrence of '{}.{}'".format(*experiments.find_occurrences), node)
# Look up the member. First look up the method dictionary.
method = info.get_method(name)
if method:
if method.is_property:
assert isinstance(method, OverloadedFuncDef)
return analyze_var(name, method.items[0].var, typ, info, node, is_lvalue, msg,
original_type, not_ready_callback)
if is_lvalue:
msg.cant_assign_to_method(node)
signature = function_type(method, builtin_type('builtins.function'))
if name == '__new__':
# __new__ is special and behaves like a static method -- don't strip
# the first argument.
pass
else:
signature = bind_self(signature, original_type)
typ = map_instance_to_supertype(typ, method.info)
return expand_type_by_instance(signature, typ)
else:
# Not a method.
return analyze_member_var_access(name, typ, info, node,
is_lvalue, is_super, builtin_type,
not_ready_callback, msg,
original_type=original_type, chk=chk)
elif isinstance(typ, AnyType):
# The base object has dynamic type.
return AnyType()
elif isinstance(typ, NoneTyp):
if chk and chk.should_suppress_optional_error([typ]):
return AnyType()
# The only attribute NoneType has are those it inherits from object
return analyze_member_access(name, builtin_type('builtins.object'), node, is_lvalue,
is_super, is_operator, builtin_type, not_ready_callback, msg,
original_type=original_type, chk=chk)
elif isinstance(typ, UnionType):
# The base object has dynamic type.
msg.disable_type_names += 1
results = [analyze_member_access(name, subtype, node, is_lvalue, is_super,
is_operator, builtin_type, not_ready_callback, msg,
original_type=original_type, chk=chk)
for subtype in typ.items]
msg.disable_type_names -= 1
return UnionType.make_simplified_union(results)
elif isinstance(typ, TupleType):
# Actually look up from the fallback instance type.
return analyze_member_access(name, typ.fallback, node, is_lvalue, is_super,
is_operator, builtin_type, not_ready_callback, msg,
original_type=original_type, chk=chk)
elif isinstance(typ, TypedDictType):
# Actually look up from the fallback instance type.
return analyze_member_access(name, typ.fallback, node, is_lvalue, is_super,
is_operator, builtin_type, not_ready_callback, msg,
original_type=original_type, chk=chk)
elif isinstance(typ, FunctionLike) and typ.is_type_obj():
# Class attribute.
# TODO super?
#.........这里部分代码省略.........