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


Python astroid.Raise方法代码示例

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


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

示例1: get_exception_handlers

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Raise [as 别名]
def get_exception_handlers(node, exception):
    """Return the collections of handlers handling the exception in arguments.

    Args:
        node (astroid.Raise): the node raising the exception.
        exception (builtin.Exception or str): exception or name of the exception.

    Returns:
        generator: the collection of handlers that are handling the exception or None.

    """
    context = _import_node_context(node)
    if isinstance(context, astroid.TryExcept):
        return (_handler for _handler in context.handlers
                if error_of_type(_handler, exception))
    return None 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:18,代码来源:utils.py

示例2: with_raises

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Raise [as 别名]
def with_raises(self, node, doc):
        """with_raises checks if one line doc end-with '.' .
        Args:
            node (astroid.node): the node is visiting.
            doc (Docstring): Docstring object.
        Returns:
            True if successful otherwise False.
        """

        find = False
        for t in node.body:
            if not isinstance(t, astroid.Raise):
                continue

            find = True
            break

        if not find:
            return True

        if len(doc.get_raises()) == 0:
            self.add_message('W9008', node=node, line=node.fromlineno)
            return False

        return True 
开发者ID:HorizonRobotics,项目名称:SocialRobot,代码行数:27,代码来源:docstring_checker.py

示例3: is_error

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Raise [as 别名]
def is_error(node):
    """return true if the function does nothing but raising an exception"""
    for child_node in node.get_children():
        if isinstance(child_node, astroid.Raise):
            return True
        return False 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:8,代码来源:utils.py

示例4: is_raising

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Raise [as 别名]
def is_raising(body):
    """return true if the given statement node raise an exception"""
    for node in body:
        if isinstance(node, astroid.Raise):
            return True
    return False 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:8,代码来源:utils.py

示例5: is_node_inside_try_except

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Raise [as 别名]
def is_node_inside_try_except(node):
    """Check if the node is directly under a Try/Except statement.
    (but not under an ExceptHandler!)

    Args:
        node (astroid.Raise): the node raising the exception.

    Returns:
        bool: True if the node is inside a try/except statement, False otherwise.
    """
    context = _import_node_context(node)
    return isinstance(context, astroid.TryExcept) 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:14,代码来源:utils.py

示例6: _is_raising

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Raise [as 别名]
def _is_raising(body: typing.List) -> bool:
    """Return true if the given statement node raise an exception"""
    for node in body:
        if isinstance(node, astroid.Raise):
            return True
    return False 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:8,代码来源:exceptions.py

示例7: is_error

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Raise [as 别名]
def is_error(node: astroid.node_classes.NodeNG) -> bool:
    """return true if the function does nothing but raising an exception"""
    for child_node in node.get_children():
        if isinstance(child_node, astroid.Raise):
            return True
    return False 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:8,代码来源:utils.py

示例8: is_node_inside_try_except

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Raise [as 别名]
def is_node_inside_try_except(node: astroid.Raise) -> bool:
    """Check if the node is directly under a Try/Except statement.
    (but not under an ExceptHandler!)

    Args:
        node (astroid.Raise): the node raising the exception.

    Returns:
        bool: True if the node is inside a try/except statement, False otherwise.
    """
    context = find_try_except_wrapper_node(node)
    return isinstance(context, astroid.TryExcept) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:14,代码来源:utils.py

示例9: _check_superfluous_else_raise

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Raise [as 别名]
def _check_superfluous_else_raise(self, node):
        return self._check_superfluous_else(
            node, msg_id="no-else-raise", returning_node_class=astroid.Raise
        ) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:6,代码来源:refactoring.py

示例10: _is_node_return_ended

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import Raise [as 别名]
def _is_node_return_ended(self, node):
        """Check if the node ends with an explicit return statement.

        Args:
            node (astroid.NodeNG): node to be checked.

        Returns:
            bool: True if the node ends with an explicit statement, False otherwise.

        """
        # Recursion base case
        if isinstance(node, astroid.Return):
            return True
        if isinstance(node, astroid.Call):
            try:
                funcdef_node = node.func.infered()[0]
                if self._is_function_def_never_returning(funcdef_node):
                    return True
            except astroid.InferenceError:
                pass
        # Avoid the check inside while loop as we don't know
        # if they will be completed
        if isinstance(node, astroid.While):
            return True
        if isinstance(node, astroid.Raise):
            # a Raise statement doesn't need to end with a return statement
            # but if the exception raised is handled, then the handler has to
            # ends with a return statement
            if not node.exc:
                # Ignore bare raises
                return True
            if not utils.is_node_inside_try_except(node):
                # If the raise statement is not inside a try/except statement
                # then the exception is raised and cannot be caught. No need
                # to infer it.
                return True
            exc = utils.safe_infer(node.exc)
            if exc is None or exc is astroid.Uninferable:
                return False
            exc_name = exc.pytype().split('.')[-1]
            handlers = utils.get_exception_handlers(node, exc_name)
            handlers = list(handlers) if handlers is not None else []
            if handlers:
                # among all the handlers handling the exception at least one
                # must end with a return statement
                return any(self._is_node_return_ended(_handler) for _handler in handlers)
            # if no handlers handle the exception then it's ok
            return True
        if isinstance(node, astroid.If):
            # if statement is returning if there are exactly two return statements in its
            # children : one for the body part, the other for the orelse part
            # Do not check if inner function definition are return ended.
            return_stmts = [self._is_node_return_ended(_child) for _child in node.get_children()
                            if not isinstance(_child, astroid.FunctionDef)]
            return sum(return_stmts) == 2
        # recurses on the children of the node except for those which are except handler
        # because one cannot be sure that the handler will really be used
        return any(self._is_node_return_ended(_child) for _child in node.get_children()
                   if not isinstance(_child, astroid.ExceptHandler)) 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:61,代码来源:refactoring.py


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