本文整理汇总了Python中mypy.nodes.TypeInfo.name方法的典型用法代码示例。如果您正苦于以下问题:Python TypeInfo.name方法的具体用法?Python TypeInfo.name怎么用?Python TypeInfo.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mypy.nodes.TypeInfo
的用法示例。
在下文中一共展示了TypeInfo.name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: base_class_definitions_incompatible
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import name [as 别名]
def base_class_definitions_incompatible(
self, name: str, base1: TypeInfo, base2: TypeInfo, context: Context
) -> None:
self.fail(
'Definition of "{}" in base class "{}" is incompatible '
'with definition in base class "{}"'.format(name, base1.name(), base2.name()),
context,
)
示例2: check_type_var_values
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import name [as 别名]
def check_type_var_values(self, type: TypeInfo, actuals: List[Type],
valids: List[Type], arg_number: int, context: Context) -> None:
for actual in actuals:
if (not isinstance(actual, AnyType) and
not any(is_same_type(actual, value) for value in valids)):
if len(actuals) > 1 or not isinstance(actual, Instance):
self.fail('Invalid type argument value for "{}"'.format(
type.name()), context)
else:
self.fail('Type argument {} of "{}" has incompatible value "{}"'.format(
arg_number, type.name(), actual.type.name()), context)
示例3: check_type_var_values
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import name [as 别名]
def check_type_var_values(self, type: TypeInfo, actuals: List[Type], arg_name: str,
valids: List[Type], arg_number: int, context: Context) -> None:
for actual in actuals:
if (not isinstance(actual, AnyType) and
not any(is_same_type(actual, value)
for value in valids)):
if len(actuals) > 1 or not isinstance(actual, Instance):
self.fail('Invalid type argument value for "{}"'.format(
type.name()), context)
else:
class_name = '"{}"'.format(type.name())
actual_type_name = '"{}"'.format(actual.type.name())
self.fail(messages.INCOMPATIBLE_TYPEVAR_VALUE.format(
arg_name, class_name, actual_type_name), context)
示例4: nearest_builtin_ancestor
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import name [as 别名]
def nearest_builtin_ancestor(type: TypeInfo) -> TypeInfo:
for base in type.mro:
if base.defn.is_builtinclass:
return base
else:
return None
assert False, 'No built-in ancestor found for {}'.format(type.name())
示例5: check_type_var_values
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import name [as 别名]
def check_type_var_values(self, type: TypeInfo, actuals: List[Type],
valids: List[Type], context: Context) -> None:
for actual in actuals:
if (not isinstance(actual, AnyType) and
not any(is_same_type(actual, value) for value in valids)):
self.fail('Invalid type argument value for "{}"'.format(
type.name()), context)
示例6: type_suffix
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import name [as 别名]
def type_suffix(self, fdef: FuncDef, info: TypeInfo = None) -> str:
"""Return the suffix for a mangled name.
This includes an optional type suffix for a function or method.
"""
if not info:
info = fdef.info
# If info is None, we have a global function => no suffix. Also if the
# method is not an override, we need no suffix.
if not info or (not info.bases or not info.bases[0].type.has_method(fdef.name())):
return ""
elif is_simple_override(fdef, info):
return self.type_suffix(fdef, info.bases[0].type)
elif self.is_pretty:
return "`" + info.name()
else:
return "__" + info.name()
示例7: enter_class_scope
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import name [as 别名]
def enter_class_scope(self, info: TypeInfo) -> str:
"""Enter a class target scope."""
# Duplicate the previous top non-class target (it can't be a class but since the
# depths of all stacks must agree we need something).
self.target_stack.append(self.target_stack[-1])
full_target = '%s.%s' % (self.full_target_stack[-1], info.name())
self.full_target_stack.append(full_target)
self.scope_stack.append(info)
return full_target
示例8: class_callable
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import name [as 别名]
def class_callable(init_type: CallableType, info: TypeInfo, type_type: Instance,
special_sig: Optional[str]) -> CallableType:
"""Create a type object type based on the signature of __init__."""
variables = [] # type: List[TypeVarDef]
variables.extend(info.defn.type_vars)
variables.extend(init_type.variables)
callable_type = init_type.copy_modified(
ret_type=fill_typevars(info), fallback=type_type, name=None, variables=variables,
special_sig=special_sig)
c = callable_type.with_name(info.name())
return c
示例9: class_callable
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import name [as 别名]
def class_callable(init_type: CallableType, info: TypeInfo, type_type: Instance) -> CallableType:
"""Create a type object type based on the signature of __init__."""
variables = [] # type: List[TypeVarDef]
for i, tvar in enumerate(info.defn.type_vars):
variables.append(TypeVarDef(tvar.name, i + 1, tvar.values, tvar.upper_bound, tvar.variance))
initvars = init_type.variables
variables.extend(initvars)
c = CallableType(
init_type.arg_types, init_type.arg_kinds, init_type.arg_names, self_type(info), type_type, None, variables
).with_name('"{}"'.format(info.name()))
return convert_class_tvars_to_func_tvars(c, len(initvars))
示例10: class_callable
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import name [as 别名]
def class_callable(init_type: CallableType, info: TypeInfo, type_type: Instance) -> CallableType:
"""Create a type object type based on the signature of __init__."""
variables = [] # type: List[TypeVarDef]
for i, tvar in enumerate(info.defn.type_vars):
variables.append(TypeVarDef(tvar.name, i + 1, tvar.values, tvar.upper_bound,
tvar.variance))
initvars = init_type.variables
variables.extend(initvars)
callable_type = init_type.copy_modified(
ret_type=self_type(info), fallback=type_type, name=None, variables=variables)
c = callable_type.with_name('"{}"'.format(info.name()))
cc = convert_class_tvars_to_func_tvars(c, len(initvars))
cc.is_classmethod_class = True
return cc
示例11: __init__
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import name [as 别名]
def __init__(self, type: TypeInfo, base: 'ClassRepresentation') -> None:
self.cname = 'MR_%s' % type.name()
self.fullname = type.fullname()
self.slotmap = {}
self.vtable_index = {}
self.defining_class = {}
self.vtable_methods = []
if base:
self.inherit_from_base(base)
for m in sorted(type.names):
if isinstance(type.names[m].node, FuncBase):
self.add_method(m, type)
else:
self.slotmap[m] = len(self.slotmap)
self.add_method('_' + m, type) # Getter TODO refactor
self.add_method('set_' + m, type) # Setter # TODO refactor
示例12: class_callable
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import name [as 别名]
def class_callable(init_type: Callable, info: TypeInfo) -> Callable:
"""Create a type object type based on the signature of __init__."""
variables = [] # type: List[TypeVarDef]
for i in range(len(info.type_vars)): # TODO bounds
variables.append(TypeVarDef(info.type_vars[i], i + 1, None))
initvars = init_type.variables
variables.extend(initvars)
c = Callable(init_type.arg_types,
init_type.arg_kinds,
init_type.arg_names,
self_type(info),
True,
None,
variables).with_name('"{}"'.format(info.name()))
return convert_class_tvars_to_func_tvars(c, len(initvars))
示例13: generate_class
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import name [as 别名]
def generate_class(self, cls: TypeInfo) -> 'ClassRepresentation':
if cls.bases:
baserep = self.get_class_representation(cls.bases[0].type)
else:
baserep = None
rep = ClassRepresentation(cls, baserep)
self.classes[cls] = rep
# Emit vtable.
vtable = 'MVT_%s' % cls.name()
self.emit_types('MFunction %s[] = {' % vtable)
for m in rep.vtable_methods:
defining_class = rep.defining_class[m]
self.emit_types(' M%s_%s,' % (defining_class, m))
self.emit_types('}; /* %s */' % vtable)
# Emit type runtime info.
self.emit_types('MTypeRepr %s = {' % rep.cname)
self.emit_types(' %s,' % vtable)
self.emit_types(' 0,')
self.emit_types(' "%s"' % cls.fullname())
self.emit_types('};\n')
return rep
示例14: read_only_property
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import name [as 别名]
def read_only_property(self, name: str, type: TypeInfo,
context: Context) -> None:
self.fail('Property "{}" defined in "{}" is read-only'.format(
name, type.name()), context)
示例15: disjointness_violation
# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import name [as 别名]
def disjointness_violation(self, cls: TypeInfo, disjoint: TypeInfo,
context: Context) -> None:
self.fail('disjointclass constraint of class {} disallows {} as a '
'base class'.format(cls.name(), disjoint.name()), context)