示例#1
0
    def visit_JoinedStr(self, node: ast.JoinedStr) -> None:
        """
        Restricts to use ``f`` strings.

        Raises:
            FormattedStringViolation

        """
        self.add_violation(consistency.FormattedStringViolation(node))
        self.generic_visit(node)
示例#2
0
    def visit_JoinedStr(self, node: ast.JoinedStr) -> None:
        """
        Forbids use of ``f`` strings and too complex ``f`` strings.

        Raises:
            FormattedStringViolation
            TooComplexFormattedStringViolation

        """
        self._check_complex_formatted_string(node)

        # We don't allow `f` strings by default:
        self.add_violation(consistency.FormattedStringViolation(node))
        self.generic_visit(node)
    def visit_JoinedStr(self, node: ast.JoinedStr) -> None:
        """
        Forbids use of ``f`` strings and too complex ``f`` strings.

        Raises:
            FormattedStringViolation
            TooComplexFormattedStringViolation

        """
        if not isinstance(nodes.get_parent(node), ast.FormattedValue):
            # We don't allow `f` strings by default,
            # But, we need this condition to make sure that this
            # is not a part of complex string format like `f"Count={count:,}"`:
            self._check_complex_formatted_string(node)
            self.add_violation(consistency.FormattedStringViolation(node))
        self.generic_visit(node)