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.
We're only fixing them so fuzzers don't yell at us when we break "valid"
code. I mean "valid" because some of the examples aren't even accepted by
Python.
syms.expr_stmt,
syms.assert_stmt,
syms.return_stmt,
syms.expr_stmt,
syms.assert_stmt,
syms.return_stmt,
+ # these ones aren't useful to end users, but they do please fuzzers
+ syms.for_stmt,
+ syms.del_stmt,
--- /dev/null
+# Most of the following examples are really dumb, some of them aren't even accepted by Python,
+# we're fixing them only so fuzzers (which follow the grammar which actually allows these
+# examples matter of fact!) don't yell at us :p
+
+del (a := [1])
+
+try:
+ pass
+except (a := 1) as (b := why_does_this_exist):
+ pass
+
+for (z := 124) in (x := -124):
+ pass
+
+with (y := [3, 2, 1]) as (funfunfun := indeed):
+ pass
+
+
+@(please := stop)
+def sigh():
+ pass
+a[(x := 12)]
+a[:(x := 13)]
+
# we don't touch expressions in f-strings but if we do one day, don't break 'em
f'{(x:=10)}'
# we don't touch expressions in f-strings but if we do one day, don't break 'em
f'{(x:=10)}'
yield (a := 2)
raise (c := 3)
yield (a := 2)
raise (c := 3)
+def this_is_so_dumb() -> (please := no):
+ pass
+
+
# output
if foo := 0:
pass
# output
if foo := 0:
pass
+a[(x := 12)]
+a[:(x := 13)]
+
# we don't touch expressions in f-strings but if we do one day, don't break 'em
f"{(x:=10)}"
# we don't touch expressions in f-strings but if we do one day, don't break 'em
f"{(x:=10)}"
await (b := 1)
yield (a := 2)
raise (c := 3)
await (b := 1)
yield (a := 2)
raise (c := 3)
+
+
+def this_is_so_dumb() -> (please := no):
+ pass
+
if sys.version_info >= (3, 8):
black.assert_equivalent(source, actual)
if sys.version_info >= (3, 8):
black.assert_equivalent(source, actual)
+ @patch("black.dump_to_file", dump_to_stderr)
+ def test_pep_572_do_not_remove_parens(self) -> None:
+ source, expected = read_data("pep_572_do_not_remove_parens")
+ # the AST safety checks will fail, but that's expected, just make sure no
+ # parentheses are touched
+ actual = black.format_str(source, mode=DEFAULT_MODE)
+ self.assertFormatEqual(expected, actual)
+
def test_pep_572_version_detection(self) -> None:
source, _ = read_data("pep_572")
root = black.lib2to3_parse(source)
def test_pep_572_version_detection(self) -> None:
source, _ = read_data("pep_572")
root = black.lib2to3_parse(source)