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


Python astroid.InferenceError方法代码示例

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


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

示例1: _nose_tools_functions

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import InferenceError [as 别名]
def _nose_tools_functions():
    """Get an iterator of names and bound methods."""
    module = _BUILDER.string_build(textwrap.dedent('''
    import unittest

    class Test(unittest.TestCase):
        pass
    a = Test()
    '''))
    try:
        case = next(module['a'].infer())
    except astroid.InferenceError:
        return
    for method in case.methods():
        if method.name.startswith('assert') and '_' not in method.name:
            pep8_name = _pep8(method.name)
            yield pep8_name, astroid.BoundMethod(method, case)
        if method.name == 'assertEqual':
            # nose also exports assert_equals.
            yield 'assert_equals', astroid.BoundMethod(method, case) 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:22,代码来源:brain_nose.py

示例2: visit_raise

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import InferenceError [as 别名]
def visit_raise(self, node):
        if node.exc is None:
            self._check_misplaced_bare_raise(node)
            return

        if PY3K and node.cause:
            self._check_bad_exception_context(node)

        expr = node.exc
        try:
            inferred_value = next(expr.infer())
        except astroid.InferenceError:
            inferred_value = None

        ExceptionRaiseRefVisitor(self, node).visit(expr)

        if inferred_value:
            ExceptionRaiseLeafVisitor(self, node).visit(inferred_value) 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:20,代码来源:exceptions.py

示例3: safe_infer

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import InferenceError [as 别名]
def safe_infer(node, context=None):
    """Return the inferred value for the given node.

    Return None if inference failed or if there is some ambiguity (more than
    one node has been inferred).
    """
    try:
        inferit = node.infer(context=context)
        value = next(inferit)
    except astroid.InferenceError:
        return None
    try:
        next(inferit)
        return None # None if there is ambiguity on the inferred node
    except astroid.InferenceError:
        return None # there is some kind of ambiguity
    except StopIteration:
        return value 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:20,代码来源:utils.py

示例4: node_type

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import InferenceError [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

示例5: is_enum_class

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import InferenceError [as 别名]
def is_enum_class(node):
    """Check if a class definition defines an Enum class.

    :param node: The class node to check.
    :type node: astroid.ClassDef

    :returns: True if the given node represents an Enum class. False otherwise.
    :rtype: bool
    """
    for base in node.bases:
        try:
            inferred_bases = base.inferred()
        except astroid.InferenceError:
            continue

        for ancestor in inferred_bases:
            if not isinstance(ancestor, astroid.ClassDef):
                continue

            if ancestor.name == 'Enum' and ancestor.root().name == 'enum':
                return True

    return False 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:25,代码来源:utils.py

示例6: visit_attribute

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import InferenceError [as 别名]
def visit_attribute(self, node):
        """Look for removed attributes"""
        if node.attrname == 'xreadlines':
            self.add_message('xreadlines-attribute', node=node)
            return

        exception_message = 'message'
        try:
            for inferred in node.expr.infer():
                if (isinstance(inferred, astroid.Instance) and
                        utils.inherit_from_std_ex(inferred)):
                    if node.attrname == exception_message:

                        # Exceptions with .message clearly defined are an exception
                        if exception_message in inferred.instance_attrs:
                            continue
                        self.add_message('exception-message-attribute', node=node)
                if isinstance(inferred, astroid.Module):
                    self._warn_if_deprecated(node, inferred.name, {node.attrname},
                                             report_on_modules=False)
        except astroid.InferenceError:
            return 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:24,代码来源:python3.py

示例7: visit_raise

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import InferenceError [as 别名]
def visit_raise(self, node):
        """Visit a raise statement and check for raising
        strings or old-raise-syntax.
        """
        if six.PY2:
            if (node.exc is not None and
                    node.inst is not None):
                self.add_message('old-raise-syntax', node=node)

        # Ignore empty raise.
        if node.exc is None:
            return
        expr = node.exc
        if self._check_raise_value(node, expr):
            return
        try:
            value = next(astroid.unpack_infer(expr))
        except astroid.InferenceError:
            return
        self._check_raise_value(node, value) 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:22,代码来源:python3.py

示例8: visit_call

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

示例9: _has_data_descriptor

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import InferenceError [as 别名]
def _has_data_descriptor(cls, attr):
    attributes = cls.getattr(attr)
    for attribute in attributes:
        try:
            for inferred in attribute.infer():
                if isinstance(inferred, astroid.Instance):
                    try:
                        inferred.getattr('__get__')
                        inferred.getattr('__set__')
                    except astroid.NotFoundError:
                        continue
                    else:
                        return True
        except astroid.InferenceError:
            # Can't infer, avoid emitting a false positive in this case.
            return True
    return False 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:19,代码来源:classes.py

示例10: _called_in_methods

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import InferenceError [as 别名]
def _called_in_methods(func, klass, methods):
    """ Check if the func was called in any of the given methods,
    belonging to the *klass*. Returns True if so, False otherwise.
    """
    if not isinstance(func, astroid.FunctionDef):
        return False
    for method in methods:
        try:
            infered = klass.getattr(method)
        except astroid.NotFoundError:
            continue
        for infer_method in infered:
            for call in infer_method.nodes_of_class(astroid.Call):
                try:
                    bound = next(call.func.infer())
                except (astroid.InferenceError, StopIteration):
                    continue
                if not isinstance(bound, astroid.BoundMethod):
                    continue
                func_obj = bound._proxied
                if isinstance(func_obj, astroid.UnboundMethod):
                    func_obj = func_obj._proxied
                if func_obj.name == func.name:
                    return True
    return False 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:27,代码来源:classes.py

示例11: _safe_infer_call_result

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import InferenceError [as 别名]
def _safe_infer_call_result(node, caller, context=None):
    """
    Safely infer the return value of a function.

    Returns None if inference failed or if there is some ambiguity (more than
    one node has been inferred). Otherwise returns infered value.
    """
    try:
        inferit = node.infer_call_result(caller, context=context)
        value = next(inferit)
    except astroid.InferenceError:
        return None  # inference failed
    except StopIteration:
        return None  # no values infered
    try:
        next(inferit)
        return None  # there is ambiguity on the inferred node
    except astroid.InferenceError:
        return None  # there is some kind of ambiguity
    except StopIteration:
        return value 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:23,代码来源:classes.py

示例12: _get_attribute_property_setter

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import InferenceError [as 别名]
def _get_attribute_property_setter(name, klass):
    """Return the name of a setter for name in klass, if name is a property."""
    try:
        attributes = klass.getattr(name)
    except astroid.NotFoundError:
        return None

    property_name = "{0}.property".format(BUILTINS)
    for attr in attributes:
        try:
            infered = next(attr.infer())
        except astroid.InferenceError:
            continue
        if infered.pytype() == property_name:
            try:
                # In this case, attr is in a statement of the form
                # <attr> = property(<fget>, <fset>); return the name of <fset>,
                # assuming it is an identifier (and not a more complex expression).
                return attr.parent.value.args[1].name
            except Exception:
                return None 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:23,代码来源:checkers.py

示例13: _nose_tools_functions

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import InferenceError [as 别名]
def _nose_tools_functions():
    """Get an iterator of names and bound methods."""
    module = _BUILDER.string_build(
        textwrap.dedent(
            """
    import unittest

    class Test(unittest.TestCase):
        pass
    a = Test()
    """
        )
    )
    try:
        case = next(module["a"].infer())
    except astroid.InferenceError:
        return
    for method in case.methods():
        if method.name.startswith("assert") and "_" not in method.name:
            pep8_name = _pep8(method.name)
            yield pep8_name, astroid.BoundMethod(method, case)
        if method.name == "assertEqual":
            # nose also exports assert_equals.
            yield "assert_equals", astroid.BoundMethod(method, case) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:26,代码来源:brain_nose.py

示例14: interfaces

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import InferenceError [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

示例15: _is_enum_class

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import InferenceError [as 别名]
def _is_enum_class(node: astroid.ClassDef) -> bool:
    """Check if a class definition defines an Enum class.

    :param node: The class node to check.
    :type node: astroid.ClassDef

    :returns: True if the given node represents an Enum class. False otherwise.
    :rtype: bool
    """
    for base in node.bases:
        try:
            inferred_bases = base.inferred()
        except astroid.InferenceError:
            continue

        for ancestor in inferred_bases:
            if not isinstance(ancestor, astroid.ClassDef):
                continue

            if ancestor.name == "Enum" and ancestor.root().name == "enum":
                return True

    return False 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:25,代码来源:design_analysis.py


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