当前位置: 首页>>代码示例>>Python>>正文


Python Instance.args方法代码示例

本文整理汇总了Python中mypy.types.Instance.args方法的典型用法代码示例。如果您正苦于以下问题:Python Instance.args方法的具体用法?Python Instance.args怎么用?Python Instance.args使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mypy.types.Instance的用法示例。


在下文中一共展示了Instance.args方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: visit_instance

# 需要导入模块: from mypy.types import Instance [as 别名]
# 或者: from mypy.types.Instance import args [as 别名]
 def visit_instance(self, t: Instance) -> None:
     info = t.type
     if info.replaced or info.tuple_type:
         self.indicator['synthetic'] = True
     # Check type argument count.
     if len(t.args) != len(info.type_vars):
         if len(t.args) == 0:
             from_builtins = t.type.fullname() in nongen_builtins and not t.from_generic_builtin
             if (self.options.disallow_any_generics and
                     not self.is_typeshed_stub and
                     from_builtins):
                 alternative = nongen_builtins[t.type.fullname()]
                 self.fail(messages.IMPLICIT_GENERIC_ANY_BUILTIN.format(alternative), t)
             # Insert implicit 'Any' type arguments.
             if from_builtins:
                 # this 'Any' was already reported elsewhere
                 any_type = AnyType(TypeOfAny.special_form,
                                    line=t.line, column=t.column)
             else:
                 any_type = AnyType(TypeOfAny.from_omitted_generics,
                                    line=t.line, column=t.column)
             t.args = [any_type] * len(info.type_vars)
             return
         # Invalid number of type parameters.
         n = len(info.type_vars)
         s = '{} type arguments'.format(n)
         if n == 0:
             s = 'no type arguments'
         elif n == 1:
             s = '1 type argument'
         act = str(len(t.args))
         if act == '0':
             act = 'none'
         self.fail('"{}" expects {}, but {} given'.format(
             info.name(), s, act), t)
         # Construct the correct number of type arguments, as
         # otherwise the type checker may crash as it expects
         # things to be right.
         t.args = [AnyType(TypeOfAny.from_error) for _ in info.type_vars]
         t.invalid = True
     elif info.defn.type_vars:
         # Check type argument values. This is postponed to the end of semantic analysis
         # since we need full MROs and resolved forward references.
         for tvar in info.defn.type_vars:
             if (tvar.values
                     or not isinstance(tvar.upper_bound, Instance)
                     or tvar.upper_bound.type.fullname() != 'builtins.object'):
                 # Some restrictions on type variable. These can only be checked later
                 # after we have final MROs and forward references have been resolved.
                 self.indicator['typevar'] = True
     for arg in t.args:
         arg.accept(self)
     if info.is_newtype:
         for base in info.bases:
             base.accept(self)
开发者ID:sixolet,项目名称:mypy,代码行数:57,代码来源:typeanal.py

示例2: visit_instance

# 需要导入模块: from mypy.types import Instance [as 别名]
# 或者: from mypy.types.Instance import args [as 别名]
 def visit_instance(self, t: Instance) -> None:
     info = t.type
     # Check type argument count.
     if len(t.args) != len(info.type_vars):
         if len(t.args) == 0:
             # Insert implicit 'Any' type arguments.
             t.args = [AnyType()] * len(info.type_vars)
             return
         # Invalid number of type parameters.
         n = len(info.type_vars)
         s = "{} type arguments".format(n)
         if n == 0:
             s = "no type arguments"
         elif n == 1:
             s = "1 type argument"
         act = str(len(t.args))
         if act == "0":
             act = "none"
         self.fail('"{}" expects {}, but {} given'.format(info.name(), s, act), t)
         # Construct the correct number of type arguments, as
         # otherwise the type checker may crash as it expects
         # things to be right.
         t.args = [AnyType() for _ in info.type_vars]
     elif info.defn.type_vars:
         # Check type argument values.
         for arg, TypeVar in zip(t.args, info.defn.type_vars):
             if TypeVar.values:
                 if isinstance(arg, TypeVarType):
                     arg_values = arg.values
                     if not arg_values:
                         self.fail(
                             'Type variable "{}" not valid as type '
                             'argument value for "{}"'.format(arg.name, info.name()),
                             t,
                         )
                         continue
                 else:
                     arg_values = [arg]
                 self.check_type_var_values(info, arg_values, TypeVar.values, t)
             if not satisfies_upper_bound(arg, TypeVar.upper_bound):
                 self.fail(
                     'Type argument "{}" of "{}" must be '
                     'a subtype of "{}"'.format(arg, info.name(), TypeVar.upper_bound),
                     t,
                 )
     for arg in t.args:
         arg.accept(self)
开发者ID:matthiaskramm,项目名称:mypy,代码行数:49,代码来源:typeanal.py

示例3: visit_instance

# 需要导入模块: from mypy.types import Instance [as 别名]
# 或者: from mypy.types.Instance import args [as 别名]
 def visit_instance(self, t: Instance) -> None:
     info = t.type
     if len(t.args) != len(info.type_vars):
         if len(t.args) == 0:
             # Implicit 'Any' type arguments.
             # TODO remove <Type> below
             t.args = [AnyType()] * len(info.type_vars)
             return
         # Invalid number of type parameters.
         n = len(info.type_vars)
         s = '{} type arguments'.format(n)
         if n == 0:
             s = 'no type arguments'
         elif n == 1:
             s = '1 type argument'
         act = str(len(t.args))
         if act == '0':
             act = 'none'
         self.fail('"{}" expects {}, but {} given'.format(
             info.name(), s, act), t)
     for arg in t.args:
         arg.accept(self)
开发者ID:bogdan-kulynych,项目名称:mypy,代码行数:24,代码来源:typeanal.py

示例4: visit_instance

# 需要导入模块: from mypy.types import Instance [as 别名]
# 或者: from mypy.types.Instance import args [as 别名]
 def visit_instance(self, t: Instance) -> None:
     info = t.type
     # Check type argument count.
     if len(t.args) != len(info.type_vars):
         if len(t.args) == 0:
             # Insert implicit 'Any' type arguments.
             t.args = [AnyType()] * len(info.type_vars)
             return
         # Invalid number of type parameters.
         n = len(info.type_vars)
         s = '{} type arguments'.format(n)
         if n == 0:
             s = 'no type arguments'
         elif n == 1:
             s = '1 type argument'
         act = str(len(t.args))
         if act == '0':
             act = 'none'
         self.fail('"{}" expects {}, but {} given'.format(
             info.name(), s, act), t)
     elif info.defn.type_vars:
         # Check type argument values.
         for arg, TypeVar in zip(t.args, info.defn.type_vars):
             if TypeVar.values:
                 if isinstance(arg, TypeVarType):
                     arg_values = arg.values
                     if not arg_values:
                         self.fail('Type variable "{}" not valid as type '
                                   'argument value for "{}"'.format(
                                       arg.name, info.name()), t)
                         continue
                 else:
                     arg_values = [arg]
                 self.check_type_var_values(info, arg_values,
                                            TypeVar.values, t)
     for arg in t.args:
         arg.accept(self)
开发者ID:o11c,项目名称:mypy,代码行数:39,代码来源:typeanal.py

示例5: visit_instance

# 需要导入模块: from mypy.types import Instance [as 别名]
# 或者: from mypy.types.Instance import args [as 别名]
 def visit_instance(self, t: Instance) -> None:
     info = t.type
     if info.replaced or info.tuple_type:
         self.indicator['synthetic'] = True
     # Check type argument count.
     if len(t.args) != len(info.type_vars):
         if len(t.args) == 0:
             from_builtins = t.type.fullname() in nongen_builtins and not t.from_generic_builtin
             if (self.options.disallow_any_generics and
                     not self.is_typeshed_stub and
                     from_builtins):
                 alternative = nongen_builtins[t.type.fullname()]
                 self.fail(messages.IMPLICIT_GENERIC_ANY_BUILTIN.format(alternative), t)
             # Insert implicit 'Any' type arguments.
             if from_builtins:
                 # this 'Any' was already reported elsewhere
                 any_type = AnyType(TypeOfAny.special_form,
                                    line=t.line, column=t.column)
             else:
                 any_type = AnyType(TypeOfAny.from_omitted_generics,
                                    line=t.line, column=t.column)
             t.args = [any_type] * len(info.type_vars)
             return
         # Invalid number of type parameters.
         n = len(info.type_vars)
         s = '{} type arguments'.format(n)
         if n == 0:
             s = 'no type arguments'
         elif n == 1:
             s = '1 type argument'
         act = str(len(t.args))
         if act == '0':
             act = 'none'
         self.fail('"{}" expects {}, but {} given'.format(
             info.name(), s, act), t)
         # Construct the correct number of type arguments, as
         # otherwise the type checker may crash as it expects
         # things to be right.
         t.args = [AnyType(TypeOfAny.from_error) for _ in info.type_vars]
         t.invalid = True
     elif info.defn.type_vars:
         # Check type argument values.
         # TODO: Calling is_subtype and is_same_types in semantic analysis is a bad idea
         for (i, arg), tvar in zip(enumerate(t.args), info.defn.type_vars):
             if tvar.values:
                 if isinstance(arg, TypeVarType):
                     arg_values = arg.values
                     if not arg_values:
                         self.fail('Type variable "{}" not valid as type '
                                   'argument value for "{}"'.format(
                                       arg.name, info.name()), t)
                         continue
                 else:
                     arg_values = [arg]
                 self.check_type_var_values(info, arg_values, tvar.name, tvar.values, i + 1, t)
             # TODO: These hacks will be not necessary when this will be moved to later stage.
             arg = self.resolve_type(arg)
             bound = self.resolve_type(tvar.upper_bound)
             if not is_subtype(arg, bound):
                 self.fail('Type argument "{}" of "{}" must be '
                           'a subtype of "{}"'.format(
                               arg, info.name(), bound), t)
     for arg in t.args:
         arg.accept(self)
     if info.is_newtype:
         for base in info.bases:
             base.accept(self)
开发者ID:greatmazinger,项目名称:mypy,代码行数:69,代码来源:typeanal.py


注:本文中的mypy.types.Instance.args方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。