當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。