repo stringlengths 7 90 | file_url stringlengths 81 315 | file_path stringlengths 4 228 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 14:38:15 2026-01-05 02:33:18 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/f_docstring.py | tests/data/cases/f_docstring.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)}"""
| python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/raw_docstring_no_string_normalization.py | tests/data/cases/raw_docstring_no_string_normalization.py | # flags: --skip-string-normalization
def do_not_touch_this_prefix():
R"""There was a bug where docstring prefixes would be normalized even with -S."""
def do_not_touch_this_prefix2():
FR'There was a bug where docstring prefixes would be normalized even with -S.'
def do_not_touch_this_prefix3():
u'''Ther... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/line_ranges_imports.py | tests/data/cases/line_ranges_imports.py | # flags: --line-ranges=8-8
# 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 test ensures no empty lines are added around import lines.
# It caused an issue before https://github.com/psf/black/pull/3610 is merged.
impor... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/linelength6.py | tests/data/cases/linelength6.py | # flags: --line-length=6
# Regression test for #3427, which reproes only with line length <= 6
def f():
"""
x
"""
| python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/string_prefixes.py | tests/data/cases/string_prefixes.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/trailing_comma.py | tests/data/cases/trailing_comma.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/annotations.py | tests/data/cases/annotations.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:
... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/function2.py | tests/data/cases/function2.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/pep_750.py | tests/data/cases/pep_750.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 ... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/python37.py | tests/data/cases/python37.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/fmtskip4.py | tests/data/cases/fmtskip4.py | a = 2
# fmt: skip
l = [1, 2, 3,]
# output
a = 2
# fmt: skip
l = [
1,
2,
3,
] | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/fmtskip_multiple_in_clause.py | tests/data/cases/fmtskip_multiple_in_clause.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,
... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/walrus_in_dict.py | tests/data/cases/walrus_in_dict.py | # flags: --preview
# This is testing an issue that is specific to the preview style (wrap_long_dict_values_in_parens)
{
"is_update": (up := commit.hash in update_hashes)
}
# output
# This is testing an issue that is specific to the preview style (wrap_long_dict_values_in_parens)
{"is_update": (up := commit.hash in... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/remove_lone_list_item_parens.py | tests/data/cases/remove_lone_list_item_parens.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 = [
... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/cantfit.py | tests/data/cases/cantfit.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/target_version_flag.py | tests/data/cases/target_version_flag.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: ...
| python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/form_feeds.py | tests/data/cases/form_feeds.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/fmtskip_multiple_strings.py | tests/data/cases/fmtskip_multiple_strings.py | # Multiple fmt: skip on string literals
a = (
"this should " # fmt: skip
"be fine"
)
b = (
"this is " # fmt: skip
"not working" # fmt: skip
)
c = (
"and neither " # fmt: skip
"is this " # fmt: skip
"working"
)
d = (
"nor "
"is this " # fmt: skip
"working" # fmt: skip
)
... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/generics_wrapping.py | tests/data/cases/generics_wrapping.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/funcdef_return_type_trailing_comma.py | tests/data/cases/funcdef_return_type_trailing_comma.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/pep_654_style.py | tests/data/cases/pep_654_style.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:
... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/docstring_no_extra_empty_line_before_eof.py | tests/data/cases/docstring_no_extra_empty_line_before_eof.py | # Make sure when the file ends with class's docstring,
# It doesn't add extra blank lines.
class ClassWithDocstring:
"""A docstring."""
| python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/context_managers_autodetect_311.py | tests/data/cases/context_managers_autodetect_311.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
... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/fmtonoff6.py | tests/data/cases/fmtonoff6.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
}
| python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/pep_701.py | tests/data/cases/pep_701.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/multiline_consecutive_open_parentheses_ignore.py | tests/data/cases/multiline_consecutive_open_parentheses_ignore.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/line_ranges_outside_source.py | tests/data/cases/line_ranges_outside_source.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_... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/composition_no_trailing_comma.py | tests/data/cases/composition_no_trailing_comma.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 ... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/preview_long_strings__regression.py | tests/data/cases/preview_long_strings__regression.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | true |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/preview_fstring.py | tests/data/cases/preview_fstring.py | # flags: --unstable
f"{''=}" f'{""=}' | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/long_strings__type_annotations.py | tests/data/cases/long_strings__type_annotations.py | def func(
arg1,
arg2,
) -> Set["this_is_a_very_long_module_name.AndAVeryLongClasName"
".WithAVeryVeryVeryVeryVeryLongSubClassName"]:
pass
def func(
argument: (
"VeryLongClassNameWithAwkwardGenericSubtype[int] |"
"VeryLongClassNameWithAwkwardGenericSubtype[str]"
),
) -> (
... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/keep_newline_after_match.py | tests/data/cases/keep_newline_after_match.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):
... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/module_docstring_3.py | tests/data/cases/module_docstring_3.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
| python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/preview_remove_multiline_lone_list_item_parens.py | tests/data/cases/preview_remove_multiline_lone_list_item_parens.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/fmtskip.py | tests/data/cases/fmtskip.py | a, b = 1, 2
c = 6 # fmt: skip
d = 5
| python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/torture.py | tests/data/cases/torture.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/type_expansion.py | tests/data/cases/type_expansion.py | # flags: --preview --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
# outpu... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/comments2.py | tests/data/cases/comments2.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/docstring.py | tests/data/cases/docstring.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/module_docstring_followed_by_function.py | tests/data/cases/module_docstring_followed_by_function.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
| python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/remove_with_brackets.py | tests/data/cases/remove_with_brackets.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/numeric_literals.py | tests/data/cases/numeric_literals.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 ... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/remove_redundant_parens_in_case_guard.py | tests/data/cases/remove_redundant_parens_in_case_guard.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
):
... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/long_strings_flag_disabled.py | tests/data/cases/long_strings_flag_disabled.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/trailing_comma_optional_parens3.py | tests/data/cases/trailing_comma_optional_parens3.py | if True:
if True:
if True:
return _(
"qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweas "
+ "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwegqweasdzxcqweasdzxc.",
"qweasdzxcqweasdzxcq... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/prefer_rhs_split_reformatted.py | tests/data/cases/prefer_rhs_split_reformatted.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/async_stmts.py | tests/data/cases/async_stmts.py | async def func() -> (int):
return 0
@decorated
async def func() -> (int):
return 0
async for (item) in async_iter:
pass
# output
async def func() -> int:
return 0
@decorated
async def func() -> int:
return 0
async for item in async_iter:
pass
| python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/collections.py | tests/data/cases/collections.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(),
... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/comments_non_breaking_space.py | tests/data/cases/comments_non_breaking_space.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/function.py | tests/data/cases/function.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/function_trailing_comma.py | tests/data/cases/function_trailing_comma.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,... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/pep_646.py | tests/data/cases/pep_646.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,... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/fmtskip9.py | tests/data/cases/fmtskip9.py | print () # fmt: skip
print () # fmt:skip
# output
print () # fmt: skip
print () # fmt:skip
| python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/preview_hug_parens_with_braces_and_square_brackets_no_ll1.py | tests/data/cases/preview_hug_parens_with_braces_and_square_brackets_no_ll1.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/line_ranges_indentation.py | tests/data/cases/line_ranges_indentation.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/context_managers_38.py | tests/data/cases/context_managers_38.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()... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/preview_standardize_type_comments.py | tests/data/cases/preview_standardize_type_comments.py | # flags: --preview
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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/py310_pep572.py | tests/data/cases/py310_pep572.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]
| python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/pep646_typed_star_arg_type_var_tuple.py | tests/data/cases/pep646_typed_star_arg_type_var_tuple.py | # flags: --minimum-version=3.11
def fn(*args: *tuple[*A, B]) -> None:
pass
fn.__annotations__
| python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/empty_lines.py | tests/data/cases/empty_lines.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/conditional_expression.py | tests/data/cases/conditional_expression.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/remove_parens_from_lhs.py | tests/data/cases/remove_parens_from_lhs.py | # flags: --preview
# Remove unnecessary parentheses from LHS of assignments
def a():
return [1, 2, 3]
# Single variable with unnecessary parentheses
(b) = a()[0]
# Tuple unpacking with unnecessary parentheses
(c, *_) = a()
# These should not be changed - parentheses are necessary
(d,) = a() # single-element ... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/pep_654.py | tests/data/cases/pep_654.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:
... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/line_ranges_two_passes.py | tests/data/cases/line_ranges_two_passes.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 ... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/comments3.py | tests/data/cases/comments3.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
... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/line_ranges_basic.py | tests/data/cases/line_ranges_basic.py | # flags: --line-ranges=5-6
# 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, parameter... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/ignore_pyi.py | tests/data/cases/ignore_pyi.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/pattern_matching_with_if_stmt.py | tests/data/cases/pattern_matching_with_if_stmt.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/skip_magic_trailing_comma.py | tests/data/cases/skip_magic_trailing_comma.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/comments8.py | tests/data/cases/comments8.py | # The percent-percent comments are Spyder IDE cells.
# Both `#%%`` and `# %%` are accepted, so `black` standardises
# to the latter.
#%%
# %%
# output
# The percent-percent comments are Spyder IDE cells.
# Both `#%%`` and `# %%` are accepted, so `black` standardises
# to the latter.
# %%
# %%
| python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/line_ranges_fmt_off_overlap.py | tests/data/cases/line_ranges_fmt_off_overlap.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/type_param_defaults.py | tests/data/cases/type_param_defaults.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/preview_cantfit_string.py | tests/data/cases/preview_cantfit_string.py | # flags: --unstable
# long arguments
normal_name = normal_function_name(
"but with super long string arguments that on their own exceed the line limit so there's no way it can ever fit",
"eggs with spam and eggs and spam with eggs with spam and eggs and spam with eggs with spam and eggs and spam with eggs",
... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/pep_572_remove_parens.py | tests/data/cases/pep_572_remove_parens.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/whitespace.py | tests/data/cases/whitespace.py |
# output
| python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/pep_572.py | tests/data/cases/pep_572.py | (a := 1)
(a := a)
if (match := pattern.search(data)) is None:
pass
if match := pattern.search(data):
pass
[y := f(x), y**2, y**3]
filtered_data = [y for x in data if (y := f(x)) is None]
(y := f(x))
y0 = (y1 := f(x))
foo(x=(y := f(x)))
def foo(answer=(p := 42)):
pass
def foo(answer: (p := 42) = 5):
... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/remove_except_types_parens_pre_py314.py | tests/data/cases/remove_except_types_parens_pre_py314.py | # flags: --preview --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
exc... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/typed_params_trailing_comma.py | tests/data/cases/typed_params_trailing_comma.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/context_managers_autodetect_310.py | tests/data/cases/context_managers_autodetect_310.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 \
:
... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/type_aliases.py | tests/data/cases/type_aliases.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 ... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/comments.py | tests/data/cases/comments.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
... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/power_op_newline.py | tests/data/cases/power_op_newline.py | # flags: --line-length=0
importA;()<<0**0#
# output
importA
(
()
<< 0
** 0
) #
| python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/module_docstring_2.py | tests/data/cases/module_docstring_2.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/comment_after_escaped_newline.py | tests/data/cases/comment_after_escaped_newline.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
| python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/beginning_backslash.py | tests/data/cases/beginning_backslash.py | \
print("hello, world")
# output
print("hello, world")
| python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/percent_precedence.py | tests/data/cases/percent_precedence.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/preview_multiline_strings.py | tests/data/cases/preview_multiline_strings.py | # flags: --preview
"""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, textwr... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/split_delimiter_comments.py | tests/data/cases/split_delimiter_comments.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(
... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/preview_fmtpass_imports.py | tests/data/cases/preview_fmtpass_imports.py | # flags: --preview
# Regression test for https://github.com/psf/black/issues/3438
import ast
import collections # fmt: skip
import dataclasses
# fmt: off
import os
# fmt: on
import pathlib
import re # fmt: skip
import secrets
# fmt: off
import sys
# fmt: on
import tempfile
import zoneinfo
| python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/starred_for_target.py | tests/data/cases/starred_for_target.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/type_params.py | tests/data/cases/type_params.py | # flags: --minimum-version=3.12
def func [T ](): pass
async def func [ T ] (): pass
class C[ T ] : pass
def all_in[T : int,U : (bytes, str),* Ts,**P](): pass
def really_long[WhatIsTheLongestTypeVarNameYouCanThinkOfEnoughToMakeBlackSplitThisLine](): pass
def even_longer[WhatIsTheLongestTypeVarNameYouCanThinkOf... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/remove_for_brackets.py | tests/data/cases/remove_for_brackets.py | # Only remove tuple brackets after `for`
for (k, v) in d.items():
print(k, v)
# Don't touch tuple brackets after `in`
for module in (core, _unicodefun):
if hasattr(module, "_verify_python3_env"):
module._verify_python3_env = lambda: None
# Brackets remain for long for loop lines
for (why_would_anyone_... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/docstring_preview.py | tests/data/cases/docstring_preview.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/pep604_union_types_line_breaks.py | tests/data/cases/pep604_union_types_line_breaks.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/python39.py | tests/data/cases/python39.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
... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/pep_572_py39.py | tests/data/cases/pep_572_py39.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)]
| python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/pattern_matching_complex.py | tests/data/cases/pattern_matching_complex.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/fmtskip13.py | tests/data/cases/fmtskip13.py | # flags: --preview
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",
... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/class_blank_parentheses.py | tests/data/cases/class_blank_parentheses.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():
... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/preview_return_annotation_brackets_string.py | tests/data/cases/preview_return_annotation_brackets_string.py | # flags: --unstable
# Long string example
def frobnicate() -> "ThisIsTrulyUnreasonablyExtremelyLongClassName | list[ThisIsTrulyUnreasonablyExtremelyLongClassName]":
pass
# splitting the string breaks if there's any parameters
def frobnicate(a) -> "ThisIsTrulyUnreasonablyExtremelyLongClassName | list[ThisIsTrulyUnr... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.