repo
stringclasses
454 values
file_path
stringlengths
5
201
extension
stringclasses
1 value
content
stringlengths
8
509k
num_lines
int64
3
16.9k
size_bytes
int64
8
511k
black
tests/data/cases/pattern_matching_simple.py
.py
# flags: --minimum-version=3.10 # Cases sampled from PEP 636 examples match command.split(): case [action, obj]: ... # interpret action, obj match command.split(): case [action]: ... # interpret single-verb action case [action, obj]: ... # interpret action, obj match command.sp...
94
2,673
black
tests/data/cases/preview_simplify_power_operator_hugging_long.py
.py
# flags: --preview # This is a copy of `power_op_spacing_long.py` with output adjusted for `simplify_power_operator_hugging`. a = 1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1 b = 1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1 c = 1 ** 1 ** 1 *...
100
2,667
black
tests/data/cases/form_feeds.py
.py
# Warning! This file contains form feeds (ASCII 0x0C, often represented by \f or ^L). # These may be invisible in your editor: ensure you can see them before making changes here. # There's one at the start that'll get stripped # Comment and statement processing is different enough that we'll test variations of bot...
228
1,933
black
tests/data/cases/nested_stub.py
.py
# flags: --pyi import sys class Outer: class InnerStub: ... outer_attr_after_inner_stub: int class Inner: inner_attr: int outer_attr: int if sys.version_info > (3, 7): if sys.platform == "win32": assignment = 1 def function_definition(self): ... def f1(self) -> str: ......
70
1,243
black
tests/data/cases/module_docstring_3.py
.py
"""Single line module-level docstring should be followed by single newline.""" a = 1 # output """Single line module-level docstring should be followed by single newline.""" a = 1
8
181
black
tests/data/cases/fmtskip6.py
.py
class A: def f(self): for line in range(10): if True: pass # fmt: skip # output class A: def f(self): for line in range(10): if True: pass # fmt: skip
14
235
black
tests/data/cases/remove_with_brackets.py
.py
with (open("bla.txt")): pass with (open("bla.txt")), (open("bla.txt")): pass with (open("bla.txt") as f): pass # Remove brackets within alias expression with (open("bla.txt")) as f: pass # Remove brackets around one-line context managers with (open("bla.txt") as f, (open("x"))): pass with ((ope...
146
2,869
black
tests/data/cases/pep_750_nested_quotes.py
.py
# flags: --minimum-version=3.14 # Regression test for t-strings whose replacement fields contain quotes. # Normalising the outer quotes would escape the inner ones and produce a # t-string that no longer parses, so these are left alone. x = t'\'{a["b"]}\'' y = t'\'{"x"}\'' # The same applies when the replacement field ...
35
1,279
black
tests/data/cases/fmtskip5.py
.py
a, b, c = 3, 4, 5 if ( a == 3 and b != 9 # fmt: skip and c is not None ): print("I'm good!") else: print("I'm bad") # output a, b, c = 3, 4, 5 if ( a == 3 and b != 9 # fmt: skip and c is not None ): print("I'm good!") else: print("I'm bad")
23
301
black
tests/data/cases/pep_572_do_not_remove_parens.py
.py
# flags: --fast # 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_e...
27
514
black
tests/data/cases/fmtskip_multiple_in_clause.py
.py
# Multiple fmt: skip in multi-part if-clause class ClassWithALongName: Constant1 = 1 Constant2 = 2 Constant3 = 3 def test(): if ( "cond1" == "cond1" and "cond2" == "cond2" and 1 in ( ClassWithALongName.Constant1, ClassWithALongName.Constant2, ...
44
871
black
tests/data/cases/preview_remove_multiline_lone_list_item_parens.py
.py
# flags: --unstable items = [(x for x in [1])] items = [ ( {"key1": "val1", "key2": "val2", "key3": "val3"} if some_var == "long strings" else {"key": "val"} ) ] items = [ ( {"key1": "val1", "key2": "val2"} if some_var == "" else {"key": "val"} ) ] items...
247
5,456
black
tests/data/cases/expression.py
.py
... 'some_string' b'\\xa3' Name None True False 1 1.0 1j True or False True or False or None True and False True and False and None (Name1 and Name2) or Name3 Name1 and Name2 or Name3 Name1 or (Name2 and Name3) Name1 or Name2 and Name3 (Name1 and Name2) or (Name3 and Name4) Name1 and Name2 or Name3 and Name4 Name1 or (...
631
18,624
black
tests/data/cases/preview_simplify_power_operator_hugging.py
.py
# flags: --preview # This is a copy of `power_op_spacing.py`. Remove when `simplify_power_operator_hugging` becomes stable. def function(**kwargs): t = a**2 + b**3 return t ** 2 def function_replace_spaces(**kwargs): t = a **2 + b** 3 + c ** 4 def function_dont_replace_spaces(): {**a, **b, **c} a...
154
3,763
black
tests/data/cases/walrus_in_dict.py
.py
{ "is_update": (up := commit.hash in update_hashes) } # output {"is_update": (up := commit.hash in update_hashes)}
7
120
black
tests/data/cases/fmtskip_class_header.py
.py
class Body(model.BaseBody[ "Keyword", "For", "While", "Group", "If", "Try", "Var", "Return", "Continue", "Break", "model.Message", "Error" ]): # fmt: skip __slots__ = () class Foo(Base[\ "A", "B"\ ]): # fmt: skip def a(self): ... def make_result( first : int, second: str, ): # fmt...
48
844
black
tests/data/cases/composition_no_trailing_comma.py
.py
class C: def test(self) -> None: with patch("black.out", print): self.assertEqual( unstyle(str(report)), "1 file reformatted, 1 file failed to reformat." ) self.assertEqual( unstyle(str(report)), "1 file reformatted, 1 file ...
366
11,174
black
tests/data/cases/fmtskip10.py
.py
def foo(): return "mock" # fmt: skip if True: print("yay") # fmt: skip for i in range(10): print(i) # fmt: skip if True: print("this"); print("that") # fmt: skip while True: print("loop"); break # fmt: skip for x in [1, 2]: print(x); print("done") # fmt: skip def f(x: int): return x # fmt: skip j = 1 # fmt: ...
22
644
black
tests/data/cases/standardize_type_comments.py
.py
def foo( a, #type:int b, #type: str c, # type: List[int] d, # type: Dict[int, str] e, # type: ignore f, # type : ignore g, # type : ignore ): pass # output def foo( a, # type: int b, # type: str c, # type: List[int] d, # type: Dict[int, str] e, ...
23
396
black
tests/data/cases/line_ranges_two_passes.py
.py
# flags: --line-ranges=9-11 # NOTE: If you need to modify this file, pay special attention to the --line-ranges= # flag above as it's formatting specifically these lines. # This is a specific case for Black's two-pass formatting behavior in `format_str`. # The second pass must respect the line ranges before the first ...
28
1,065
black
tests/data/cases/comments_in_blocks.py
.py
# Test cases from: # - https://github.com/psf/black/issues/1798 # - https://github.com/psf/black/issues/1499 # - https://github.com/psf/black/issues/1211 # - https://github.com/psf/black/issues/563 ( lambda # a comment : None ) ( lambda: # b comment None ) ( lambda # a comment : ...
112
2,150
black
tests/data/cases/conditional_expression.py
.py
long_kwargs_single_line = my_function( foo="test, this is a sample value", bar=some_long_value_name_foo_bar_baz if some_boolean_variable else some_fallback_value_foo_bar_baz, baz="hello, this is a another value", ) multiline_kwargs_indented = my_function( foo="test, this is a sample value", bar=som...
205
4,910
black
tests/data/cases/percent_precedence.py
.py
("" % a) ** 2 ("" % a)[0] ("" % a)() ("" % a).b 2 * ("" % a) 2 @ ("" % a) 2 / ("" % a) 2 // ("" % a) 2 % ("" % a) +("" % a) b + ("" % a) -("" % a) b - ("" % a) b + -("" % a) ~("" % a) 2 ** ("" % a) await ("" % a) b[("" % a)] b(("" % a)) # output ("" % a) ** 2 ("" % a)[0] ("" % a)() ("" % a).b 2 * ("" % a) 2 @ ("" % a...
42
485
black
tests/data/cases/preview_prefer_rhs_split_indexed_assignment.py
.py
# flags: --preview # Indexed assignment with a short RHS expression should not get unnecessary parens. dictionary_of_arrays["long_key_name_for_the_example"][ very_long_index_name, index_zero ] = 10 - 5 # Unformatted input: the unnecessary parens should be removed. dictionary_of_arrays["long_key_name_for_the_examp...
95
3,679
black
tests/data/cases/trailing_comma_optional_parens3.py
.py
if True: if True: if True: return _( "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweas " + "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwegqweasdzxcqweasdzxc.", "qweasdzxcqweasdzxcq...
22
967
black
tests/data/cases/long_strings_flag_disabled.py
.py
x = "This is a really long string that can't possibly be expected to fit all together on one line. In fact it may even take up three or more lines... like four or five... but probably just three." x += "This is a really long string that can't possibly be expected to fit all together on one line. In fact it may even ta...
297
11,608
black
tests/data/cases/fmtonoff_comment_only_with.py
.py
# flags: --minimum-version=3.10 with open("bug.txt", "r", encoding="utf-8") as fh1: pass # fmt: off # fmt: on # xxx # fmt: off # fmt: on with open("bug.txt", "r", encoding="utf-8") as fh2: pass def fn(str: str) -> float: match str: case _: pass # output with open("bug.txt", "r", encod...
35
537
black
tests/data/cases/preview_long_strings__regression.py
.py
# flags: --unstable class A: def foo(): result = type(message)("") # Don't merge multiline (e.g. triple-quoted) strings. def foo(): query = ( """SELECT xxxxxxxxxxxxxxxxxxxx(xxx)""" """ FROM xxxxxxxxxxxxxxxx WHERE xxxxxxxxxx AND xxx <> xxxxxxxxxxxxxx()""") # There was a bug where tuple...
1,270
46,702
black
tests/data/cases/comment_after_escaped_newline.py
.py
def bob(): \ # pylint: disable=W9016 pass def bobtwo(): \ \ # some comment here pass # output def bob(): # pylint: disable=W9016 pass def bobtwo(): # some comment here pass
21
216
black
tests/data/cases/py310_pep572.py
.py
# flags: --minimum-version=3.10 x[a:=0] x[a := 0] x[a := 0, b := 1] x[5, b := 0] x[a:=0,b:=1] # output x[a := 0] x[a := 0] x[a := 0, b := 1] x[5, b := 0] x[a := 0, b := 1]
14
173
black
tests/data/cases/pattern_matching_trailing_comma.py
.py
# flags: --minimum-version=3.10 match maybe, multiple: case perhaps, 5: pass case perhaps, 6,: pass match more := (than, one), indeed,: case _, (5, 6): pass case [[5], (6)], [7],: pass case _: pass # output match maybe, multiple: case perhaps, 5: ...
39
547
black
tests/data/cases/pep_572_py39.py
.py
# Unparenthesized walruses are now allowed in set literals & set comprehensions # since Python 3.9 {x := 1, 2, 3} {x4 := x**5 for x in range(7)} # We better not remove the parentheses here (since it's a 3.10 feature) x[(a := 1)] x[(a := 1), (b := 3)]
8
251
black
tests/data/cases/line_ranges_exceeding_end.py
.py
# flags: --line-ranges=6-1000 # NOTE: If you need to modify this file, pay special attention to the --line-ranges= # flag above as it's formatting specifically these lines. def foo1(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parameter_6, parameter_7): pass def foo2(parameter_1, parameter_2, parame...
37
1,276
black
tests/data/cases/unstable_comment_on_optional_parens.py
.py
# Regression for https://github.com/psf/black/issues/3701 # Inline comment on optional parentheses must not migrate across formatter passes. assert some_long_name, ( # long __________________________ comment 'long ___________________________________ string %s' % str(variable)) # Related case from https://git...
28
1,058
black
tests/data/cases/python39.py
.py
@relaxed_decorator[0] def f(): ... @relaxed_decorator[extremely_long_name_that_definitely_will_not_fit_on_one_line_of_standard_length] def f(): ... @extremely_long_variable_name_that_doesnt_fit := complex.expression(with_long="arguments_value_that_wont_fit_at_the_end_of_the_line") def f(): ... # output ...
28
630
black
tests/data/cases/context_managers_autodetect_311.py
.py
# flags: --minimum-version=3.11 # This file uses except* clause in Python 3.11. try: some_call() except* Error as e: pass with \ make_context_manager1() as cm1, \ make_context_manager2() as cm2, \ make_context_manager3() as cm3, \ make_context_manager4() as cm4 \ : pass # output ...
39
585
black
tests/data/cases/one_element_subscript.py
.py
# We should not treat the trailing comma # in a single-element subscript. a: tuple[int,] b = tuple[int,] # The magic comma still applies to multi-element subscripts. c: tuple[int, int,] d = tuple[int, int,] # Magic commas still work as expected for non-subscripts. small_list = [1,] list_of_types = [tuple[int,],] # o...
37
674
black
tests/data/cases/docstring_newline.py
.py
""" 87 characters ............................................................................ """
4
99
black
tests/data/cases/remove_lone_list_item_parens.py
.py
items = [(123)] items = [(True)] items = [(((((True)))))] items = [(((((True,)))))] items = [((((()))))] items = [(x for x in [1])] items = {(123)} items = {(True)} items = {(((((True)))))} # Requires `hug_parens_with_braces_and_square_brackets` unstable style to remove parentheses # around multiline values items = [ ...
158
3,417
black
tests/data/cases/string_prefixes.py
.py
#!/usr/bin/env python3 name = "Łukasz" (f"hello {name}", F"hello {name}") (b"", B"") (u"", U"") (r"", R"") (rf"", fr"", Rf"", fR"", rF"", Fr"", RF"", FR"") (rb"", br"", Rb"", bR"", rB"", Br"", RB"", BR"") def docstring_singleline(): R"""2020 was one hell of a year. The good news is that we were able to""" def...
46
845
black
tests/data/cases/pep_701.py
.py
# flags: --minimum-version=3.12 x = f"foo" x = f'foo' x = f"""foo""" x = f'''foo''' x = f"foo {{ bar {{ baz" x = f"foo {{ {2 + 2}bar {{ baz" x = f'foo {{ {2 + 2}bar {{ baz' x = f"""foo {{ {2 + 2}bar {{ baz""" x = f'''foo {{ {2 + 2}bar {{ baz''' # edge case: FSTRING_MIDDLE containing only whitespace should not be strip...
277
4,699
black
tests/data/cases/comments5.py
.py
while True: if something.changed: do.stuff() # trailing comment # Comment belongs to the `if` block. # This one belongs to the `while` block. # Should this one, too? I guess so. # This one is properly standalone now. for i in range(100): # first we do this if i % 33 == 0: ...
68
1,011
black
tests/data/cases/numeric_literals.py
.py
x = 123456789 x = 123456 x = .1 x = 1. x = 1E+1 x = 1E-1 x = 1.000_000_01 x = 123456789.123456789 x = 123456789.123456789E123456789 x = 123456789E123456789 x = 123456789J x = 123456789.123456789J x = 0XB1ACC x = 0B1011 x = 0O777 x = 0.000000006 x = 10000 x = 133333 # output x = 123456789 x = 123456 x = 0.1 x = 1.0 x ...
40
544
black
tests/data/cases/pep_572_remove_parens.py
.py
if (foo := 0): pass if (foo := 1): pass if (y := 5 + 5): pass y = (x := 0) y += (x := 0) (y := 5 + 5) test: int = (test2 := 2) a, b = (test := (1, 2)) # see also https://github.com/psf/black/issues/2139 assert (foo := 42 - 12) foo(x=(y := f(x))) def foo(answer=(p := 42)): ... def foo2(answe...
142
1,888
black
tests/data/cases/funcdef_return_type_trailing_comma.py
.py
# flags: --minimum-version=3.10 # normal, short, function definition def foo(a, b) -> tuple[int, float]: ... # normal, short, function definition w/o return type def foo(a, b): ... # no splitting def foo(a: A, b: B) -> list[p, q]: pass # magic trailing comma in param list def foo(a, b,): ... # magic trailin...
303
5,777
black
tests/data/cases/pep_646.py
.py
# flags: --minimum-version=3.11 A[*b] A[*b] = 1 A del A[*b] A A[*b, *b] A[*b, *b] = 1 A del A[*b, *b] A A[b, *b] A[b, *b] = 1 A del A[b, *b] A A[*b, b] A[*b, b] = 1 A del A[*b, b] A A[b, b, *b] A[b, b, *b] = 1 A del A[b, b, *b] A A[*b, b, b] A[*b, b, b] = 1 A del A[*b, b, b] A A[b, *b, b] A[b, *b, b] = 1 A del A[b, *b,...
196
2,146
black
tests/data/cases/function_trailing_comma.py
.py
def f(a,): d = {'key': 'value',} tup = (1,) def f2(a,b,): d = {'key': 'value', 'key2': 'value2',} tup = (1,2,) def f(a:int=1,): call(arg={'explode': 'this',}) call2(arg=[1,2,3],) x = { "a": 1, "b": 2, }["a"] if a == {"a": 1,"b": 2,"c": 3,"d": 4,"e": 5,"f": 6,"g": 7,...
309
5,318
black
tests/data/cases/line_ranges_indentation.py
.py
# flags: --line-ranges=5-5 # NOTE: If you need to modify this file, pay special attention to the --line-ranges= # flag above as it's formatting specifically these lines. if cond1: print("first") if cond2: print("second") else: print("else") if another_cond: print("will not be changed") # output # fla...
28
633
black
tests/data/cases/backslash_before_indent.py
.py
# flags: --minimum-version=3.10 class Plotter: \ pass class AnotherCase: \ """Some \ Docstring """ # output class Plotter: pass class AnotherCase: """Some \ Docstring """
25
219
black
tests/data/cases/preview_long_dict_values.py
.py
# flags: --preview x = { "xx_xxxxx_xxxxxxxxxx_xxxxxxxxx_xx": ( "xx:xxxxxxxxxxxxxxxxx_xxxxx_xxxxxxx_xxxxxxxxxxx{xx}xxx_xxxxx_xxxxxxxxx_xxxxxxxxxxxx_xxxx" ) } x = { "xx_xxxxx_xxxxxxxxxx_xxxxxxxxx_xx": ( "xx:xxxxxxxxxxxxxxxxx_xxxxx_xxxxxxx_xxxxxxxxxxx{xx}xxx_xxxxx_xxxxxxxxx_xxxxxxxxxxxx_xxxx" ...
304
8,191
black
tests/data/cases/starred_for_target.py
.py
# flags: --minimum-version=3.10 for x in *a, *b: print(x) for x in a, b, *c: print(x) for x in *a, b, c: print(x) for x in *a, b, *c: print(x) async for x in *a, *b: print(x) async for x in *a, b, *c: print(x) async for x in a, b, *c: print(x) async for x in ( *loooooooooooooooooo...
29
412
black
tests/data/cases/pep_654.py
.py
# flags: --minimum-version=3.11 try: raise OSError("blah") except* ExceptionGroup as e: pass try: async with trio.open_nursery() as nursery: # Make two concurrent calls to child() nursery.start_soon(child) nursery.start_soon(child) except* ValueError: pass try: try: ...
55
1,004
black
tests/data/cases/trailing_comma_optional_parens1.py
.py
if e1234123412341234.winerror not in (_winapi.ERROR_SEM_TIMEOUT, _winapi.ERROR_PIPE_BUSY) or _check_timeout(t): pass if x: if y: new_id = max(Vegetable.objects.order_by('-id')[0].id, Mineral.objects.order_by('-id')[0].id) + 1 class X: def get_help_text(...
64
1,615
black
tests/data/cases/if_guard_inside_case.py
.py
# flags: --preview def f(x): match x: # good refactor case [ y ] if y == 123: pass case [ y ] if True: pass case [ y, ] if True: pass # bad refactor case [ ...
50
675
black
tests/data/cases/skip_magic_trailing_comma_generic_wrap.py
.py
# flags: --minimum-version=3.12 --skip-magic-trailing-comma def plain[T, B](a: T, b: T) -> T: return a def arg_magic[T, B](a: T, b: T,) -> T: return a def type_param_magic[T, B,](a: T, b: T) -> T: return a def both_magic[T, B,](a: T, b: T,) -> T: return a def plain_multiline[ T, B ]( a:...
164
2,150
black
tests/data/cases/format_unicode_escape_seq.py
.py
x = "\x1F" x = "\\x1B" x = "\\\x1B" x = "\U0001F60E" x = "\u0001F60E" x = r"\u0001F60E" x = "don't format me" x = "\xA3" x = "\u2717" x = "\uFaCe" x = "\N{ox}\N{OX}" x = "\N{lAtIn smaLL letteR x}" x = "\N{CYRILLIC small LETTER BYELORUSSIAN-UKRAINIAN I}" x = b"\x1Fdon't byte" x = rb"\x1Fdon't format" # output x = "\x1...
34
613
black
tests/data/cases/context_managers_autodetect_39.py
.py
# This file uses parenthesized context managers introduced in Python 3.9. with \ make_context_manager1() as cm1, \ make_context_manager2() as cm2, \ make_context_manager3() as cm3, \ make_context_manager4() as cm4 \ : pass with ( new_new_new1() as cm1, new_new_new2() ): pass ...
35
623
black
tests/data/cases/cantfit.py
.py
# long variable name this_is_a_ridiculously_long_name_and_nobody_in_their_right_mind_would_use_one_like_it = 0 this_is_a_ridiculously_long_name_and_nobody_in_their_right_mind_would_use_one_like_it = 1 # with a comment this_is_a_ridiculously_long_name_and_nobody_in_their_right_mind_would_use_one_like_it = [ 1, 2, 3...
101
3,523
black
tests/data/cases/numeric_literals_skip_underscores.py
.py
x = 123456789 x = 1_2_3_4_5_6_7 x = 1E+1 x = 0xb1acc x = 0.00_00_006 x = 12_34_567J x = .1_2 x = 1_2. # output x = 123456789 x = 1_2_3_4_5_6_7 x = 1e1 x = 0xB1ACC x = 0.00_00_006 x = 12_34_567j x = 0.1_2 x = 1_2.0
19
215
black
tests/data/cases/line_ranges_outside_source.py
.py
# flags: --line-ranges=5000-6000 # NOTE: If you need to modify this file, pay special attention to the --line-ranges= # flag above as it's formatting specifically these lines, in this case none. def foo1(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parameter_6, parameter_7): pass def foo2(parameter_...
8
619
black
tests/data/cases/context_managers_autodetect_38.py
.py
# This file doesn't use any Python 3.9+ only grammars. # Make sure parens around a single context manager don't get autodetected as # Python 3.9+. with (a): pass with \ make_context_manager1() as cm1, \ make_context_manager2() as cm2, \ make_context_manager3() as cm3, \ make_context_manager4...
47
1,058
black
tests/data/cases/module_docstring_after_comment.py
.py
#!/python # regression test for #4762 """ docstring """ from __future__ import annotations import os # output #!/python # regression test for #4762 """ docstring """ from __future__ import annotations import os
22
217
black
tests/data/cases/comments3.py
.py
# The percent-percent comments are Spyder IDE cells. # %% def func(): x = """ a really long string """ lcomp3 = [ # This one is actually too long to fit in a single line. element.split("\n", 1)[0] # yup for element in collection.select_elements() # right ...
48
1,573
black
tests/data/cases/keep_newline_after_match.py
.py
# flags: --minimum-version=3.10 def http_status(status): match status: case 400: return "Bad request" case 401: return "Unauthorized" case 403: return "Forbidden" case 404: return "Not found" # output def http_status(status): ...
41
547
black
tests/data/cases/comments_in_comprehensions.py
.py
# Regression tests for https://github.com/psf/black/issues/4296. [ x for # comment x, y in ["AB",] ] [ [ x for x # comment in [ # comment "ABC" ] ] ] { ( lambda # comment x: [ # comment ...
92
948
black
tests/data/cases/multiline_consecutive_open_parentheses_ignore.py
.py
# This is a regression test. Issue #3737 a = ( # type: ignore int( # type: ignore int( # type: ignore int( # type: ignore 6 ) ) ) ) b = ( int( 6 ) ) print( "111") # type: ignore print( "111" ) # type: igno...
41
644
black
tests/data/cases/pattern_matching_with_if_stmt.py
.py
# flags: --minimum-version=3.10 match match: case "test" if case != "not very loooooooooooooog condition": # comment pass match smth: case "test" if "any long condition" != "another long condition" and "this is a long condition": pass case test if "any long condition" != "another long cond...
73
2,180
black
tests/data/cases/comments.py
.py
#!/usr/bin/env python3 # fmt: on # Some license here. # # Has many lines. Many, many lines. # Many, many, many lines. """Module docstring. Possibly also many, many lines. """ import os.path import sys import a from b.c import X # some noqa comment try: import fast except ImportError: import slow as fast ...
97
1,909
black
tests/data/cases/context_managers_38.py
.py
with \ make_context_manager1() as cm1, \ make_context_manager2() as cm2, \ make_context_manager3() as cm3, \ make_context_manager4() as cm4 \ : pass with \ make_context_manager1() as cm1, \ make_context_manager2(), \ make_context_manager3() as cm3, \ make_context_manager4()...
55
1,140
black
tests/data/cases/bytes_docstring.py
.py
def bitey(): b" not a docstring" def bitey2(): b' also not a docstring' def triple_quoted_bytes(): b""" not a docstring""" def triple_quoted_bytes2(): b''' also not a docstring''' def capitalized_bytes(): B" NOT A DOCSTRING" # output def bitey(): b" not a docstring" def bitey2(): b" a...
34
511
black
tests/data/cases/composition.py
.py
class C: def test(self) -> None: with patch("black.out", print): self.assertEqual( unstyle(str(report)), "1 file reformatted, 1 file failed to reformat." ) self.assertEqual( unstyle(str(report)), "1 file reformatted, 1 file ...
180
5,574
black
tests/data/cases/multiline_strings.py
.py
"""cow say""", call(3, "dogsay", textwrap.dedent("""dove coo""" % "cowabunga")) call(3, "dogsay", textwrap.dedent("""dove coo""" % "cowabunga")) call(3, textwrap.dedent("""cow moo""" % "cowabunga"), "dogsay") call(3, "dogsay", textwrap.dedent("""crow caw""" % "cowabunga"),) call(3, textwrap.dedent("""cat ...
540
9,985
black
tests/data/cases/module_docstring_1.py
.py
"""Single line module-level docstring should be followed by single newline.""" a = 1 """I'm just a string so should be followed by 2 newlines.""" b = 2 # output """Single line module-level docstring should be followed by single newline.""" a = 1 """I'm just a string so should be followed by 2 newlines."""...
26
329
black
tests/data/cases/type_aliases.py
.py
# flags: --minimum-version=3.12 type A=int type Gen[T]=list[T] type Alias[T]=lambda: T type And[T]=T and T type IfElse[T]=T if T else T type One = int; type Another = str class X: type InClass = int type = aliased print(type(42)) # output type A = int type Gen[T] = list[T] type Alias[T] = lambda: T type And[T] = T ...
31
458
black
tests/data/cases/comment_type_hint.py
.py
# flags: --no-preview-line-length-1 # split out from comments2 as it does not work with line-length=1, losing the comment a = "type comment with trailing space" # type: str
4
174
black
tests/data/cases/generics_wrapping.py
.py
# flags: --minimum-version=3.12 def plain[T, B](a: T, b: T) -> T: return a def arg_magic[T, B](a: T, b: T,) -> T: return a def type_param_magic[T, B,](a: T, b: T) -> T: return a def both_magic[T, B,](a: T, b: T,) -> T: return a def plain_multiline[ T, B ]( a: T, b: T ) -> T: ret...
308
3,888
black
tests/data/cases/remove_except_parens.py
.py
# These brackets are redundant, therefore remove. try: a.something except (AttributeError) as err: raise err # This is tuple of exceptions. # Although this could be replaced with just the exception, # we do not remove brackets to preserve AST. try: a.something except (AttributeError,) as err: raise err...
80
2,025
black
tests/data/cases/fmtskip_after_bracket_with_comment.py
.py
# A `# fmt: skip` on a line that opens a bracket, combined with a standalone # comment among the bracket's contents, used to crash inside # `is_line_short_enough` with `AttributeError: 'Leaf' object has no attribute # 'bracket_depth'`. The whole statement should now be left untouched. from m import ( # fmt: skip #...
28
465
black
tests/data/cases/stub.py
.py
# flags: --pyi X: int def f(): ... class D: ... class C: ... class B: this_lack_of_newline_should_be_kept: int def b(self) -> None: ... but_this_newline_should_also_be_kept: int class A: attr: int attr2: str def f(self) -> int: ... def g(self) -> str: ... def g(...
153
2,281
black
tests/data/cases/import_line_collapse.py
.py
from middleman.authentication import validate_oauth_token logger = logging.getLogger(__name__) # case 2 comment after import from middleman.authentication import validate_oauth_token #comment logger = logging.getLogger(__name__) # case 3 comment after import from middleman.authentication import validate_oauth_to...
180
2,076
black
tests/data/cases/type_param_defaults.py
.py
# flags: --minimum-version=3.13 type A[T=int] = float type B[*P=int] = float type C[*Ts=int] = float type D[*Ts=*int] = float type D[something_that_is_very_very_very_long=something_that_is_very_very_very_long] = float type D[*something_that_is_very_very_very_long=*something_that_is_very_very_very_long] = float type so...
70
1,705
black
tests/data/cases/pyi_overload_groups.py
.py
# flags: --preview --pyi # # Test cases for blank line handling around overload groups in .pyi files: # - No blank lines between consecutive same-name decorated functions (overloads) # - No blank lines between overloads even when a function has a docstring # - Blank line enforced after an overload group before an unrel...
946
23,105
black
tests/data/cases/type_expansion.py
.py
# flags: --minimum-version=3.12 def f1[T: (int, str)](a,): pass def f2[T: (int, str)](a: int, b,): pass def g1[T: (int,)](a,): pass def g2[T: (int, str, bytes)](a,): pass def g3[T: ((int, str), (bytes,))](a,): pass def g4[T: (int, (str, bytes))](a,): pass def g5[T: ((int,),)](a: int, b,): pass # output def f1[...
61
666
black
tests/data/cases/no_blank_line_before_docstring.py
.py
def line_before_docstring(): """Please move me up""" class LineBeforeDocstring: """Please move me up""" class EvenIfThereIsAMethodAfter: """I'm the docstring""" def method(self): pass class TwoLinesBeforeDocstring: """I want to be treated the same as if I were closer""" class Mu...
66
987
black
tests/data/cases/pep_570.py
.py
def positional_only_arg(a, /): pass def all_markers(a, b, /, c, d, *, e, f): pass def all_markers_with_args_and_kwargs( a_long_one, b_long_one, /, c_long_one, d_long_one, *args, e_long_one, f_long_one, **kwargs, ): pass def all_markers_with_defaults(a, b=1, /, c=2, ...
45
680
black
tests/data/cases/pattern_matching_extras.py
.py
# flags: --minimum-version=3.10 import match match something: case [a as b]: print(b) case [a as b, c, d, e as f]: print(f) case Point(a as b): print(b) case Point(int() as x, int() as y): print(x, y) match = 1 case: int = re.match(something) match re.match(case): ...
103
1,796
black
tests/data/cases/fmtskip8.py
.py
# Make sure a leading comment is not removed. def some_func( unformatted, args ): # fmt: skip print("I am some_func") return 0 # Make sure this comment is not removed. # Make sure a leading comment is not removed. async def some_async_func( unformatted, args): # fmt: skip print("I am some_asyn...
63
1,705
black
tests/data/cases/line_ranges_unwrapping.py
.py
# flags: --line-ranges=5-5 --line-ranges=9-9 --line-ranges=13-13 # NOTE: If you need to modify this file, pay special attention to the --line-ranges= # flag above as it's formatting specifically these lines. alist = [ 1, 2 ] adict = { "key" : "value" } func_call ( arg = value ) # output ...
26
591
black
tests/data/cases/comments2.py
.py
from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import ( MyLovelyCompanyTeamProjectComponent # NOT DRY ) from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import ( MyLovelyCompanyTeamProjectComponent as component # DRY ) # Please keep __all__ alph...
345
7,640
black
tests/data/cases/single_line_format_skip_with_multiple_comments.py
.py
foo = 123 # fmt: skip # noqa: E501 # pylint bar = ( 123 , ( 1 + 5 ) # pylint # fmt:skip ) baz = "a" + "b" # pylint; fmt: skip; noqa: E501 skip_will_not_work = "a" + "b" # pylint fmt:skip skip_will_not_work2 = "a" + "b" # some text; fmt:skip happens to be part of it...
20
646
black
tests/data/cases/fmtonoff2.py
.py
import pytest TmSt = 1 TmEx = 2 # fmt: off # Test data: # Position, Volume, State, TmSt/TmEx/None, [call, [arg1...]] @pytest.mark.parametrize('test', [ # Test don't manage the volume [ ('stuff', 'in') ], ]) def test_fader(test): pass def check_fader(test): pass def verify_fader(tes...
41
604
black
tests/data/cases/skip_magic_trailing_comma.py
.py
# flags: --skip-magic-trailing-comma # We should not remove the trailing comma in a single-element subscript. a: tuple[int,] b = tuple[int,] # But commas in multiple element subscripts should be removed. c: tuple[int, int,] d = tuple[int, int,] # Remove commas for non-subscripts. small_list = [1,] list_of_types = [tu...
112
2,505
black
tests/data/cases/preview_long_strings__edge_case.py
.py
# flags: --unstable some_variable = "This string is long but not so long that it needs to be split just yet" some_variable = 'This string is long but not so long that it needs to be split just yet' some_variable = "This string is long, just long enough that it needs to be split, u get?" some_variable = 'This string is ...
142
6,556
black
tests/data/cases/fmtonoff5.py
.py
# Regression test for https://github.com/psf/black/issues/3129. setup( entry_points={ # fmt: off "console_scripts": [ "foo-bar" "=foo.bar.:main", # fmt: on ] # Includes an formatted indentation. }, ) # Regression test for https://github.com/psf/blac...
176
3,619
black
tests/data/cases/preview_long_strings__east_asian_width.py
.py
# flags: --unstable # The following strings do not have not-so-many chars, but are long enough # when these are rendered in a monospace font (if the renderer respects # Unicode East Asian Width properties). hangul = '코드포인트 수는 적으나 실제 터미널이나 에디터에서 렌더링될 땐 너무 길어서 줄바꿈이 필요한 문자열' hanzi = '中文測試:代碼點數量少,但在真正的終端模擬器或編輯器中呈現時太長,因此需要換...
58
3,183
black
tests/data/cases/pattern_matching_generic.py
.py
# flags: --minimum-version=3.10 re.match() match = a with match() as match: match = f"{match}" re.match() match = a with match() as match: match = f"{match}" def get_grammars(target_versions: Set[TargetVersion]) -> List[Grammar]: if not target_versions: # No target_version specified, so try all g...
109
3,098
black
tests/data/cases/fmtonoff6.py
.py
# Regression test for https://github.com/psf/black/issues/2478. def foo(): arr = ( (3833567325051000, 5, 1, 2, 4229.25, 6, 0), # fmt: off ) # Regression test for https://github.com/psf/black/issues/3458. dependencies = { a: b, # fmt: off } # Regression test for https://github.com/psf...
90
1,245
black
tests/data/cases/yield_singleton_tuple.py
.py
# flags: --preview def f(): yield x, # output def f(): yield (x,)
12
79
black
tests/data/cases/preview_hug_comparator.py
.py
# flags: --preview --line-length=88 # Regression test for https://github.com/psf/black/issues/4514 # Black used to split between a variable and its comparator (`if t / not in`) # whenever the RHS was a bracketed expression that had to break. With the fix, # the comparator stays attached to its left operand and the bra...
135
4,038
black
tests/data/cases/pep_572_slices.py
.py
x[(a:=0):] x[:(a:=0)] # output x[(a := 0) :] x[: (a := 0)]
7
60