* 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.
+
### 18.4a4
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:
return True
elif (
- n.type == syms.typedargslist
+ n.type in {syms.typedargslist, syms.arglist}
and n.children
and n.children[-1].type == token.COMMA
):
if ch.type in STARS:
return True
+ if ch.type == syms.argument:
+ for argch in ch.children:
+ if argch.type in STARS:
+ return True
+
return False
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,
+ )
# output
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)
+ @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")