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

Python parse.parse函数代码示例

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

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



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

示例1: test_parse_error

def test_parse_error(testcase):
    try:
        # Compile temporary file.
        parse(bytes("\n".join(testcase.input), "ascii"), INPUT_FILE_NAME)
        raise AssertionFailure("No errors reported")
    except CompileError as e:
        # Verify that there was a compile error and that the error messages
        # are equivalent.
        assert_string_arrays_equal(
            testcase.output, e.messages, "Invalid compiler output ({}, line {})".format(testcase.file, testcase.line)
        )
开发者ID:narusemotoki,项目名称:mypy,代码行数:11,代码来源:testparse.py


示例2: test_parse_error

def test_parse_error(testcase):
    try:
        # Compile temporary file. The test file contains non-ASCII characters.
        parse(bytes('\n'.join(testcase.input), 'utf-8'), INPUT_FILE_NAME, None, Options())
        raise AssertionFailure('No errors reported')
    except CompileError as e:
        # Verify that there was a compile error and that the error messages
        # are equivalent.
        assert_string_arrays_equal(
            testcase.output, e.messages,
            'Invalid compiler output ({}, line {})'.format(testcase.file,
                                                           testcase.line))
开发者ID:AXGKl,项目名称:Transcrypt,代码行数:12,代码来源:testparse.py


示例3: test_parse_error

def test_parse_error(testcase: DataDrivenTestCase) -> None:
    try:
        # Compile temporary file. The test file contains non-ASCII characters.
        parse(bytes('\n'.join(testcase.input), 'utf-8'), INPUT_FILE_NAME, '__main__', None,
              Options())
        raise AssertionError('No errors reported')
    except CompileError as e:
        if e.module_with_blocker is not None:
            assert e.module_with_blocker == '__main__'
        # Verify that there was a compile error and that the error messages
        # are equivalent.
        assert_string_arrays_equal(
            testcase.output, e.messages,
            'Invalid compiler output ({}, line {})'.format(testcase.file,
                                                           testcase.line))
开发者ID:python,项目名称:mypy,代码行数:15,代码来源:testparse.py


示例4: parse

    def parse(self, source_text, fnam):
        """Parse the source of a file with the given name.

        Raise CompileError if there is a parse error.
        """
        num_errs = self.errors().num_messages()
        tree = parse.parse(source_text, fnam, self.errors())
        tree._full_name = self.id
        if self.errors().num_messages() != num_errs:
            self.errors().raise_error()
        return tree
开发者ID:SRiikonen,项目名称:mypy-py,代码行数:11,代码来源:build.py


示例5: parse

    def parse(self, source_text: str, fnam: str) -> MypyFile:
        """Parse the source of a file with the given name.

        Raise CompileError if there is a parse error.
        """
        num_errs = self.errors().num_messages()
        tree = parse.parse(source_text, fnam, self.errors(),
                           pyversion=self.manager.pyversion)
        tree._fullname = self.id
        if self.errors().num_messages() != num_errs:
            self.errors().raise_error()
        return tree
开发者ID:adamhaney,项目名称:mypy,代码行数:12,代码来源:build.py


示例6: test_parser

def test_parser(testcase):
    """Perform a single parser test case. The argument contains the description
    of the test case.
    """
    try:
        n = parse('\n'.join(testcase.input))
        a = str(n).split('\n')
    except CompileError as e:
        a = e.messages
    assert_string_arrays_equal(testcase.output, a,
                               'Invalid parser output ({}, line {})'.format(
                                   testcase.file, testcase.line))
开发者ID:SRiikonen,项目名称:mypy,代码行数:12,代码来源:testparse.py


示例7: parse

    def parse(self, source_text: Union[str, bytes], fnam: str) -> MypyFile:
        """Parse the source of a file with the given name.

        Raise CompileError if there is a parse error.
        """
        num_errs = self.errors().num_messages()
        tree = parse.parse(source_text, fnam, self.errors(),
                           dialect=self.manager.dialect,
                           custom_typing_module=self.manager.custom_typing_module)
        tree._fullname = self.id
        if self.errors().num_messages() != num_errs:
            self.errors().raise_error()
        return tree
开发者ID:o11c,项目名称:mypy,代码行数:13,代码来源:build.py


示例8: parse

    def parse(self, source_text: Union[str, bytes], fnam: str) -> MypyFile:
        """Parse the source of a file with the given name.

        Raise CompileError if there is a parse error.
        """
        num_errs = self.errors().num_messages()
        tree = parse.parse(source_text, fnam, self.errors(),
                           pyversion=self.manager.pyversion,
                           custom_typing_module=self.manager.custom_typing_module,
                           fast_parser=FAST_PARSER in self.manager.flags)
        tree._fullname = self.id
        if self.errors().num_messages() != num_errs:
            self.errors().raise_error()
        return tree
开发者ID:philippmayrth,项目名称:mypy,代码行数:14,代码来源:build.py


示例9: test_output

def test_output(testcase):
    """Perform an identity source code transformation test case."""
    expected = testcase.output
    if expected == []:
        expected = testcase.input
    try:
        src = '\n'.join(testcase.input)
        # Parse and analyze the source program.
        # Parse and semantically analyze the source program.
        any trees, any symtable, any infos, any types
        
        # Test case names with a special suffix get semantically analyzed. This
        # lets us test that semantic analysis does not break source code pretty
        # printing.
        if testcase.name.endswith('_SemanticAnalyzer'):
            result = build.build('main',
                                 target=build.SEMANTIC_ANALYSIS,
                                 program_text=src,
                                 flags=[build.TEST_BUILTINS],
                                 alt_lib_path=test_temp_dir)
            files = result.files
        else:
            files = {'main': parse(src, 'main')}
        a = []
        first = True
        # Produce an output containing the pretty-printed forms (with original
        # formatting) of all the relevant source files.
        for fnam in sorted(files.keys()):
            f = files[fnam]
            # Omit the builtins and files marked for omission.
            if (not f.path.endswith(os.sep + 'builtins.py') and
                    '-skip.' not in f.path):
                # Add file name + colon for files other than the first.
                if not first:
                    a.append('{}:'.format(fix_path(remove_prefix(
                        f.path, test_temp_dir))))
                
                v = OutputVisitor()
                f.accept(v)
                s = v.output()
                if s != '':
                    a += s.split('\n')
            first = False
    except CompileError as e:
        a = e.messages
    assert_string_arrays_equal(
        expected, a, 'Invalid source code output ({}, line {})'.format(
            testcase.file, testcase.line))
开发者ID:Varriount,项目名称:mypy,代码行数:48,代码来源:testoutput.py


示例10: test_parser

def test_parser(testcase):
    """Perform a single parser test case.

    The argument contains the description of the test case.
    """

    pyversion = 3
    if testcase.file.endswith('python2.test'):
        pyversion = 2

    try:
        n = parse(bytes('\n'.join(testcase.input), 'ascii'), pyversion=pyversion)
        a = str(n).split('\n')
    except CompileError as e:
        a = e.messages
    assert_string_arrays_equal(testcase.output, a,
                               'Invalid parser output ({}, line {})'.format(
                                   testcase.file, testcase.line))
开发者ID:JamesTFarrington,项目名称:mypy,代码行数:18,代码来源:testparse.py


示例11: test_parser

def test_parser(testcase):
    """Perform a single parser test case.

    The argument contains the description of the test case.
    """

    pyversion = 3
    if testcase.file.endswith("python2.test"):
        pyversion = 2

    try:
        n = parse(bytes("\n".join(testcase.input), "ascii"), pyversion=pyversion, fnam="main")
        a = str(n).split("\n")
    except CompileError as e:
        a = e.messages
    assert_string_arrays_equal(
        testcase.output, a, "Invalid parser output ({}, line {})".format(testcase.file, testcase.line)
    )
开发者ID:narusemotoki,项目名称:mypy,代码行数:18,代码来源:testparse.py


示例12: test_parser

def test_parser(testcase):
    """Perform a single parser test case.

    The argument contains the description of the test case.
    """

    if testcase.file.endswith('python2.test'):
        dialect = Dialect('2.7.0')
    else:
        dialect = default_dialect()

    try:
        n = parse(bytes('\n'.join(testcase.input), 'ascii'), dialect=dialect, fnam='main')
        a = str(n).split('\n')
    except CompileError as e:
        a = e.messages
    assert_string_arrays_equal(testcase.output, a,
                               'Invalid parser output ({}, line {})'.format(
                                   testcase.file, testcase.line))
开发者ID:o11c,项目名称:mypy,代码行数:19,代码来源:testparse.py


示例13: test_parser

def test_parser(testcase):
    """Perform a single parser test case.

    The argument contains the description of the test case.
    """
    options = Options()

    if testcase.file.endswith('python2.test'):
        options.python_version = defaults.PYTHON2_VERSION
    else:
        options.python_version = defaults.PYTHON3_VERSION

    try:
        n = parse(bytes('\n'.join(testcase.input), 'ascii'),
                  fnam='main',
                  errors=None,
                  options=options)
        a = str(n).split('\n')
    except CompileError as e:
        a = e.messages
    assert_string_arrays_equal(testcase.output, a,
                               'Invalid parser output ({}, line {})'.format(
                                   testcase.file, testcase.line))
开发者ID:AXGKl,项目名称:Transcrypt,代码行数:23,代码来源:testparse.py


示例14: run

def run(filepath):
    with open(filepath) as rf:
        source = rf.read()

    sources, options = process_options([filepath])
    return parse(source, filepath, None, options)
开发者ID:podhmo,项目名称:individual-sandbox,代码行数:6,代码来源:01parse.py


示例15: StateInfo

        if text is not None:
            info = StateInfo(path, id, self.errors().import_context(),
                             self.manager)
            self.manager.states.append(UnprocessedFile(info, text))
            self.manager.module_files[id] = path
            return True
        else:
            return False
    
    MypyFile parse(self, str source_text, str fnam):
        """Parse the source of a file with the given name.

        Raise CompileError if there is a parse error.
        """
        num_errs = self.errors().num_messages()
        tree = parse.parse(source_text, fnam, self.errors())
        tree._full_name = self.id
        if self.errors().num_messages() != num_errs:
            self.errors().raise_error()
        return tree
    
    int state(self):
        return UNPROCESSED_STATE


class ParsedFile(State):
    MypyFile tree
    
    void __init__(self, StateInfo info, MypyFile tree):
        super().__init__(info)
        self.tree = tree
开发者ID:SRiikonen,项目名称:mypy,代码行数:31,代码来源:build.py


示例16: print_nodes

def print_nodes(file: str) -> None:
    mypy_file = parse(file, "ASD", None, Options())
    for d in mypy_file.defs:
        print(d.expr.accept(evaluator))
开发者ID:qaphla,项目名称:mypy,代码行数:4,代码来源:test_evaltree.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python sametypes.is_same_type函数代码示例发布时间:2022-05-27
下一篇:
Python options.Options类代码示例发布时间: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