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/comments_in_double_parens.py
.py
if ( True # sdf ): print("hw") if (( True # sdf )): print("hw") if (( # type: ignore True )): print("hw") if (( True # type: ignore )): print("hw") if ( # a long comment about # the condition below (a or b) ): pass def return_true(): return ( ...
114
1,142
black
tests/data/cases/t_docstring.py
.py
# flags: --minimum-version=3.14 def tea(): t" not a docstring" def tea2(): t' also not a docstring' def triple_quoted_template(): t""" not a docstring """ def triple_quoted_template2(): t''' also not a docstring ''' def raw_template(): rt" not a docstring " def capitalized_tem...
59
871
black
tests/data/cases/ignore_pyi.py
.py
# flags: --pyi def f(): # type: ignore ... class x: # some comment ... class y: ... # comment # whitespace doesn't matter (note the next line has a trailing space and tab) class z: ... def g(): # hi ... def h(): ... # bye # output def f(): # type: ignore ... class...
43
520
black
tests/data/cases/allow_empty_first_line.py
.py
def foo(): """ Docstring """ # Here we go if x: # This is also now fine a = 123 else: # But not necessary a = 123 if y: while True: """ Long comment here """ a = 123 if z: for _ in...
167
1,794
black
tests/data/cases/comments_non_breaking_space.py
.py
from .config import ( ConfigTypeAttributes, Int, Path, #Β String, #Β DEFAULT_TYPE_ATTRIBUTES, ) result = 1 #Β A simple comment result = ( 1, ) #Β Another one result = 1 #Β type: ignore result = 1#Β This comment is talking about type: ignore square = Square(4) #Β type: Optional[Square] def function(a:in...
45
994
black
tests/data/cases/class_methods_new_line.py
.py
class ClassSimplest: pass class ClassWithSingleField: a = 1 class ClassWithJustTheDocstring: """Just a docstring.""" class ClassWithInit: def __init__(self): pass class ClassWithTheDocstringAndInit: """Just a docstring.""" def __init__(self): pass class ClassWithInitAndVars: ...
271
4,318
black
tests/data/cases/remove_await_parens.py
.py
import asyncio # Control example async def main(): await asyncio.sleep(1) # Remove brackets for short coroutine/task async def main(): await (asyncio.sleep(1)) async def main(): await ( asyncio.sleep(1) ) async def main(): await (asyncio.sleep(1) ) # Check comments async def main():...
196
3,538
black
tests/data/cases/power_op_spacing_long.py
.py
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 ** 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 d ...
97
2,500
black
tests/data/cases/target_version_flag.py
.py
# flags: --minimum-version=3.12 --target-version=py312 # this is invalid in versions below py312 class ClassA[T: str]: def method1(self) -> T: ... # output # this is invalid in versions below py312 class ClassA[T: str]: def method1(self) -> T: ...
11
265
black
tests/data/cases/remove_redundant_parens_in_case_guard.py
.py
# flags: --minimum-version=3.10 --line-length=79 match 1: case _ if (True): pass match 1: case _ if ( True ): pass match 1: case _ if ( # this is a comment True ): pass match 1: case _ if ( True # this is a comment ): ...
115
1,486
black
tests/data/cases/preview_long_strings.py
.py
# flags: --unstable 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...
965
37,918
black
tests/data/cases/fmtskip7.py
.py
a = "this is some code" b = 5 # fmt:skip c = 9 #fmt: skip d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasuperlongstring" # fmt:skip # output a = "this is some code" b = 5 # fmt:skip c = 9 #fmt: skip d = "thisisasuperlongstringthisisasuperlong...
12
395
black
tests/data/cases/pattern_matching_complex.py
.py
# flags: --minimum-version=3.10 # Cases sampled from Lib/test/test_patma.py # case black_test_patma_098 match x: case -0j: y = 0 # case black_test_patma_142 match x: case bytes(z): y = 0 # case black_test_patma_073 match x: case 0 if 0: y = 0 case 0 if 1: y = 1 # case bl...
156
2,965
black
tests/data/cases/fstring.py
.py
f"f-string without formatted values is just a string" f"{{NOT a formatted value}}" f"{{NOT 'a' \"formatted\" \"value\"}}" f"some f-string with {a} {few():.2f} {formatted.values!r}" f'some f-string with {a} {few(""):.2f} {formatted.values!r}' f"{f'''{'nested'} inner'''} outer" f"\"{f'{nested} inner'}\" outer" f"space be...
26
989
black
tests/data/cases/empty_lines.py
.py
"""Docstring.""" # leading comment def f(): NO = '' SPACE = ' ' DOUBLESPACE = ' ' t = leaf.type p = leaf.parent # trailing comment v = leaf.value if t in ALWAYS_NO_SPACE: pass if t == token.COMMENT: # another trailing comment return DOUBLESPACE assert p is no...
188
4,597
black
tests/data/cases/class_blank_parentheses.py
.py
class SimpleClassWithBlankParentheses(): pass class ClassWithSpaceParentheses ( ): first_test_data = 90 second_test_data = 100 def test_func(self): return None class ClassWithEmptyFunc(object): def func_with_blank_parentheses(): return 5 def public_func_with_blank_parentheses(): ...
60
1,092
black
tests/data/cases/docstring2.py
.py
def docstring_almost_at_line_limit(): """long docstring................................................................. """ def docstring_almost_at_line_limit_with_prefix(): f"""long docstring................................................................ """ def mulitline_docstring_almost_at_line...
105
3,518
black
tests/data/cases/is_simple_lookup_for_doublestar_expression.py
.py
m2 = None if not isinstance(dist, Normal) else m** 2 + s * 2 m3 = None if not isinstance(dist, Normal) else m ** 2 + s * 2 m4 = None if not isinstance(dist, Normal) else m**2 + s * 2 m5 = obj.method(another_obj.method()).attribute **2 m6 = None if ... else m**2 + s**2 # output m2 = None if not isinstance(dist, Normal...
13
546
black
tests/data/cases/pyi_docstring_blank_lines.py
.py
# flags: --preview --pyi import sys from typing import overload def top_level_comment() -> None: """docs""" # leading comment for the next statement top_level_attr: int def top_level_if() -> None: """docs""" if sys.version_info >= (3, 12): top_level_if_attr: int class C: def before_comment(self) -> N...
165
3,892
black
tests/data/cases/power_op_newline.py
.py
# flags: --line-length=0 importA;()<<0**0# # output importA ( () << 0 ** 0 ) #
12
94
black
tests/data/cases/tupleassign.py
.py
# This is a standalone comment. sdfjklsdfsjldkflkjsf, sdfjsdfjlksdljkfsdlkf, sdfsdjfklsdfjlksdljkf, sdsfsdfjskdflsfsdf = 1, 2, 3 # This is as well. this_will_be_wrapped_in_parens, = struct.unpack(b"12345678901234567890") (a,) = call() # output # This is a standalone comment. ( sdfjklsdfsjldkflkjsf, sdfjsdf...
23
510
black
tests/data/cases/pep_654_style.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: ...
113
2,065
black
tests/data/cases/comments6.py
.py
from typing import Any, Tuple def f( a, # type: int ): pass # test type comments def f(a, b, c, d, e, f, g, h, i): # type: (int, int, int, int, int, int, int, int, int) -> None pass def f( a, # type: int b, # type: int c, # type: int d, # type: int e, # type: int f, ...
119
2,479
black
tests/data/cases/docstring_tabs.py
.py
def test(): """ Test of indentation Testing indentation Yes this is testing Testing again Shocking! Wow! More interesting information """ # output def test(): """ Test of indentation Testing indentation Yes this is testing Testing again Shocking! ...
25
378
black
tests/data/cases/module_docstring_followed_by_function.py
.py
"""Two blank lines between module docstring and a function def.""" def function(): pass # output """Two blank lines between module docstring and a function def.""" def function(): pass
11
196
black
tests/data/cases/trailing_comma_optional_parens2.py
.py
if (e123456.get_tk_patchlevel() >= (8, 6, 0, 'final') or (8, 5, 8) <= get_tk_patchlevel() < (8, 6)): pass # output if e123456.get_tk_patchlevel() >= (8, 6, 0, "final") or ( 8, 5, 8, ) <= get_tk_patchlevel() < (8, 6): pass
13
248
black
tests/data/cases/python38.py
.py
def starred_return(): my_list = ["value2", "value3"] return "value1", *my_list def starred_yield(): my_list = ["value2", "value3"] yield "value1", *my_list # all right hand side expressions allowed in regular assignments are now also allowed in # annotated assignments a : Tuple[ str, int] = "1", 2 a...
40
780
black
tests/data/cases/line_ranges_decorator_edge_case.py
.py
# flags: --line-ranges=6-7 class Foo: @overload def foo(): ... def fox(self): print()
9
108
black
tests/data/cases/fmtskip3.py
.py
a = 3 # fmt: off b, c = 1, 2 d = 6 # fmt: skip e = 5 # fmt: on f = ["This is a very long line that should be formatted into a clearer line ", "by rearranging."] # output a = 3 # fmt: off b, c = 1, 2 d = 6 # fmt: skip e = 5 # fmt: on f = [ "This is a very long line that should be formatted into a...
21
362
black
tests/data/cases/fmtskip12.py
.py
with open("file.txt") as f: content = f.read() # fmt: skip # Ideally, only the last line would be ignored # But ignoring only part of the asexpr_test causes a parse error # Same with ignoring the asexpr_test without also ignoring the entire with_stmt with open ( "file.txt" , ) as f: content = f.read() # ...
20
671
black
tests/data/cases/docstring.py
.py
class MyClass: """ Multiline class docstring """ def method(self): """Multiline method docstring """ pass def foo(): """This is a docstring with some lines of text here """ return def bar(): '''This is another docstring with more lines of text ''' return def b...
458
7,926
black
tests/data/cases/pep_572_py310.py
.py
# flags: --minimum-version=3.10 # Unparenthesized walruses are now allowed in indices since Python 3.10. x[a := 0] x[a := 0, b := 1] x[5, b := 0] # Walruses are allowed inside generator expressions on function calls since 3.10. if any(match := pattern_error.match(s) for s in buffer): if match.group(2) == data_not_...
22
643
black
tests/data/cases/remove_except_types_parens_pre_py314.py
.py
# flags: --minimum-version=3.11 # SEE PEP 758 FOR MORE DETAILS # remains unchanged try: pass except: pass # remains unchanged try: pass except ValueError: pass try: pass except* ValueError: pass # parenthesis are removed try: pass except (ValueError): pass try: pass except* (Valu...
226
2,962
black
tests/data/cases/trailing_comma.py
.py
e = { "a": fun(msg, "ts"), "longggggggggggggggid": ..., "longgggggggggggggggggggkey": ..., "created": ... # "longkey": ... } f = [ arg1, arg2, arg3, arg4 # comment ] g = ( arg1, arg2, arg3, arg4 # comment ) h = { arg1, arg2, arg3, arg4 # comment } # outpu...
56
655
black
tests/data/cases/function.py
.py
#!/usr/bin/env python3 import asyncio import sys from third_party import X, Y, Z from library import some_connection, \ some_decorator f'trigger 3.6 mode' def func_no_args(): a; b; c if True: raise RuntimeError if False: ... for i in range(10): print(i) continue exec("new-style e...
245
6,408
black
tests/data/cases/fmtskip_type_ignore.py
.py
a = 1 # type: ignore b = 1 # fmt: skip
3
41
black
tests/data/cases/import_spacing.py
.py
"""The asyncio package, tracking PEP 3156.""" # flake8: noqa from logging import ( WARNING ) from logging import ( ERROR, ) import sys # This relies on each of the submodules having an __all__ variable. from .base_events import * from .coroutines import * from .events import * # comment here from .futures ...
119
2,542
black
tests/data/cases/string_quotes_escaped_trailing_quote.py
.py
# Regression test for quote normalisation of triple-quoted strings whose body # already ends in an escaped double quote. x = '''\'''\"''' y = b'''\'''\"''' z = '''a\"''' # Here the backslashes escape each other, so the trailing quote is bare and # escaping it would add an escape - the original quotes are kept. w = '''\...
22
687
black
tests/data/cases/pep_604.py
.py
def some_very_long_name_function() -> my_module.Asdf | my_module.AnotherType | my_module.YetAnotherType | None: pass def some_very_long_name_function() -> my_module.Asdf | my_module.AnotherType | my_module.YetAnotherType | my_module.EvenMoreType | None: pass # output def some_very_long_name_function() -> ...
26
583
black
tests/data/cases/context_managers_39.py
.py
with \ make_context_manager1() as cm1, \ make_context_manager2() as cm2, \ make_context_manager3() as cm3, \ make_context_manager4() as cm4 \ : pass # Leading comment with \ make_context_manager1() as cm1, \ make_context_manager2(), \ make_context_manager3() as cm3, \ make_...
186
3,560
black
tests/data/cases/return_annotation_brackets.py
.py
# Control def double(a: int) -> int: return 2*a # Remove the brackets def double(a: int) -> (int): return 2*a # Some newline variations def double(a: int) -> ( int): return 2*a def double(a: int) -> (int ): return 2*a def double(a: int) -> ( int ): return 2*a # Don't lose the comments d...
220
5,207
black
tests/data/cases/bracketmatch.py
.py
for ((x in {}) or {})['a'] in x: pass pem_spam = lambda l, spam = { "x": 3 }: not spam.get(l.strip()) lambda x=lambda y={1: 3}: y['x':lambda y: {1: 2}]: x # output for ((x in {}) or {})["a"] in x: pass pem_spam = lambda l, spam={"x": 3}: not spam.get(l.strip()) lambda x=lambda y={1: 3}: y["x" : lambda y...
16
333
black
tests/data/cases/fmtskip9.py
.py
print () # fmt: skip print () # fmt:skip # output print () # fmt: skip print () # fmt:skip
9
94
black
tests/data/cases/raw_docstring.py
.py
# flags: --skip-string-normalization class C: r"""Raw""" def f(): r"""Raw""" class SingleQuotes: r'''Raw''' class UpperCaseR: R"""Raw""" # output class C: r"""Raw""" def f(): r"""Raw""" class SingleQuotes: r'''Raw''' class UpperCaseR: R"""Raw"""
33
292
black
tests/data/cases/python37.py
.py
def f(): return (i * 2 async for i in arange(42)) def g(): return ( something_long * something_long async for something_long in async_generator(with_an_argument) ) async def func(): await ... if test: out_batched = [ i async for i in aitertools._as...
62
1,173
black
tests/data/cases/line_ranges_fmt_off.py
.py
# flags: --line-ranges=7-7 --line-ranges=17-23 # NOTE: If you need to modify this file, pay special attention to the --line-ranges= # flag above as it's formatting specifically these lines. # fmt: off import os def myfunc( ): # Intentionally unformatted. pass # fmt: on def myfunc( ): # This will not be...
50
1,373
black
tests/data/cases/comments4.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 ) class C: @pytest.ma...
95
3,532
black
tests/data/cases/preview_wrap_comprehension_in.py
.py
# flags: --preview --line-length=79 [a for graph_path_expression in refined_constraint.condition_as_predicate.variables] [ a for graph_path_expression in refined_constraint.condition_as_predicate.variables ] [ a for graph_path_expression in refined_constraint.condition_as_predicate.variables ] [ ...
186
5,581
black
tests/data/cases/annotations.py
.py
# regression test for #1765 class Foo: def foo(self): if True: content_ids: Mapping[ str, Optional[ContentId] ] = self.publisher_content_store.store_config_contents(files) # output # regression test for #1765 class Foo: def foo(self): if True: ...
17
460
black
tests/data/cases/docstring_no_string_normalization.py
.py
# flags: --skip-string-normalization class ALonelyClass: ''' A multiline class docstring. ''' def AnEquallyLonelyMethod(self): ''' A multiline method docstring''' pass def one_function(): '''This is a docstring with a single line of text.''' pass def shockingly_the_qu...
251
3,638
black
tests/data/cases/beginning_backslash.py
.py
\ print("hello, world") # output print("hello, world")
13
63
black
tests/data/cases/type_comment_syntax_error.py
.py
def foo( # type: Foo x): pass # output def foo( # type: Foo x, ): pass
12
93
black
tests/data/cases/line_ranges_diff_edge_case.py
.py
# flags: --line-ranges=10-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. # Reproducible example for https://github.com/psf/black/issues/4033. # This can be fixed in the future if we use a better diffing algorithm, or mak...
29
954
black
tests/data/cases/type_ignore_with_other_comment.py
.py
import pandas as pd interval_td = pd.Interval( pd.Timedelta("1 days"), pd.Timedelta("2 days"), closed="neither" ) _td = ( # pyright: ignore[reportOperatorIssue,reportUnknownVariableType] interval_td - pd.Interval( # type: ignore[operator] pd.Timedelta(1, "ns"), pd.Timedelta(2, "ns") ) ) # o...
28
643
black
tests/data/cases/typed_params_trailing_comma.py
.py
def long_function_name_goes_here( x: Callable[List[int]] ) -> Union[List[int], float, str, bytes, Tuple[int]]: pass def long_function_name_goes_here( x: Callable[[str, Any], int] ) -> Union[List[int], float, str, bytes, Tuple[int]]: pass # output def long_function_name_goes_here( x: Callable[Lis...
24
525
black
tests/data/cases/fmtonoff4.py
.py
# fmt: off @test([ 1, 2, 3, 4, ]) # fmt: on def f(): pass @test([ 1, 2, 3, 4, ]) def f(): pass # output # fmt: off @test([ 1, 2, 3, 4, ]) # fmt: on def f(): pass @test( [ 1, 2, 3, 4, ] ) def f(): pass
37
278
black
tests/data/cases/preview_hug_parens_with_braces_and_square_brackets_no_ll1.py
.py
# flags: --unstable --no-preview-line-length-1 # split out from preview_hug_parens_with_brackes_and_square_brackets, as it produces # different code on the second pass with line-length 1 in many cases. # Seems to be about whether the last string in a sequence gets wrapped in parens or not. foo(*["long long long long lo...
107
4,093
black
tests/data/cases/line_ranges_fmt_off_overlap.py
.py
# flags: --line-ranges=11-17 # 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 myfunc( ): # This will not be reformatted. print( {"also won't be reformatted"} ) # fmt: off def myfunc( ): # This will not be r...
38
1,155
black
tests/data/cases/pattern_matching_case_case_small_line_length.py
.py
# flags: --minimum-version=3.10 --line-length=10 match test: case case if True: pass # output match test: case ( case ) if True: pass
14
173
black
tests/data/cases/comments_in_lambda_default.py
.py
help(lambda x=( # comment "bar", ): False) result = (lambda x=( # a standalone comment 1, 2, 3, ): x) # output help( lambda x=( # comment "bar", ): False, ) result = lambda x=( # a standalone comment 1, 2, 3, ): x
28
274
black
tests/data/cases/slices.py
.py
slice[a.b : c.d] slice[d :: d + 1] slice[d + 1 :: d] slice[d::d] slice[0] slice[-1] slice[:-1] slice[::-1] slice[:c, c - 1] slice[c, c + 1, d::] slice[ham[c::d] :: 1] slice[ham[cheese**2 : -1] : 1 : 1, ham[1:2]] slice[:-1:] slice[lambda: None : lambda: None] slice[lambda x, y, *args, really=2, **kwargs: None :, None::]...
32
787
black
tests/data/cases/dummy_implementations.py
.py
from typing import NoReturn, Protocol, Union, overload class Empty: ... def dummy(a): ... async def other(b): ... @overload def a(arg: int) -> int: ... @overload def a(arg: str) -> str: ... @overload def a(arg: object) -> NoReturn: ... def a(arg: Union[int, str, object]) -> Union[int, str]: if not isinstanc...
250
3,384
black
tests/data/cases/f_docstring.py
.py
def foo(e): f""" {'.'.join(e)}""" def bar(e): f"{'.'.join(e)}" def baz(e): F""" {'.'.join(e)}""" # output def foo(e): f""" {'.'.join(e)}""" def bar(e): f"{'.'.join(e)}" def baz(e): f""" {'.'.join(e)}"""
21
234
black
tests/data/cases/module_docstring_followed_by_class.py
.py
"""Two blank lines between module docstring and a class.""" class MyClass: pass # output """Two blank lines between module docstring and a class.""" class MyClass: pass
11
180
black
tests/data/cases/prefer_rhs_split.py
.py
first_item, second_item = ( some_looooooooong_module.some_looooooooooooooong_function_name( first_argument, second_argument, third_argument ) ) some_dict["with_a_long_key"] = ( some_looooooooong_module.some_looooooooooooooong_function_name( first_argument, second_argument, third_argument ...
119
3,708
black
tests/data/cases/collections.py
.py
import core, time, a from . import A, B, C # keeps existing trailing comma from foo import ( bar, ) # also keeps existing structure from foo import ( baz, qux, ) # `as` works as well from foo import ( xyzzy as magic, ) a = {1,2,3,} b = { 1,2, 3} c = { 1, 2, 3, } x = 1, y = narf(), ...
175
3,294
black
tests/data/cases/preview_hug_parens_with_type_ignore.py
.py
# flags: --unstable # A `type: ignore` is recorded per line by the AST, so hugging must not join two # of them onto one line. foo( # type:ignore [ # type:ignore a ] ) items = [ # type: ignore ( # type: ignore {"key1": "val1", "key2": "val2", "key3": "val3"} if some_var == "longs...
59
1,235
black
tests/data/cases/parenthesized_context_managers.py
.py
# flags: --minimum-version=3.10 with (CtxManager() as example): ... with (CtxManager1(), CtxManager2()): ... with (CtxManager1() as example, CtxManager2()): ... with (CtxManager1(), CtxManager2() as example): ... with (CtxManager1() as example1, CtxManager2() as example2): ... with ( CtxMan...
47
797
black
tests/data/cases/fmtskip13.py
.py
t = ( {"foo": "very long string", "bar": "another very long string", "baz": "we should run out of space by now"}, # fmt: skip {"foo": "bar"}, ) t = ( { "foo": "very long string", "bar": "another very long string", "baz": "we should run out of space by now", }, # fmt: skip ...
63
1,398
black
tests/data/cases/pep604_union_types_line_breaks.py
.py
# flags: --minimum-version=3.10 # This has always worked z= Loooooooooooooooooooooooong | Loooooooooooooooooooooooong | Loooooooooooooooooooooooong | Loooooooooooooooooooooooong # "AnnAssign"s now also work z: Loooooooooooooooooooooooong | Loooooooooooooooooooooooong | Loooooooooooooooooooooooong | Loooooooooooooooooo...
217
5,427
black
tests/data/cases/fmtskip.py
.py
a, b = 1, 2 c = 6 # fmt: skip d = 5
4
40
black
tests/data/cases/context_managers_autodetect_310.py
.py
# flags: --minimum-version=3.10 # This file uses pattern matching introduced in Python 3.10. match http_code: case 404: print("Not found") with \ make_context_manager1() as cm1, \ make_context_manager2() as cm2, \ make_context_manager3() as cm3, \ make_context_manager4() as cm4 \ : ...
37
627
black
tests/data/cases/fmtskip2.py
.py
# flags: --no-preview-line-length-1 # l2 loses the comment with line-length=1 in preview mode l1 = ["This list should be broken up", "into multiple lines", "because it is way too long"] l2 = ["But this list shouldn't", "even though it also has", "way too many characters in it"] # fmt: skip l3 = ["I have", "trailing co...
21
708
black
tests/data/cases/fmtonoff.py
.py
#!/usr/bin/env python3 import asyncio import sys from third_party import X, Y, Z from library import some_connection, \ some_decorator # fmt: off from third_party import (X, Y, Z) # fmt: on f'trigger 3.6 mode' # Comment 1 # Comment 2 # fmt: off def func_no_args(): a; b...
522
11,187
black
tests/data/cases/module_docstring_2.py
.py
"""I am a very helpful module docstring. With trailing spaces: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure do...
70
2,135
black
tests/data/cases/split_delimiter_comments.py
.py
a = ( 1 + # type: ignore 2 # type: ignore ) a = ( 1 # type: ignore + 2 # type: ignore ) bad_split3 = ( "What if we have inline comments on " # First Comment "each line of a bad split? In that " # Second Comment "case, we should just leave it alone." # Third Comment ) parametrize( ...
52
817
black
tests/data/cases/fmtskip_in_parens.py
.py
# Regression tests for https://github.com/psf/black/issues/4513. # Fixed by #4903 ("Improve fmt:skip handling in nested expressions with checks"). # Each of the three inputs below used to crash with a "Cannot parse" error. # Case A: triple-quoted string inside parens with a leading `# fmt: skip` line. ( # fmt: skip ""...
50
1,183
black
tests/data/cases/pep646_typed_star_arg_type_var_tuple.py
.py
# flags: --minimum-version=3.11 def fn(*args: *tuple[*A, B]) -> None: pass fn.__annotations__
9
102
black
tests/data/cases/function2.py
.py
def f( a, **kwargs, ) -> A: with cache_dir(): if something: result = ( CliRunner().invoke(black.main, [str(src1), str(src2), "--diff", "--check"]) ) limited.append(-limited.pop()) # negate top return A( very_long_argument_name1=very_long_value_for...
122
2,419
black
tests/data/cases/fmtonoff3.py
.py
# fmt: off x = [ 1, 2, 3, 4, ] # fmt: on # fmt: off x = [ 1, 2, 3, 4, ] # fmt: on x = [ 1, 2, 3, 4 ] # output # fmt: off x = [ 1, 2, 3, 4, ] # fmt: on # fmt: off x = [ 1, 2, 3, 4, ] # fmt: on x = [1, 2, 3, 4]
36
251
black
tests/data/cases/pattern_matching_style.py
.py
# flags: --minimum-version=3.10 match something: case b(): print(1+1) case c( very_complex=True, perhaps_even_loooooooooooooooooooooooooooooooooooooong=- 1 ): print(1) case c( very_complex=True, perhaps_even_loooooooooooooooooooooooooooooooooooooong=-1, ): print(2) ...
93
1,093
black
tests/data/cases/comments9.py
.py
# Test for https://github.com/psf/black/issues/246. some = statement # This comment should be split from the statement above by two lines. def function(): pass some = statement # This multiline comments section # should be split from the statement # above by two lines. def function(): pass some = statement...
306
5,279
black
tests/data/cases/preview_fmt_off_class_blank_lines.py
.py
# flags: --preview import sys # fmt: off class C: def foo(self): print(sys.platform) # output import sys # fmt: off class C: def foo(self): print(sys.platform)
18
189
black
tests/data/cases/pep_750.py
.py
# flags: --minimum-version=3.14 x = t"foo" x = t'foo {{ {2 + 2}bar {{ baz' x = t"foo {f'abc'} bar" x = t"""foo {{ a foo {2 + 2}bar {{ baz x = f"foo {{ { 2 + 2 # comment }bar" {{ baz }} buzz {print("abc" + "def" )} abc""" t'{(abc:=10)}' t'''This is a really long string, but just ...
84
1,126
black
tests/data/cases/remove_newline_after_code_block_open.py
.py
import random def foo1(): print("The newline above me should be kept!") def foo2(): print("All the newlines above me should be kept!") def foo3(): print("No newline above me!") print("There is a newline above me, and that's OK!") def foo4(): # There is a comment here print("The n...
213
3,218
black
tests/data/cases/prefer_rhs_split_reformatted.py
.py
# Test cases separate from `prefer_rhs_split.py` that contains unformatted source. # Left hand side fits in a single line but will still be exploded by the # magic trailing comma. first_value, (m1, m2,), third_value = xxxxxx_yyyyyy_zzzzzz_wwwwww_uuuuuuu_vvvvvvvvvvv( arg1, arg2, ) # Make when when the left sid...
72
2,119
black
tests/data/cases/fmtskip_in_clause.py
.py
# Single 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 ( # fmt: skip ClassWithALongName.Constant1, ClassWithALongName.Constant2, ...
44
845
black
tests/data/cases/fstring_quotations.py
.py
# Regression tests for long f-strings, including examples from issue #3623 a = ( 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' f'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"{"b"}"' ) a = ( f'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"{"b"}"'...
68
1,664
black
tests/data/cases/linelength6.py
.py
# flags: --line-length=6 # Regression test for #3427, which reproes only with line length <= 6 def f(): """ x """
7
126
black
tests/data/cases/remove_parens.py
.py
x = (1) x = (1.2) data = ( "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ).encode() async def show_status(): while True: try: if report_host: data = ( f"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
143
3,493
black
tests/data/cases/torture.py
.py
importA;() << 0 ** 101234234242352525425252352352525234890264906820496920680926538059059209922523523525 # assert sort_by_dependency( { "1": {"2", "3"}, "2": {"2a", "2b"}, "3": {"3a", "3b"}, "2a": set(), "2b": set(), "3a": set(), "3b": set() } ) == ["2a", "2b", "2", "3a", "3b", "3", "1"] import...
92
2,279
black
tests/data/cases/python315.py
.py
# flags: --fast lazy import json lazy from package.subpackage import ( alpha, beta, gamma, ) from .lazy import thing lazy = "still an identifier" def eager(): lazy = "still an identifier" return lazy flattened = [*item for item in items] generator = (*item for item in items) combined = {*member...
53
919
black
tests/data/cases/tricky_unicode_symbols.py
.py
Γ€ = 1 Β΅ = 2 θŸ’ = 3 xσ „€ = 4 មុ = 1 QΜ‡_per_meter = 4 A᧚ = 3 A፩ = 8
10
80
black
tests/data/cases/remove_except_types_parens.py
.py
# flags: --minimum-version=3.14 # SEE PEP 758 FOR MORE DETAILS # remains unchanged try: pass except: pass # remains unchanged try: pass except ValueError: pass try: pass except* ValueError: pass # parenthesis are removed try: pass except (ValueError): pass try: pass except* (Valu...
250
3,386
black
tests/data/miscellaneous/blackd_diff.py
.py
def abc (): return ["hello", "world", "!"] print( "Incorrect formatting" )
7
98
black
tests/data/miscellaneous/pattern_matching_invalid.py
.py
# First match, no errors match something: case bla(): pass # Problem on line 10 match invalid_case: case valid_case: pass case a := b: pass case valid_case: pass # No problems either match something: case bla(): pass
19
279
black
tests/data/miscellaneous/async_as_identifier.py
.py
def async(): pass def await(): pass await = lambda: None async = lambda: None async() await() def sync_fn(): await = lambda: None async = lambda: None async() await() async def async_fn(): await async_fn() # output def async(): pass def await(): pass await = lambda: Non...
50
495
black
tests/data/miscellaneous/force_pyi.py
.py
# flags: --pyi from typing import Union @bird def zoo(): ... class A: ... @bar class B: def BMethod(self) -> None: ... @overload def BMethod(self, arg : List[str]) -> None: ... class C: ... @hmm class D: ... class E: ... @baz def foo() -> None: ... class F (A , C): ... def spam() -> None: ... @ove...
67
808
black
tests/data/miscellaneous/force_py36.py
.py
# The input source must not contain any Py36-specific syntax (e.g. argument type # annotations, trailing comma after *rest) or this test becomes invalid. def long_function_name(argument_one, argument_two, argument_three, argument_four, argument_five, argument_six, *rest): pass # output # The input source must not conta...
17
600
black
tests/data/miscellaneous/decorators.py
.py
# This file doesn't use the standard decomposition. # Decorator syntax test cases are separated by double # comments. # Those before the 'output' comment are valid under the old syntax. # Those after the 'ouput' comment require PEP614 relaxed syntax. # Do not remove the double # separator before the first test case, it...
182
1,774