예제 #1
0
 def visit_const(self, node: nodes.Const) -> None:
     if self._py36_plus:
         # f-strings require Python 3.6
         if node.pytype() == "builtins.str" and not isinstance(
             node.parent, nodes.JoinedStr
         ):
             self._detect_replacable_format_call(node)
예제 #2
0
    def visit_const(self, node: nodes.Const) -> None:
        """Check if the ellipsis constant is used unnecessarily.

        Emits a warning when:
         - A line consisting of an ellipsis is preceded by a docstring.
         - A statement exists in the same scope as the ellipsis.
           For example: A function consisting of an ellipsis followed by a
           return statement on the next line.
        """
        if (node.pytype() == "builtins.Ellipsis"
                and isinstance(node.parent, nodes.Expr)
                and ((isinstance(node.parent.parent,
                                 (nodes.ClassDef, nodes.FunctionDef))
                      and node.parent.parent.doc_node)
                     or len(node.parent.parent.body) > 1)):
            self.add_message("unnecessary-ellipsis", node=node)
예제 #3
0
 def visit_const(self, node: nodes.Const) -> None:
     """Check if the ellipsis constant is used unnecessarily.
     Emit a warning when:
      - A line consisting of an ellipsis is preceded by a docstring.
      - A statement exists in the same scope as the ellipsis.
        For example: A function consisting of an ellipsis followed by a
        return statement on the next line.
     """
     if (node.pytype() == "builtins.Ellipsis"
             and not isinstance(node.parent,
                                (nodes.Assign, nodes.AnnAssign, nodes.Call))
             and (len(node.parent.parent.child_sequence(node.parent)) > 1 or
                  (isinstance(node.parent.parent,
                              (nodes.ClassDef, nodes.FunctionDef)) and
                   (node.parent.parent.doc is not None)))):
         self.add_message("unnecessary-ellipsis", node=node)
예제 #4
0
 def visit_const(self, node: nodes.Const) -> None:
     if node.pytype() == "builtins.str" and not isinstance(
             node.parent, nodes.JoinedStr):
         self._detect_u_string_prefix(node)