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

Python astroid.extract_node函数代码示例

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

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



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

示例1: test_check_bad_docstring

    def test_check_bad_docstring(self):
        stmt = astroid.extract_node('def fff():\n   """bad coment"""\n   pass')
        with self.assertAddsMessages(
            Message(
                "wrong-spelling-in-docstring",
                line=2,
                args=(
                    "coment",
                    "bad coment",
                    "    ^^^^^^",
                    self._get_msg_suggestions("coment"),
                ),
            )
        ):
            self.checker.visit_functiondef(stmt)

        stmt = astroid.extract_node('class Abc(object):\n   """bad coment"""\n   pass')
        with self.assertAddsMessages(
            Message(
                "wrong-spelling-in-docstring",
                line=2,
                args=(
                    "coment",
                    "bad coment",
                    "    ^^^^^^",
                    self._get_msg_suggestions("coment"),
                ),
            )
        ):
            self.checker.visit_classdef(stmt)
开发者ID:aluoch-sheila,项目名称:NEIGHBOURHOOD,代码行数:30,代码来源:unittest_checker_spelling.py


示例2: test_module_level_names

    def test_module_level_names(self):
        assign = astroid.extract_node("""
        import collections
        Class = collections.namedtuple("a", ("b", "c")) #@
        """)
        with self.assertNoMessages():
            self.checker.visit_assignname(assign.targets[0])

        assign = astroid.extract_node("""
        class ClassA(object):
            pass
        ClassB = ClassA
        """)
        with self.assertNoMessages():
            self.checker.visit_assignname(assign.targets[0])

        module = astroid.parse("""
        def A():
          return 1, 2, 3
        CONSTA, CONSTB, CONSTC = A()
        CONSTD = A()""")
        with self.assertNoMessages():
            self.checker.visit_assignname(module.body[1].targets[0].elts[0])
            self.checker.visit_assignname(module.body[2].targets[0])

        assign = astroid.extract_node("""
        CONST = "12 34 ".rstrip().split()""")
        with self.assertNoMessages():
            self.checker.visit_assignname(assign.targets[0])
开发者ID:glennmatthews,项目名称:pylint,代码行数:29,代码来源:unittest_checker_base.py


示例3: test_skip_camel_cased_words

    def test_skip_camel_cased_words(self):
        stmt = astroid.extract_node(
            'class ComentAbc(object):\n   """comentAbc with a bad coment"""\n   pass')
        with self.assertAddsMessages(
            Message('wrong-spelling-in-docstring', line=2,
                    args=('coment', 'comentAbc with a bad coment',
                          '                     ^^^^^^',
                          self._get_msg_suggestions('coment')))):
            self.checker.visit_classdef(stmt)

        # With just a single upper case letter in the end
        stmt = astroid.extract_node(
            'class ComentAbc(object):\n   """argumentN with a bad coment"""\n   pass')
        with self.assertAddsMessages(
            Message('wrong-spelling-in-docstring', line=2,
                    args=('coment', 'argumentN with a bad coment',
                          '                     ^^^^^^',
                          self._get_msg_suggestions('coment')))):
            self.checker.visit_classdef(stmt)

        # With just a single lower and upper case letter is not good
        stmt = astroid.extract_node(
            'class ComentAbc(object):\n   """zN with a bad comment"""\n   pass')
        with self.assertAddsMessages(
            Message('wrong-spelling-in-docstring', line=2,
                    args=('zN', 'zN with a bad comment',
                          '^^',
                          self._get_msg_suggestions('zN')))):
            self.checker.visit_classdef(stmt)
开发者ID:AWhetter,项目名称:pylint,代码行数:29,代码来源:unittest_checker_spelling.py


示例4: test_custom_callback_string

    def test_custom_callback_string(self):
        """ Test the --calbacks option works. """
        node = astroid.extract_node("""
        def callback_one(abc):
             ''' should not emit unused-argument. '''
        """)
        with self.assertNoMessages():
            self.checker.visit_functiondef(node)
            self.checker.leave_functiondef(node)

        node = astroid.extract_node("""
        def two_callback(abc, defg):
             ''' should not emit unused-argument. '''
        """)
        with self.assertNoMessages():
            self.checker.visit_functiondef(node)
            self.checker.leave_functiondef(node)

        node = astroid.extract_node("""
        def normal_func(abc):
             ''' should emit unused-argument. '''
        """)
        with self.assertAddsMessages(
                Message('unused-argument', node=node['abc'], args='abc')):
            self.checker.visit_functiondef(node)
            self.checker.leave_functiondef(node)

        node = astroid.extract_node("""
        def cb_func(abc):
             ''' Previous callbacks are overridden. '''
        """)
        with self.assertAddsMessages(
                Message('unused-argument', node=node['abc'], args='abc')):
            self.checker.visit_functiondef(node)
            self.checker.leave_functiondef(node)
开发者ID:KabageMark,项目名称:newsapp,代码行数:35,代码来源:unittest_checker_variables.py


示例5: test_skip_camel_cased_words

    def test_skip_camel_cased_words(self):
        stmt = astroid.extract_node(
            'class ComentAbc(object):\n   """comentAbc with a bad coment"""\n   pass')
        with self.assertAddsMessages(
            Message('wrong-spelling-in-docstring', line=2,
                    args=('coment', 'comentAbc with a bad coment',
                          '                     ^^^^^^',
                          self._get_msg_suggestions('coment')))):
            self.checker.visit_classdef(stmt)

        # With just a single upper case letter in the end
        stmt = astroid.extract_node(
            'class ComentAbc(object):\n   """argumentN with a bad coment"""\n   pass')
        with self.assertAddsMessages(
            Message('wrong-spelling-in-docstring', line=2,
                    args=('coment', 'argumentN with a bad coment',
                          '                     ^^^^^^',
                          self._get_msg_suggestions('coment')))):
            self.checker.visit_classdef(stmt)

        for ccn in ('xmlHttpRequest', 'newCustomer', 'newCustomerId',
                    'innerStopwatch', 'supportsIpv6OnIos', 'affine3D'):
            stmt = astroid.extract_node(
                'class TestClass(object):\n   """{} comment"""\n   pass'.format(ccn))
            self.checker.visit_classdef(stmt)
            assert self.linter.release_messages() == []
开发者ID:Mariatta,项目名称:pylint,代码行数:26,代码来源:unittest_checker_spelling.py


示例6: test_dict_not_iter_method

 def test_dict_not_iter_method(self):
     arg_node = astroid.extract_node("x.iterkeys(x)  #@")
     stararg_node = astroid.extract_node("x.iterkeys(*x)  #@")
     kwarg_node = astroid.extract_node("x.iterkeys(y=x)  #@")
     with self.assertNoMessages():
         for node in (arg_node, stararg_node, kwarg_node):
             self.checker.visit_call(node)
开发者ID:bluesheeptoken,项目名称:pylint,代码行数:7,代码来源:unittest_checker_python3.py


示例7: testSingleLineClassStmts

    def testSingleLineClassStmts(self):
        stmt = astroid.extract_node("""
        class MyError(Exception): pass  #@
        """)
        self.checker.config.single_line_class_stmt = False
        with self.assertAddsMessages(Message('multiple-statements', node=stmt.body[0])):
            self.visitFirst(stmt)
        self.checker.config.single_line_class_stmt = True
        with self.assertNoMessages():
            self.visitFirst(stmt)

        stmt = astroid.extract_node("""
        class MyError(Exception): a='a'  #@
        """)
        self.checker.config.single_line_class_stmt = False
        with self.assertAddsMessages(Message('multiple-statements', node=stmt.body[0])):
            self.visitFirst(stmt)
        self.checker.config.single_line_class_stmt = True
        with self.assertNoMessages():
            self.visitFirst(stmt)

        stmt = astroid.extract_node("""
        class MyError(Exception): a='a'; b='b'  #@
        """)
        self.checker.config.single_line_class_stmt = False
        with self.assertAddsMessages(Message('multiple-statements', node=stmt.body[0])):
            self.visitFirst(stmt)
        self.checker.config.single_line_class_stmt = True
        with self.assertAddsMessages(Message('multiple-statements', node=stmt.body[0])):
            self.visitFirst(stmt)
开发者ID:KabageMark,项目名称:newsapp,代码行数:30,代码来源:unittest_checker_format.py


示例8: test_not_next_method

 def test_not_next_method(self):
     arg_node = astroid.extract_node('x.next(x)  #@')
     stararg_node = astroid.extract_node('x.next(*x)  #@')
     kwarg_node = astroid.extract_node('x.next(y=x)  #@')
     with self.assertNoMessages():
         for node in (arg_node, stararg_node, kwarg_node):
             self.checker.visit_call(node)
开发者ID:Vauxoo,项目名称:pylint,代码行数:7,代码来源:unittest_checker_python3.py


示例9: test_dict_not_view_method

 def test_dict_not_view_method(self):
     arg_node = astroid.extract_node('x.viewkeys(x)  #@')
     stararg_node = astroid.extract_node('x.viewkeys(*x)  #@')
     kwarg_node = astroid.extract_node('x.viewkeys(y=x)  #@')
     non_dict_node = astroid.extract_node('x=[]\nx.viewkeys() #@')
     with self.assertNoMessages():
         for node in (arg_node, stararg_node, kwarg_node, non_dict_node):
             self.checker.visit_call(node)
开发者ID:Vauxoo,项目名称:pylint,代码行数:8,代码来源:unittest_checker_python3.py


示例10: test_wrong_name_of_func_params_in_numpy_docstring

    def test_wrong_name_of_func_params_in_numpy_docstring(self):
        """Example of functions with inconsistent parameter names in the
        signature and in the Numpy style documentation
        """
        node = astroid.extract_node("""
        def function_foo(xarg, yarg, zarg):
            '''function foo ...

            Parameters
            ----------
            xarg1: int
                bla xarg
            yarg: float
                bla yarg

            zarg1: str
                bla zarg
            '''
            return xarg + yarg
        """)
        with self.assertAddsMessages(
            Message(
                msg_id='missing-param-doc',
                node=node,
                args=('xarg, xarg1, zarg, zarg1',)),
            Message(
                msg_id='missing-type-doc',
                node=node,
                args=('xarg, xarg1, zarg, zarg1',)),
        ):
            self.checker.visit_functiondef(node)

        node = astroid.extract_node("""
        def function_foo(xarg, yarg):
            '''function foo ...

            Parameters
            ----------
            yarg1: float
                bla yarg

            For the other parameters, see bla.
            '''
            return xarg + yarg
        """)
        with self.assertAddsMessages(
            Message(
                msg_id='missing-param-doc',
                node=node,
                args=('yarg1',)),
            Message(
                msg_id='missing-type-doc',
                node=node,
                args=('yarg1',))
        ):
            self.checker.visit_functiondef(node)
开发者ID:Vauxoo,项目名称:pylint,代码行数:56,代码来源:test_check_docs.py


示例11: test_old_raise_syntax

    def test_old_raise_syntax(self):
        node = astroid.extract_node('raise Exception, "test"')
        message = testutils.Message('old-raise-syntax', node=node)
        with self.assertAddsMessages(message):
            self.checker.visit_raise(node)

        node = astroid.extract_node('raise Exception, "test", tb')
        message = testutils.Message('old-raise-syntax', node=node)

        with self.assertAddsMessages(message):
            self.checker.visit_raise(node)
开发者ID:nnishimura,项目名称:python,代码行数:11,代码来源:unittest_checker_python3.py


示例12: testGetArgumentFromCall

def testGetArgumentFromCall():
    node = astroid.extract_node("foo(a, not_this_one=1, this_one=2)")
    arg = utils.get_argument_from_call(node, position=2, keyword="this_one")
    assert 2 == arg.value

    node = astroid.extract_node("foo(a)")
    with pytest.raises(utils.NoSuchArgumentError):
        utils.get_argument_from_call(node, position=1)
    with pytest.raises(ValueError):
        utils.get_argument_from_call(node, None, None)
    name = utils.get_argument_from_call(node, position=0)
    assert name.name == "a"
开发者ID:aluoch-sheila,项目名称:NEIGHBOURHOOD,代码行数:12,代码来源:unittest_checkers_utils.py


示例13: test_custom_callback_string

    def test_custom_callback_string(self):
        """ Test the --calbacks option works. """

        def cleanup():
            self.checker._to_consume = _to_consume

        _to_consume = self.checker._to_consume
        self.checker._to_consume = []
        self.addCleanup(cleanup)

        node = astroid.extract_node(
            """
        def callback_one(abc):
             ''' should not emit unused-argument. '''
        """
        )
        with self.assertNoMessages():
            self.checker.visit_functiondef(node)
            self.checker.leave_functiondef(node)

        node = astroid.extract_node(
            """
        def two_callback(abc, defg):
             ''' should not emit unused-argument. '''
        """
        )
        with self.assertNoMessages():
            self.checker.visit_functiondef(node)
            self.checker.leave_functiondef(node)

        node = astroid.extract_node(
            """
        def normal_func(abc):
             ''' should emit unused-argument. '''
        """
        )
        with self.assertAddsMessages(Message("unused-argument", node=node["abc"], args="abc")):
            self.checker.visit_functiondef(node)
            self.checker.leave_functiondef(node)

        node = astroid.extract_node(
            """
        def cb_func(abc):
             ''' Previous callbacks are overriden. '''
        """
        )
        with self.assertAddsMessages(Message("unused-argument", node=node["abc"], args="abc")):
            self.checker.visit_functiondef(node)
            self.checker.leave_functiondef(node)
开发者ID:PyCQA,项目名称:pylint,代码行数:49,代码来源:unittest_checker_variables.py


示例14: test_existing_func_params_in_numpy_docstring

    def test_existing_func_params_in_numpy_docstring(self):
        """Example of a function with correctly documented parameters and
        return values (Numpy style)
        """
        node = astroid.extract_node("""
        def function_foo(xarg, yarg, zarg, warg):
            '''function foo ...

            Parameters
            ----------
            xarg: int
                bla xarg
            yarg: my.qualified.type
                bla yarg

            zarg: int
                bla zarg
            warg: my.qualified.type
                bla warg

            Returns
            -------
            float
                sum
            '''
            return xarg + yarg
        """)
        with self.assertNoMessages():
            self.checker.visit_functiondef(node)
开发者ID:Vauxoo,项目名称:pylint,代码行数:29,代码来源:test_check_docs.py


示例15: test_missing_func_params_in_sphinx_docstring

    def test_missing_func_params_in_sphinx_docstring(self):
        """Example of a function with missing Sphinx parameter documentation in
        the docstring
        """
        node = astroid.extract_node("""
        def function_foo(x, y, z):
            '''docstring ...

            :param x: bla

            :param int z: bar
            '''
            pass
        """)
        with self.assertAddsMessages(
            Message(
                msg_id='missing-param-doc',
                node=node,
                args=('y',)),
            Message(
                msg_id='missing-type-doc',
                node=node,
                args=('x, y',))
        ):
            self.checker.visit_functiondef(node)
开发者ID:Vauxoo,项目名称:pylint,代码行数:25,代码来源:test_check_docs.py


示例16: test_existing_func_params_in_sphinx_docstring

    def test_existing_func_params_in_sphinx_docstring(self):
        """Example of a function with correctly documented parameters and
        return values (Sphinx style)
        """
        node = astroid.extract_node("""
        def function_foo(xarg, yarg, zarg, warg):
            '''function foo ...

            :param xarg: bla xarg
            :type xarg: int

            :parameter yarg: bla yarg
            :type yarg: my.qualified.type

            :arg int zarg: bla zarg

            :keyword my.qualified.type warg: bla warg

            :return: sum
            :rtype: float
            '''
            return xarg + yarg
        """)
        with self.assertNoMessages():
            self.checker.visit_functiondef(node)
开发者ID:Vauxoo,项目名称:pylint,代码行数:25,代码来源:test_check_docs.py


示例17: test_missing_method_params_in_numpy_docstring

    def test_missing_method_params_in_numpy_docstring(self):
        """Example of a class method with missing parameter documentation in
        the Numpy style docstring
        """
        node = astroid.extract_node("""
        class Foo(object):
            def method_foo(self, x, y):
                '''docstring ...

                missing parameter documentation

                Parameters
                ----------
                x:
                    bla
                '''
                pass
        """)
        method_node = node.body[0]
        with self.assertAddsMessages(
            Message(
                msg_id='missing-param-doc',
                node=method_node,
                args=('y',)),
            Message(
                msg_id='missing-type-doc',
                node=method_node,
                args=('x, y',))
        ):
            self._visit_methods_of_class(node)
开发者ID:Vauxoo,项目名称:pylint,代码行数:30,代码来源:test_check_docs.py


示例18: test_ok_str_translate_call_not_str

 def test_ok_str_translate_call_not_str(self):
     node = astroid.extract_node('''
      foobar = {}
      foobar.translate(None, 'foobar') #@
      ''')
     with self.assertNoMessages():
         self.checker.visit_call(node)
开发者ID:Vauxoo,项目名称:pylint,代码行数:7,代码来源:unittest_checker_python3.py


示例19: test_ok_string_import_from

 def test_ok_string_import_from(self):
     node = astroid.extract_node('''
      from string import digits #@
      ''')
     absolute_import_message = testutils.Message('no-absolute-import', node=node)
     with self.assertAddsMessages(absolute_import_message):
         self.checker.visit_importfrom(node)
开发者ID:Vauxoo,项目名称:pylint,代码行数:7,代码来源:unittest_checker_python3.py


示例20: test_all_elements_without_parent

 def test_all_elements_without_parent(self):
     node = astroid.extract_node('__all__ = []')
     node.value.elts.append(astroid.Const('test'))
     root = node.root()
     with self.assertNoMessages():
         self.checker.visit_module(root)
         self.checker.leave_module(root)
开发者ID:glennmatthews,项目名称:pylint,代码行数:7,代码来源:unittest_checker_variables.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python astroid.parse函数代码示例发布时间:2022-05-24
下一篇:
Python astroid.are_exclusive函数代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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