• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python util.short_type函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mypy.util.short_type函数的典型用法代码示例。如果您正苦于以下问题:Python short_type函数的具体用法?Python short_type怎么用?Python short_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: run_test

 def run_test(self, testcase):
     a = []
     try:
         line = testcase.input[0]
         mask = ''
         if line.startswith('##'):
             mask = '(' + line[2:].strip() + ')$'
         
         src = '\n'.join(testcase.input)
         result = build.build(program_path='main',
                              target=build.TYPE_CHECK,
                              program_text=src,
                              flags=[build.TEST_BUILTINS],
                              alt_lib_path=testconfig.test_temp_dir)
         map = result.types
         kk = map.keys()
         keys = []
         for k in kk:
             if k.line is not None and k.line != -1 and map[k]:
                 if (re.match(mask, short_type(k))
                         or (isinstance(k, NameExpr)
                             and re.match(mask, k.name))):
                     keys.append(k)
         for key in sorted(keys,
                           key=lambda n: (n.line, short_type(n),
                                          str(n) + str(map[n]))):
             ts = str(map[key]).replace('*', '') # Remove erased tags
             ts = ts.replace('__main__.', '')
             a.append('{}({}) : {}'.format(short_type(key), key.line, ts))
     except CompileError as e:
         a = e.messages
     assert_string_arrays_equal(
         testcase.output, a,
         'Invalid type checker output ({}, line {})'.format(testcase.file,
                                                            testcase.line))
开发者ID:SRiikonen,项目名称:mypy,代码行数:35,代码来源:testtypegen.py


示例2: run_case

    def run_case(self, testcase: DataDrivenTestCase) -> None:
        try:
            line = testcase.input[0]
            mask = ''
            if line.startswith('##'):
                mask = '(' + line[2:].strip() + ')$'

            src = '\n'.join(testcase.input)
            options = Options()
            options.strict_optional = False  # TODO: Enable strict optional checking
            options.use_builtins_fixtures = True
            options.show_traceback = True
            options.export_types = True
            result = build.build(sources=[BuildSource('main', None, src)],
                                 options=options,
                                 alt_lib_path=test_temp_dir)
            a = result.errors
            map = result.types
            nodes = map.keys()

            # Ignore NameExpr nodes of variables with explicit (trivial) types
            # to simplify output.
            searcher = SkippedNodeSearcher()
            for file in result.files.values():
                file.accept(searcher)
            ignored = searcher.nodes

            # Filter nodes that should be included in the output.
            keys = []
            for node in nodes:
                if node.line is not None and node.line != -1 and map[node]:
                    if ignore_node(node) or node in ignored:
                        continue
                    if (re.match(mask, short_type(node))
                            or (isinstance(node, NameExpr)
                                and re.match(mask, node.name))):
                        # Include node in output.
                        keys.append(node)

            for key in sorted(keys,
                              key=lambda n: (n.line, short_type(n),
                                             str(n) + str(map[n]))):
                ts = str(map[key]).replace('*', '')  # Remove erased tags
                ts = ts.replace('__main__.', '')
                a.append('{}({}) : {}'.format(short_type(key), key.line, ts))
        except CompileError as e:
            a = e.messages
        assert_string_arrays_equal(
            testcase.output, a,
            'Invalid type checker output ({}, line {})'.format(testcase.file,
                                                               testcase.line))
开发者ID:Michael0x2a,项目名称:mypy,代码行数:51,代码来源:testtypegen.py


示例3: run_test

    def run_test(self, testcase):
        implementation = testcase_python_implementation(testcase)

        a = []
        try:
            line = testcase.input[0]
            mask = ''
            if line.startswith('##'):
                mask = '(' + line[2:].strip() + ')$'

            src = '\n'.join(testcase.input)
            result = build.build(target=build.TYPE_CHECK,
                                 sources=[BuildSource('main', None, src)],
                                 implementation=implementation,
                                 flags=[build.TEST_BUILTINS],
                                 alt_lib_path=config.test_temp_dir)
            map = result.types
            nodes = map.keys()

            # Ignore NameExpr nodes of variables with explicit (trivial) types
            # to simplify output.
            searcher = VariableDefinitionNodeSearcher()
            for file in result.files.values():
                file.accept(searcher)
            ignored = searcher.nodes

            # Filter nodes that should be included in the output.
            keys = []
            for node in nodes:
                if node.line is not None and node.line != -1 and map[node]:
                    if ignore_node(node) or node in ignored:
                        continue
                    if (re.match(mask, short_type(node))
                            or (isinstance(node, NameExpr)
                                and re.match(mask, node.name))):
                        # Include node in output.
                        keys.append(node)

            for key in sorted(keys,
                              key=lambda n: (n.line, short_type(n),
                                             str(n) + str(map[n]))):
                ts = str(map[key]).replace('*', '')  # Remove erased tags
                ts = ts.replace('__main__.', '')
                a.append('{}({}) : {}'.format(short_type(key), key.line, ts))
        except CompileError as e:
            a = e.messages
        assert_string_arrays_equal(
            testcase.output, a,
            'Invalid type checker output ({}, line {})'.format(testcase.file,
                                                               testcase.line))
开发者ID:o11c,项目名称:mypy,代码行数:50,代码来源:testtypegen.py


示例4: dump

 def dump(self, nodes, obj):
     """Convert an array of items to a multiline pretty-printed
     string. The tag is produced from the type name of obj and its
     line number. See util::DumpTagged for a description of the
     nodes argument.
     """
     return dump_tagged(nodes, short_type(obj) + ':' + str(obj.line))
开发者ID:SRiikonen,项目名称:mypy,代码行数:7,代码来源:strconv.py


示例5: visit_name_expr

 def visit_name_expr(self, o: 'mypy.nodes.NameExpr') -> str:
     pretty = self.pretty_name(o.name, o.kind, o.fullname,
                               o.is_inferred_def or o.is_special_form,
                               o.node)
     if isinstance(o.node, mypy.nodes.Var) and o.node.is_final:
         pretty += ' = {}'.format(o.node.final_value)
     return short_type(o) + '(' + pretty + ')'
开发者ID:Michael0x2a,项目名称:mypy,代码行数:7,代码来源:strconv.py


示例6: __str__

 def __str__(self):
     s = '{}/{}'.format(node_kinds[self.kind], short_type(self.node))
     if self.mod_id is not None:
         s += ' ({})'.format(self.mod_id)
     # Include declared type of variables and functions.
     if self.type() is not None:
         s += ' : {}'.format(self.type())
     return s
开发者ID:SRiikonen,项目名称:mypy-py,代码行数:8,代码来源:nodes.py


示例7: dump

    def dump(self, nodes: Sequence[object], obj: 'mypy.nodes.Context') -> str:
        """Convert a list of items to a multiline pretty-printed string.

        The tag is produced from the type name of obj and its line
        number. See mypy.util.dump_tagged for a description of the nodes
        argument.
        """
        return dump_tagged(nodes, short_type(obj) + ':' + str(obj.get_line()))
开发者ID:rra,项目名称:mypy,代码行数:8,代码来源:strconv.py


示例8: __str__

 def __str__(self) -> str:
     s = "{}/{}".format(node_kinds[self.kind], short_type(self.node))
     if self.mod_id is not None:
         s += " ({})".format(self.mod_id)
     # Include declared type of variables and functions.
     if self.type is not None:
         s += " : {}".format(self.type)
     return s
开发者ID:akaihola,项目名称:mypy,代码行数:8,代码来源:nodes.py


示例9: dump_types

 def dump_types(self, manager: BuildManager) -> List[str]:
     a = []
     # To make the results repeatable, we try to generate unique and
     # deterministic sort keys.
     for module_id in sorted(manager.modules):
         if not is_dumped_module(module_id):
             continue
         type_map = manager.saved_cache[module_id][2]
         if type_map:
             a.append('## {}'.format(module_id))
             for expr in sorted(type_map, key=lambda n: (n.line, short_type(n),
                                                         str(n) + str(type_map[n]))):
                 typ = type_map[expr]
                 a.append('{}:{}: {}'.format(short_type(expr),
                                             expr.line,
                                             self.format_type(typ)))
     return a
开发者ID:greatmazinger,项目名称:mypy,代码行数:17,代码来源:testmerge.py


示例10: dump

    def dump(self, nodes: Sequence[object], obj: 'mypy.nodes.Context') -> str:
        """Convert a list of items to a multiline pretty-printed string.

        The tag is produced from the type name of obj and its line
        number. See mypy.util.dump_tagged for a description of the nodes
        argument.
        """
        tag = short_type(obj) + ':' + str(obj.get_line())
        if self.show_ids:
            assert self.id_mapper is not None
            tag += '<{}>'.format(self.get_id(obj))
        return dump_tagged(nodes, tag, self)
开发者ID:mananpal1997,项目名称:mypy,代码行数:12,代码来源:strconv.py


示例11: visit_name_expr

 def visit_name_expr(self, o: 'mypy.nodes.NameExpr') -> str:
     return (short_type(o) + '(' + self.pretty_name(o.name, o.kind,
                                                    o.fullname, o.is_def)
             + ')')
开发者ID:rra,项目名称:mypy,代码行数:4,代码来源:strconv.py


示例12: type

        else:
            return None
    
    mypy.types.Type type(self):
        # IDEA: Get rid of the any type.
        any node = self.node
        if self.type_override is not None:
            return self.type_override
        elif ((isinstance(node, Var) or isinstance(node, FuncDef))
              and node.type is not None):
            return node.type
        else:
            return None
    
    str __str__(self):
        s = '{}/{}'.format(node_kinds[self.kind], short_type(self.node))
        if self.mod_id is not None:
            s += ' ({})'.format(self.mod_id)
        # Include declared type of variables and functions.
        if self.type() is not None:
            s += ' : {}'.format(self.type())
        return s


str clean_up(str s):
    return re.sub('.*::', '', s)
        

mypy.types.FunctionLike function_type(FuncBase func):
    if func.type:
        return (mypy.types.FunctionLike)func.type
开发者ID:Varriount,项目名称:mypy,代码行数:31,代码来源:nodes.py


示例13: __init__

from mypy.util import short_type


class Token:
    """Base class for all tokens"""
    str pre = '' # Space, comments etc. before token
    str string   # Token string
    int line     # Token line number
    
    void __init__(self, str string, str pre=''):
        self.string = string
        self.pre = pre
    
    str __repr__(self):
        """The representation is of form Keyword('  if')."""
        t = short_type(self)
        return t + '(' + self.fix(self.pre) + self.fix(self.string) + ')'
    
    str rep(self):
        return self.pre + self.string
    
    str fix(self, str s):
        """Replace common non-printable chars with escape sequences.

        Do not use repr() since we don't want do duplicate backslashes.
        """
        return s.replace('\n', '\\n').replace('\t', '\\t').replace('\r', '\\r')


# Token classes
开发者ID:Varriount,项目名称:mypy,代码行数:30,代码来源:lex.py


示例14: visit_name_expr

 def visit_name_expr(self, o):
     return short_type(o) + "(" + self.pretty_name(o.name, o.kind, o.fullname, o.is_def) + ")"
开发者ID:ashleyh,项目名称:mypy,代码行数:2,代码来源:strconv.py


示例15: visit_name_expr

 def visit_name_expr(self, o: 'mypy.nodes.NameExpr') -> str:
     pretty = self.pretty_name(o.name, o.kind, o.fullname, o.is_inferred_def, o.node)
     return short_type(o) + '(' + pretty + ')'
开发者ID:greatmazinger,项目名称:mypy,代码行数:3,代码来源:strconv.py


示例16: __repr__

 def __repr__(self) -> str:
     """The representation is of form 'Keyword(  if)'."""
     t = short_type(self)
     return t + '(' + self.fix(self.pre) + self.fix(self.string) + ')'
开发者ID:bogdan-kulynych,项目名称:mypy,代码行数:4,代码来源:lex.py


示例17: visit_name_expr

 def visit_name_expr(self, o):
     return (short_type(o) + '(' + self.pretty_name(o.name, o.kind,
                                                    o.fullname, o.is_def)
             + ')')
开发者ID:mvcisback,项目名称:mypy,代码行数:4,代码来源:strconv.py


示例18: __repr__

 def __repr__(self):
     """The representation is of form Keyword('  if')."""
     t = short_type(self)
     return t + '(' + self.fix(self.pre) + self.fix(self.string) + ')'
开发者ID:SRiikonen,项目名称:mypy-py,代码行数:4,代码来源:lex.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python myquaternaryutility.QuaternaryPlot类代码示例发布时间:2022-05-27
下一篇:
Python types.UnionType类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap