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.
summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
e196180)
Fixes a pathological situation where if a function signature used a trailing
comma but was later reformatted to a single line (with the trailing comma
removed), Black would change its mind whether a file is Python
3.6-compatible between runs.
* fixed not splitting long from-imports with only a single name
* fixed not splitting long from-imports with only a single name
+* fixed Python 3.6+ file discovery by also looking at function calls with
+ unpacking. This fixed non-deterministic formatting if trailing commas
+ where used both in function signatures with stars and function calls
+ with stars but the former would be reformatted to a single line.
+
Currently looking for:
- f-strings; and
Currently looking for:
- f-strings; and
- - trailing commas after * or ** in function signatures.
+ - trailing commas after * or ** in function signatures and calls.
"""
for n in node.pre_order():
if n.type == token.STRING:
"""
for n in node.pre_order():
if n.type == token.STRING:
- n.type == syms.typedargslist
+ n.type in {syms.typedargslist, syms.arglist}
and n.children
and n.children[-1].type == token.COMMA
):
and n.children
and n.children[-1].type == token.COMMA
):
if ch.type in STARS:
return True
if ch.type in STARS:
return True
+ if ch.type == syms.argument:
+ for argch in ch.children:
+ if argch.type in STARS:
+ return True
+
C: 0.1 * (10.0 / 12),
D: 0.1 * (10.0 / 12),
}
C: 0.1 * (10.0 / 12),
D: 0.1 * (10.0 / 12),
}
+def f(
+ a,
+ **kwargs,
+) -> A:
+ return A(
+ very_long_argument_name1=very_long_value_for_the_argument,
+ very_long_argument_name2=very_long_value_for_the_argument,
+ **kwargs,
+ )
C: 0.1 * (10.0 / 12),
D: 0.1 * (10.0 / 12),
}
C: 0.1 * (10.0 / 12),
D: 0.1 * (10.0 / 12),
}
+
+
+def f(a, **kwargs) -> A:
+ return A(
+ very_long_argument_name1=very_long_value_for_the_argument,
+ very_long_argument_name2=very_long_value_for_the_argument,
+ **kwargs,
+ )
--- /dev/null
+def f(
+ a,
+ **kwargs,
+) -> A:
+ return A(
+ very_long_argument_name1=very_long_value_for_the_argument,
+ very_long_argument_name2=very_long_value_for_the_argument,
+ **kwargs,
+ )
+
+# output
+
+def f(a, **kwargs) -> A:
+ return A(
+ very_long_argument_name1=very_long_value_for_the_argument,
+ very_long_argument_name2=very_long_value_for_the_argument,
+ **kwargs,
+ )
black.assert_equivalent(source, actual)
black.assert_stable(source, actual, line_length=ll)
black.assert_equivalent(source, actual)
black.assert_stable(source, actual, line_length=ll)
+ @patch("black.dump_to_file", dump_to_stderr)
+ def test_function2(self) -> None:
+ source, expected = read_data("function2")
+ actual = fs(source)
+ self.assertFormatEqual(expected, actual)
+ black.assert_equivalent(source, actual)
+ black.assert_stable(source, actual, line_length=ll)
+
@patch("black.dump_to_file", dump_to_stderr)
def test_expression(self) -> None:
source, expected = read_data("expression")
@patch("black.dump_to_file", dump_to_stderr)
def test_expression(self) -> None:
source, expected = read_data("expression")