All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
Found by the fuzzer. Repro case:
python -m black -c 'importA;()<<0**0#'
if (
prev
and prev.type == token.COMMA
if (
prev
and prev.type == token.COMMA
+ and leaf.opening_bracket is not None
and not is_one_tuple_between(
leaf.opening_bracket, leaf, line.leaves
)
and not is_one_tuple_between(
leaf.opening_bracket, leaf, line.leaves
)
if (
prev
and prev.type == token.COMMA
if (
prev
and prev.type == token.COMMA
+ and leaf.opening_bracket is not None
and not is_one_tuple_between(leaf.opening_bracket, leaf, line.leaves)
):
# Never omit bracket pairs with trailing commas.
and not is_one_tuple_between(leaf.opening_bracket, leaf, line.leaves)
):
# Never omit bracket pairs with trailing commas.
if self.is_import:
return True
if self.is_import:
return True
- if not is_one_tuple_between(closing.opening_bracket, closing, self.leaves):
+ if closing.opening_bracket is not None and not is_one_tuple_between(
+ closing.opening_bracket, closing, self.leaves
+ ):
value: Text
fixers_applied: List[Any]
bracket_depth: int
value: Text
fixers_applied: List[Any]
bracket_depth: int
- opening_bracket: "Leaf"
+ # Changed later in brackets.py
+ opening_bracket: Optional["Leaf"] = None
used_names: Optional[Set[Text]]
_prefix = "" # Whitespace and comments preceding this token in the input
lineno: int = 0 # Line where this token starts in the input
used_names: Optional[Set[Text]]
_prefix = "" # Whitespace and comments preceding this token in the input
lineno: int = 0 # Line where this token starts in the input
context: Optional[Context] = None,
prefix: Optional[Text] = None,
fixers_applied: List[Any] = [],
context: Optional[Context] = None,
prefix: Optional[Text] = None,
fixers_applied: List[Any] = [],
+ opening_bracket: Optional["Leaf"] = None,
) -> None:
"""
Initializer.
) -> None:
"""
Initializer.
self._prefix = prefix
self.fixers_applied: Optional[List[Any]] = fixers_applied[:]
self.children = []
self._prefix = prefix
self.fixers_applied: Optional[List[Any]] = fixers_applied[:]
self.children = []
+ self.opening_bracket = opening_bracket
def __repr__(self) -> str:
"""Return a canonical string representation."""
def __repr__(self) -> str:
"""Return a canonical string representation."""
self.value,
(self.prefix, (self.lineno, self.column)),
fixers_applied=self.fixers_applied,
self.value,
(self.prefix, (self.lineno, self.column)),
fixers_applied=self.fixers_applied,
+ opening_bracket=self.opening_bracket,
)
def leaves(self) -> Iterator["Leaf"]:
)
def leaves(self) -> Iterator["Leaf"]:
--- /dev/null
+importA;()<<0**0#
+
+# output
+
+importA
+(
+ ()
+ << 0
+ ** 0
+) #
def test_python39() -> None:
source, expected = read_data("python39")
assert_format(source, expected, minimum_version=(3, 9))
def test_python39() -> None:
source, expected = read_data("python39")
assert_format(source, expected, minimum_version=(3, 9))
+
+
+def test_power_op_newline() -> None:
+ # requires line_length=0
+ source, expected = read_data("power_op_newline")
+ assert_format(source, expected, mode=black.Mode(line_length=0))