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

Python utils.get_argument_from_call函数代码示例

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

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



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

示例1: _check_open_encoding

 def _check_open_encoding(self, node):
     """Check that an open() call always has an encoding set."""
     try:
         mode_arg = utils.get_argument_from_call(node, position=1,
                                                 keyword='mode')
     except utils.NoSuchArgumentError:
         mode_arg = None
     _encoding = None
     try:
         _encoding = utils.get_argument_from_call(node, position=2)
     except utils.NoSuchArgumentError:
         try:
             _encoding = utils.get_argument_from_call(node,
                                                      keyword='encoding')
         except utils.NoSuchArgumentError:
             pass
     if _encoding is None:
         if mode_arg is not None:
             mode = utils.safe_infer(mode_arg)
         if (mode_arg is not None and isinstance(mode, astroid.Const) and
                 'b' in getattr(mode, 'value', '')):
             # Files opened as binary don't need an encoding.
             return
         else:
             self.add_message('open-without-encoding', node=node)
开发者ID:HalosGhost,项目名称:qutebrowser,代码行数:25,代码来源:openencoding.py


示例2: _check_config

 def _check_config(self, node):
     """Check that the arguments to config.get(...) are valid."""
     try:
         sect_arg = utils.get_argument_from_call(node, position=0,
                                                 keyword='sectname')
         opt_arg = utils.get_argument_from_call(node, position=1,
                                                keyword='optname')
     except utils.NoSuchArgumentError:
         return
     sect_arg = utils.safe_infer(sect_arg)
     opt_arg = utils.safe_infer(opt_arg)
     if not (isinstance(sect_arg, astroid.Const) and
             isinstance(opt_arg, astroid.Const)):
         return
     try:
         configdata.DATA[sect_arg.value][opt_arg.value]
     except KeyError:
         self.add_message('bad-config-call', node=node,
                          args=(sect_arg.value, opt_arg.value))
开发者ID:michaelbeaumont,项目名称:qutebrowser,代码行数:19,代码来源:config.py


示例3: _check_open_mode

 def _check_open_mode(self, node):
     """Check that the mode argument of an open or file call is valid."""
     try:
         mode_arg = utils.get_argument_from_call(node, position=1, keyword="mode")
     except utils.NoSuchArgumentError:
         return
     if mode_arg:
         mode_arg = utils.safe_infer(mode_arg)
         if isinstance(mode_arg, astroid.Const) and not _check_mode_str(mode_arg.value):
             self.add_message("bad-open-mode", node=node, args=mode_arg.value)
开发者ID:vzhz,项目名称:cache-cards,代码行数:10,代码来源:stdlib.py


示例4: _check_config

    def _check_config(self, node):
        """Check that the arguments to config.get(...) are valid.

        FIXME: We should check all ConfigManager calls.
        https://github.com/The-Compiler/qutebrowser/issues/107
        """
        try:
            sect_arg = utils.get_argument_from_call(node, position=0, keyword="sectname")
            opt_arg = utils.get_argument_from_call(node, position=1, keyword="optname")
        except utils.NoSuchArgumentError:
            return
        sect_arg = utils.safe_infer(sect_arg)
        opt_arg = utils.safe_infer(opt_arg)
        if not (isinstance(sect_arg, astroid.Const) and isinstance(opt_arg, astroid.Const)):
            return
        try:
            configdata.DATA[sect_arg.value][opt_arg.value]
        except KeyError:
            self.add_message("bad-config-call", node=node, args=(sect_arg.value, opt_arg.value))
开发者ID:shawa,项目名称:qutebrowser,代码行数:19,代码来源:config.py


示例5: _check_open_mode

 def _check_open_mode(self, node):
     """Check that the mode argument of an open or file call is valid."""
     try:
         mode_arg = utils.get_argument_from_call(node, position=1, keyword='mode')
         if mode_arg:
             mode_arg = utils.safe_infer(mode_arg)
             if (isinstance(mode_arg, astroid.Const)
                 and not re.match(_VALID_OPEN_MODE_REGEX, mode_arg.value)):
                 self.add_message('W1501', node=node, args=(mode_arg.value))
     except (utils.NoSuchArgumentError, TypeError):
         pass
开发者ID:Launcelot,项目名称:nupic-linux64,代码行数:11,代码来源:stdlib.py


示例6: _check_reversed

    def _check_reversed(self, node):
        """ check that the argument to `reversed` is a sequence """
        try:
            argument = safe_infer(get_argument_from_call(node, position=0))
        except NoSuchArgumentError:
            self.add_message('missing-reversed-argument', node=node)
        else:
            if argument is astroid.YES:
                return
            if argument is None:
                # nothing was infered
                # try to see if we have iter()
                if isinstance(node.args[0], astroid.CallFunc):
                    try:
                        func = node.args[0].func.infer().next()
                    except InferenceError:
                        return
                    if (getattr(func, 'name', None) == 'iter' and
                        is_builtin_object(func)):
                        self.add_message('bad-reversed-sequence', node=node)
                return

            if isinstance(argument, astroid.Instance):
                if (argument._proxied.name == 'dict' and 
                    is_builtin_object(argument._proxied)):
                     self.add_message('bad-reversed-sequence', node=node)
                     return
                elif any(ancestor.name == 'dict' and is_builtin_object(ancestor)
                       for ancestor in argument._proxied.ancestors()):
                    # mappings aren't accepted by reversed()
                    self.add_message('bad-reversed-sequence', node=node)
                    return

                for methods in REVERSED_METHODS:
                    for meth in methods:
                        try:
                            argument.getattr(meth)
                        except astroid.NotFoundError:
                            break
                    else:
                        break
                else:             
                    # check if it is a .deque. It doesn't seem that
                    # we can retrieve special methods 
                    # from C implemented constructs    
                    if argument._proxied.qname().endswith(".deque"):
                        return
                    self.add_message('bad-reversed-sequence', node=node)
            elif not isinstance(argument, (astroid.List, astroid.Tuple)):
                # everything else is not a proper sequence for reversed()
                self.add_message('bad-reversed-sequence', node=node)
开发者ID:BearDrinkbeer,项目名称:python-mode,代码行数:51,代码来源:base.py


示例7: 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


示例8: _check_new_format_specifiers

    def _check_new_format_specifiers(self, node, fields, named):
        """
        Check attribute and index access in the format
        string ("{0.a}" and "{0[a]}").
        """
        for key, specifiers in fields:
            # Obtain the argument. If it can't be obtained
            # or infered, skip this check.
            if key == "":
                # {[0]} will have an unnamed argument, defaulting
                # to 0. It will not be present in `named`, so use the value
                # 0 for it.
                key = 0
            if isinstance(key, numbers.Number):
                try:
                    argname = utils.get_argument_from_call(node, key)
                except utils.NoSuchArgumentError:
                    continue
            else:
                if key not in named:
                    continue
                argname = named[key]
            if argname in (astroid.Uninferable, None):
                continue
            try:
                argument = next(argname.infer())
            except astroid.InferenceError:
                continue
            if not specifiers or argument is astroid.Uninferable:
                # No need to check this key if it doesn't
                # use attribute / item access
                continue
            if argument.parent and isinstance(argument.parent, astroid.Arguments):
                # Ignore any object coming from an argument,
                # because we can't infer its value properly.
                continue
            previous = argument
            parsed = []
            for is_attribute, specifier in specifiers:
                if previous is astroid.Uninferable:
                    break
                parsed.append((is_attribute, specifier))
                if is_attribute:
                    try:
                        previous = previous.getattr(specifier)[0]
                    except astroid.NotFoundError:
                        if (
                            hasattr(previous, "has_dynamic_getattr")
                            and previous.has_dynamic_getattr()
                        ):
                            # Don't warn if the object has a custom __getattr__
                            break
                        path = get_access_path(key, parsed)
                        self.add_message(
                            "missing-format-attribute",
                            args=(specifier, path),
                            node=node,
                        )
                        break
                else:
                    warn_error = False
                    if hasattr(previous, "getitem"):
                        try:
                            previous = previous.getitem(astroid.Const(specifier))
                        except (
                            astroid.AstroidIndexError,
                            astroid.AstroidTypeError,
                            astroid.AttributeInferenceError,
                        ):
                            warn_error = True
                        except astroid.InferenceError:
                            break
                        if previous is astroid.Uninferable:
                            break
                    else:
                        try:
                            # Lookup __getitem__ in the current node,
                            # but skip further checks, because we can't
                            # retrieve the looked object
                            previous.getattr("__getitem__")
                            break
                        except astroid.NotFoundError:
                            warn_error = True
                    if warn_error:
                        path = get_access_path(key, parsed)
                        self.add_message(
                            "invalid-format-index", args=(specifier, path), node=node
                        )
                        break

                try:
                    previous = next(previous.infer())
                except astroid.InferenceError:
                    # can't check further if we can't infer it
                    break
开发者ID:bluesheeptoken,项目名称:pylint,代码行数:95,代码来源:strings.py


示例9: testGetArgumentFromCallExists

def testGetArgumentFromCallExists(fn, kw):
    node = astroid.extract_node(fn)
    assert utils.get_argument_from_call(node, **kw) is not None
开发者ID:aluoch-sheila,项目名称:NEIGHBOURHOOD,代码行数:3,代码来源:unittest_checkers_utils.py


示例10: testGetArgumentFromCallError

def testGetArgumentFromCallError(fn, kw):
    with pytest.raises(utils.NoSuchArgumentError):
        node = astroid.extract_node(fn)
        utils.get_argument_from_call(node, **kw)
开发者ID:aluoch-sheila,项目名称:NEIGHBOURHOOD,代码行数:4,代码来源:unittest_checkers_utils.py


示例11: testGetArgumentFromCall

 def testGetArgumentFromCall(self):
     node = test_utils.extract_node('foo(bar=3)')
     self.assertIsNotNone(utils.get_argument_from_call(node, keyword='bar'))
     with self.assertRaises(utils.NoSuchArgumentError):
         node = test_utils.extract_node('foo(3)')
         utils.get_argument_from_call(node, keyword='bar')
     with self.assertRaises(utils.NoSuchArgumentError):
         node = test_utils.extract_node('foo(one=a, two=b, three=c)')
         utils.get_argument_from_call(node, position=1)
     node = test_utils.extract_node('foo(a, b, c)')
     self.assertIsNotNone(utils.get_argument_from_call(node, position=1))
     node = test_utils.extract_node('foo(a, not_this_one=1, this_one=2)')
     arg = utils.get_argument_from_call(node, position=1, keyword='this_one')
     self.assertEqual(2, arg.value)
     node = test_utils.extract_node('foo(a)')
     with self.assertRaises(utils.NoSuchArgumentError):
         utils.get_argument_from_call(node, position=1)
     with self.assertRaises(ValueError):
         utils.get_argument_from_call(node, None, None)
             
     name = utils.get_argument_from_call(node, position=0)
     self.assertEqual(name.name, 'a')
开发者ID:Launcelot,项目名称:nupic-linux64,代码行数:22,代码来源:unittest_checkers_utils.py


示例12: _check_shallow_copy_environ

 def _check_shallow_copy_environ(self, node):
     arg = utils.get_argument_from_call(node, position=0)
     for inferred in arg.inferred():
         if inferred.qname() == OS_ENVIRON:
             self.add_message('shallow-copy-environ', node=node)
             break
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:6,代码来源:stdlib.py


示例13: _check_new_format_specifiers

    def _check_new_format_specifiers(self, node, fields, named):
        """
        Check attribute and index access in the format
        string ("{0.a}" and "{0[a]}").
        """
        for key, specifiers in fields:
            # Obtain the argument. If it can't be obtained
            # or infered, skip this check.
            if key == '':
                # {[0]} will have an unnamed argument, defaulting
                # to 0. It will not be present in `named`, so use the value
                # 0 for it.
                key = 0
            if isinstance(key, numbers.Number):
                try:
                    argname = utils.get_argument_from_call(node, key)
                except utils.NoSuchArgumentError:
                    continue
            else:
                if key not in named:
                    continue
                argname = named[key]
            if argname in (astroid.YES, None):
                continue
            try:
                argument = argname.infer().next()
            except astroid.InferenceError:
                continue
            if not specifiers or argument is astroid.YES:
                # No need to check this key if it doesn't
                # use attribute / item access
                continue
            if argument.parent and isinstance(argument.parent, astroid.Arguments):
                # Check to see if our argument is kwarg or vararg,
                # and skip the check for this argument if so, because when inferring,
                # astroid will return empty objects (dicts and tuples) and
                # that can lead to false positives.
                if argname.name in (argument.parent.kwarg, argument.parent.vararg):
                    continue
            previous = argument
            parsed = []
            for is_attribute, specifier in specifiers:
                if previous is astroid.YES:
                    break
                parsed.append((is_attribute, specifier))
                if is_attribute:
                    try:
                        previous = previous.getattr(specifier)[0]
                    except astroid.NotFoundError:
                        if (hasattr(previous, 'has_dynamic_getattr') and
                                previous.has_dynamic_getattr()):
                            # Don't warn if the object has a custom __getattr__
                            break
                        path = get_access_path(key, parsed)
                        self.add_message('missing-format-attribute',
                                         args=(specifier, path),
                                         node=node)
                        break
                else:
                    warn_error = False
                    if hasattr(previous, 'getitem'):
                        try:
                            previous = previous.getitem(specifier)
                        except (IndexError, TypeError):
                            warn_error = True
                    else:
                        try:
                            # Lookup __getitem__ in the current node,
                            # but skip further checks, because we can't
                            # retrieve the looked object
                            previous.getattr('__getitem__')
                            break
                        except astroid.NotFoundError:
                            warn_error = True
                    if warn_error:
                        path = get_access_path(key, parsed)
                        self.add_message('invalid-format-index',
                                         args=(specifier, path),
                                         node=node)
                        break

                try:
                    previous = previous.infer().next()
                except astroid.InferenceError:
                    # can't check further if we can't infer it
                    break
开发者ID:CoherentLabs,项目名称:depot_tools,代码行数:86,代码来源:strings.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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