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


Python astroid.Uninferable方法代码示例

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


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

示例1: _looks_like_lru_cache

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Uninferable [as 别名]
def _looks_like_lru_cache(node):
    """Check if the given function node is decorated with lru_cache."""
    if not node.decorators:
        return False

    for decorator in node.decorators.nodes:
        if not isinstance(decorator, astroid.Call):
            continue

        func = helpers.safe_infer(decorator.func)
        if func in (None, astroid.Uninferable):
            continue

        if isinstance(func, astroid.FunctionDef) and func.qname() == LRU_CACHE:
            return True
    return False 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:18,代码来源:brain_functools.py

示例2: visit_tuple

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Uninferable [as 别名]
def visit_tuple(self, tuple_node):
        if PY3K or not tuple_node.elts:
            self._checker.add_message('raising-bad-type',
                                      node=self._node,
                                      args='tuple')
            return

        # On Python 2, using the following is not an error:
        #    raise (ZeroDivisionError, None)
        #    raise (ZeroDivisionError, )
        # What's left to do is to check that the first
        # argument is indeed an exception. Verifying the other arguments
        # is not the scope of this check.
        first = tuple_node.elts[0]
        inferred = utils.safe_infer(first)
        if not inferred or inferred is astroid.Uninferable:
            return

        if (isinstance(inferred, astroid.Instance)
                and inferred.__class__.__name__ != 'Instance'):
            # TODO: explain why
            self.visit_default(tuple_node)
        else:
            self.visit(inferred) 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:26,代码来源:exceptions.py

示例3: node_type

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Uninferable [as 别名]
def node_type(node):
    """Return the inferred type for `node`

    If there is more than one possible type, or if inferred type is YES or None,
    return None
    """
    # check there is only one possible type for the assign node. Else we
    # don't handle it for now
    types = set()
    try:
        for var_type in node.infer():
            if var_type == astroid.Uninferable or is_none(var_type):
                continue
            types.add(var_type)
            if len(types) > 1:
                return None
    except astroid.InferenceError:
        return None
    return types.pop() if types else None 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:21,代码来源:utils.py

示例4: _check_len

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Uninferable [as 别名]
def _check_len(self, node):
        inferred = _safe_infer_call_result(node, node)
        if not inferred or inferred is astroid.Uninferable:
            return

        if (isinstance(inferred, astroid.Instance)
                and inferred.name == 'int'
                and not isinstance(inferred, astroid.Const)):
            # Assume it's good enough, since the int() call might wrap
            # something that's uninferable for us
            return

        if not isinstance(inferred, astroid.Const):
            self.add_message('invalid-length-returned', node=node)
            return

        value = inferred.value
        if not isinstance(value, six.integer_types) or value < 0:
            self.add_message('invalid-length-returned', node=node) 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:21,代码来源:classes.py

示例5: interfaces

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Uninferable [as 别名]
def interfaces(node, herited=True, handler_func=_iface_hdlr):
    """Return an iterator on interfaces implemented by the given class node."""
    # FIXME: what if __implements__ = (MyIFace, MyParent.__implements__)...
    try:
        implements = bases.Instance(node).getattr("__implements__")[0]
    except exceptions.NotFoundError:
        return
    if not herited and implements.frame() is not node:
        return
    found = set()
    missing = False
    for iface in node_classes.unpack_infer(implements):
        if iface is astroid.Uninferable:
            missing = True
            continue
        if iface not in found and handler_func(iface):
            found.add(iface)
            yield iface
    if missing:
        raise exceptions.InferenceError() 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:22,代码来源:inspector.py

示例6: visit_tuple

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Uninferable [as 别名]
def visit_tuple(self, tuple_node):
        if PY3K or not tuple_node.elts:
            self._checker.add_message("raising-bad-type", node=self._node, args="tuple")
            return

        # On Python 2, using the following is not an error:
        #    raise (ZeroDivisionError, None)
        #    raise (ZeroDivisionError, )
        # What's left to do is to check that the first
        # argument is indeed an exception. Verifying the other arguments
        # is not the scope of this check.
        first = tuple_node.elts[0]
        inferred = utils.safe_infer(first)
        if not inferred or inferred is astroid.Uninferable:
            return

        if (
            isinstance(inferred, astroid.Instance)
            and inferred.__class__.__name__ != "Instance"
        ):
            # TODO: explain why
            self.visit_default(tuple_node)
        else:
            self.visit(inferred) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:26,代码来源:exceptions.py

示例7: _check_bad_exception_context

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Uninferable [as 别名]
def _check_bad_exception_context(self, node):
        """Verify that the exception context is properly set.

        An exception context can be only `None` or an exception.
        """
        cause = utils.safe_infer(node.cause)
        if cause in (astroid.Uninferable, None):
            return

        if isinstance(cause, astroid.Const):
            if cause.value is not None:
                self.add_message("bad-exception-context", node=node)
        elif not isinstance(cause, astroid.ClassDef) and not utils.inherit_from_std_ex(
            cause
        ):
            self.add_message("bad-exception-context", node=node) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:18,代码来源:exceptions.py

示例8: node_type

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Uninferable [as 别名]
def node_type(node: astroid.node_classes.NodeNG) -> Optional[type]:
    """Return the inferred type for `node`

    If there is more than one possible type, or if inferred type is Uninferable or None,
    return None
    """
    # check there is only one possible type for the assign node. Else we
    # don't handle it for now
    types = set()
    try:
        for var_type in node.infer():
            if var_type == astroid.Uninferable or is_none(var_type):
                continue
            types.add(var_type)
            if len(types) > 1:
                return None
    except astroid.InferenceError:
        return None
    return types.pop() if types else None 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:21,代码来源:utils.py

示例9: _check_misplaced_format_function

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Uninferable [as 别名]
def _check_misplaced_format_function(self, call_node):
        if not isinstance(call_node.func, astroid.Attribute):
            return
        if call_node.func.attrname != "format":
            return

        expr = utils.safe_infer(call_node.func.expr)
        if expr is astroid.Uninferable:
            return
        if not expr:
            # we are doubtful on inferred type of node, so here just check if format
            # was called on print()
            call_expr = call_node.func.expr
            if not isinstance(call_expr, astroid.Call):
                return
            if (
                isinstance(call_expr.func, astroid.Name)
                and call_expr.func.name == "print"
            ):
                self.add_message("misplaced-format-function", node=call_node) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:22,代码来源:base.py

示例10: visit_call

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Uninferable [as 别名]
def visit_call(self, node):
        """Visit a Call node."""
        try:
            for inferred in node.func.infer():
                if inferred is astroid.Uninferable:
                    continue
                elif inferred.root().name == OPEN_MODULE:
                    if getattr(node.func, "name", None) in OPEN_FILES:
                        self._check_open_mode(node)
                elif inferred.root().name == UNITTEST_CASE:
                    self._check_redundant_assert(node, inferred)
                elif isinstance(inferred, astroid.ClassDef):
                    if inferred.qname() == THREADING_THREAD:
                        self._check_bad_thread_instantiation(node)
                    elif inferred.qname() == SUBPROCESS_POPEN:
                        self._check_for_preexec_fn_in_Popen(node)
                elif isinstance(inferred, astroid.FunctionDef):
                    name = inferred.qname()
                    if name == COPY_COPY:
                        self._check_shallow_copy_environ(node)
                    elif name in ENV_GETTERS:
                        self._check_env_function(node, inferred)
                self._check_deprecated_method(node, inferred)
        except astroid.InferenceError:
            return 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:27,代码来源:stdlib.py

示例11: _check_proper_bases

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Uninferable [as 别名]
def _check_proper_bases(self, node):
        """
        Detect that a class inherits something which is not
        a class or a type.
        """
        for base in node.bases:
            ancestor = safe_infer(base)
            if ancestor in (astroid.Uninferable, None):
                continue
            if isinstance(ancestor, astroid.Instance) and ancestor.is_subtype_of(
                "%s.type" % (BUILTINS,)
            ):
                continue

            if not isinstance(ancestor, astroid.ClassDef) or _is_invalid_base_class(
                ancestor
            ):
                self.add_message("inherit-non-class", args=base.as_string(), node=node)

            if ancestor.name == object.__name__:
                self.add_message(
                    "useless-object-inheritance", args=node.name, node=node
                ) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:25,代码来源:classes.py

示例12: _is_iterator

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Uninferable [as 别名]
def _is_iterator(node):
        if node is astroid.Uninferable:
            # Just ignore Uninferable objects.
            return True
        if isinstance(node, Generator):
            # Generators can be itered.
            return True

        if isinstance(node, astroid.Instance):
            try:
                node.local_attr(NEXT_METHOD)
                return True
            except astroid.NotFoundError:
                pass
        elif isinstance(node, astroid.ClassDef):
            metaclass = node.metaclass()
            if metaclass and isinstance(metaclass, astroid.ClassDef):
                try:
                    metaclass.local_attr(NEXT_METHOD)
                    return True
                except astroid.NotFoundError:
                    pass
        return False 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:25,代码来源:classes.py

示例13: _check_len

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Uninferable [as 别名]
def _check_len(self, node):
        inferred = _safe_infer_call_result(node, node)
        if not inferred or inferred is astroid.Uninferable:
            return

        if (
            isinstance(inferred, astroid.Instance)
            and inferred.name == "int"
            and not isinstance(inferred, astroid.Const)
        ):
            # Assume it's good enough, since the int() call might wrap
            # something that's uninferable for us
            return

        if not isinstance(inferred, astroid.Const):
            self.add_message("invalid-length-returned", node=node)
            return

        value = inferred.value
        if not isinstance(value, int) or value < 0:
            self.add_message("invalid-length-returned", node=node) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:23,代码来源:classes.py

示例14: _annotated_unpack_infer

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Uninferable [as 别名]
def _annotated_unpack_infer(stmt, context=None):
    """
    Recursively generate nodes inferred by the given statement.
    If the inferred value is a list or a tuple, recurse on the elements.
    Returns an iterator which yields tuples in the format
    ('original node', 'infered node').
    """
    if isinstance(stmt, (astroid.List, astroid.Tuple)):
        for elt in stmt.elts:
            inferred = utils.safe_infer(elt)
            if inferred and inferred is not astroid.Uninferable:
                yield elt, inferred
        return
    for infered in stmt.infer(context):
        if infered is astroid.Uninferable:
            continue
        yield stmt, infered 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:19,代码来源:exceptions.py

示例15: _check_module_attrs

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Uninferable [as 别名]
def _check_module_attrs(self, node, module, module_names):
        """check that module_names (list of string) are accessible through the
        given module
        if the latest access name corresponds to a module, return it
        """
        assert isinstance(module, astroid.Module), module
        while module_names:
            name = module_names.pop(0)
            if name == '__dict__':
                module = None
                break
            try:
                module = next(module.getattr(name)[0].infer())
                if module is astroid.Uninferable:
                    return None
            except astroid.NotFoundError:
                if module.name in self._ignored_modules:
                    return None
                self.add_message('no-name-in-module',
                                 args=(name, module.name), node=node)
                return None
            except astroid.InferenceError:
                return None
        if module_names:
            # FIXME: other message if name is not the latest part of
            # module_names ?
            modname = module.name if module else '__dict__'
            self.add_message('no-name-in-module', node=node,
                             args=('.'.join(module_names), modname))
            return None
        if isinstance(module, astroid.Module):
            return module
        return None 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:35,代码来源:variables.py


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