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/scripts/diff_shades_gha_helper.py | scripts/diff_shades_gha_helper.py | """Helper script for psf/black's diff-shades Github Actions integration.
diff-shades is a tool for analyzing what happens when you run Black on
OSS code capturing it for comparisons or other usage. It's used here to
help measure the impact of a change *before* landing it (in particular
posting a comment on completion ... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/scripts/check_version_in_basics_example.py | scripts/check_version_in_basics_example.py | """
Check that the rev value in the example from ``the_basics.md`` matches
the latest version of Black. This saves us from forgetting to update that
during the release process.
"""
import os
import sys
import commonmark
from bs4 import BeautifulSoup
def main(changes: str, the_basics: str) -> None:
changes_html ... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/scripts/fuzz.py | scripts/fuzz.py | """Property-based tests for Black.
By Zac Hatfield-Dodds, based on my Hypothesmith tool for source code
generation. You can run this file with `python`, `pytest`, or (soon)
a coverage-guided fuzzer I'm working on.
"""
import hypothesmith
from hypothesis import HealthCheck, given, settings
from hypothesis import stra... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/scripts/generate_schema.py | scripts/generate_schema.py | import json
from typing import IO, Any
import click
import black
def generate_schema_from_click(
cmd: click.Command,
) -> dict[str, Any]:
result: dict[str, dict[str, Any]] = {}
for param in cmd.params:
if not isinstance(param, click.Option) or param.is_eager:
continue
assert... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/scripts/check_pre_commit_rev_in_example.py | scripts/check_pre_commit_rev_in_example.py | """
Check that the rev value in the example pre-commit configuration matches
the latest version of Black. This saves us from forgetting to update that
during the release process.
Why can't we just use `rev: stable` and call it a day? Well pre-commit
won't auto update the hook as you may expect (and for good reasons, s... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/scripts/release_tests.py | scripts/release_tests.py | #!/usr/bin/env python3
import unittest
from pathlib import Path
from shutil import rmtree
from tempfile import TemporaryDirectory
from typing import Any
from unittest.mock import Mock, patch
from release import SourceFiles, tuple_calver # type: ignore
class FakeDateTime:
"""Used to mock the date to test genera... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/scripts/__init__.py | scripts/__init__.py | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false | |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/scripts/release.py | scripts/release.py | #!/usr/bin/env python3
"""
Tool to help automate changes needed in commits during and after releases
"""
from __future__ import annotations
import argparse
import logging
import re
import sys
from datetime import datetime
from pathlib import Path
from subprocess import run
LOG = logging.getLogger(__name__)
NEW_VERS... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/gallery/gallery.py | gallery/gallery.py | import atexit
import json
import subprocess
import tarfile
import tempfile
import traceback
import venv
import zipfile
from argparse import ArgumentParser, Namespace
from collections.abc import Generator
from concurrent.futures import ThreadPoolExecutor
from functools import lru_cache, partial
from pathlib import Path
... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/blib2to3/pytree.py | src/blib2to3/pytree.py | # Copyright 2006 Google, Inc. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.
"""
Python parse tree definitions.
This is a very concrete parse tree; we need to keep every token and
even the comments and whitespace between tokens.
There's also a pattern matching implementation here.
"""
# mypy:... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/blib2to3/pygram.py | src/blib2to3/pygram.py | # Copyright 2006 Google, Inc. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.
"""Export the Python grammar and symbols."""
# Python imports
import os
from typing import Union
# Local imports
from .pgen2 import driver
from .pgen2.grammar import Grammar
# Moved into initialize because mypyc can'... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/blib2to3/__init__.py | src/blib2to3/__init__.py | # empty
| python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/blib2to3/pgen2/conv.py | src/blib2to3/pgen2/conv.py | # Copyright 2004-2005 Elemental Security, Inc. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.
# mypy: ignore-errors
"""Convert graminit.[ch] spit out by pgen to Python code.
Pgen is the Python parser generator. It is useful to quickly create a
parser from a grammar file in Python's grammar no... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/blib2to3/pgen2/literals.py | src/blib2to3/pgen2/literals.py | # Copyright 2004-2005 Elemental Security, Inc. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.
"""Safely evaluate Python string literals without using eval()."""
import re
simple_escapes: dict[str, str] = {
"a": "\a",
"b": "\b",
"f": "\f",
"n": "\n",
"r": "\r",
"t": "\t"... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/blib2to3/pgen2/driver.py | src/blib2to3/pgen2/driver.py | # Copyright 2004-2005 Elemental Security, Inc. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.
# Modifications:
# Copyright 2006 Google, Inc. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.
"""Parser driver.
This provides a high-level interface to parse a file into a synta... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/blib2to3/pgen2/token.py | src/blib2to3/pgen2/token.py | """Token constants (from "token.h")."""
from typing import Final
# Taken from Python (r53757) and modified to include some tokens
# originally monkeypatched in by pgen2.tokenize
# --start constants--
ENDMARKER: Final = 0
NAME: Final = 1
NUMBER: Final = 2
STRING: Final = 3
NEWLINE: Final = 4
INDENT: Final = 5
DEDE... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/blib2to3/pgen2/tokenize.py | src/blib2to3/pgen2/tokenize.py | # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006 Python Software Foundation.
# All rights reserved.
# mypy: allow-untyped-defs, allow-untyped-calls
"""Tokenization help for Python programs.
generate_tokens(readline) is a generator that breaks a stream of
text into Python tokens. It accepts a readline-like method ... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/blib2to3/pgen2/parse.py | src/blib2to3/pgen2/parse.py | # Copyright 2004-2005 Elemental Security, Inc. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.
"""Parser engine for the grammar tables generated by pgen.
The grammar table must be loaded first.
See Parser/parser.c in the Python distribution for additional info on
how this parsing engine works.
... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/blib2to3/pgen2/pgen.py | src/blib2to3/pgen2/pgen.py | # Copyright 2004-2005 Elemental Security, Inc. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.
import os
from collections.abc import Iterator, Sequence
from typing import IO, Any, NoReturn, Union
from blib2to3.pgen2 import grammar, token, tokenize
from blib2to3.pgen2.tokenize import TokenInfo
P... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/blib2to3/pgen2/grammar.py | src/blib2to3/pgen2/grammar.py | # Copyright 2004-2005 Elemental Security, Inc. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.
"""This module defines the data structures used to represent a grammar.
These are a bit arcane because they are derived from the data
structures used by Python's 'pgen' parser generator.
There's also ... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/blib2to3/pgen2/__init__.py | src/blib2to3/pgen2/__init__.py | # Copyright 2004-2005 Elemental Security, Inc. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.
"""The pgen2 package."""
| python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/black/handle_ipynb_magics.py | src/black/handle_ipynb_magics.py | """Functions to process IPython magics with."""
import ast
import collections
import dataclasses
import re
import secrets
from functools import lru_cache
from importlib.util import find_spec
from typing import TypeGuard
from black.mode import Mode
from black.output import out
from black.report import NothingChanged
... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/black/lines.py | src/black/lines.py | import itertools
import math
from collections.abc import Callable, Iterator, Sequence
from dataclasses import dataclass, field
from typing import Optional, TypeVar, Union, cast
from black.brackets import COMMA_PRIORITY, DOT_PRIORITY, BracketTracker
from black.mode import Mode, Preview
from black.nodes import (
BRA... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | true |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/black/report.py | src/black/report.py | """
Summarize Black runs to users.
"""
from dataclasses import dataclass
from enum import Enum
from pathlib import Path
from click import style
from black.output import err, out
class Changed(Enum):
NO = 0
CACHED = 1
YES = 2
class NothingChanged(UserWarning):
"""Raised when reformatted code is th... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/black/mode.py | src/black/mode.py | """Data structures configuring Black behavior.
Mostly around Python language feature support per version and Black configuration
chosen by the user.
"""
from dataclasses import dataclass, field
from enum import Enum, auto
from hashlib import sha256
from operator import attrgetter
from typing import Final
from black.... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/black/trans.py | src/black/trans.py | """
String transformers that can split and merge strings.
"""
import re
from abc import ABC, abstractmethod
from collections import defaultdict
from collections.abc import Callable, Collection, Iterable, Iterator, Sequence
from dataclasses import dataclass
from typing import Any, ClassVar, Final, Literal, TypeVar, Uni... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | true |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/black/debug.py | src/black/debug.py | from collections.abc import Iterator
from dataclasses import dataclass, field
from typing import Any, TypeVar, Union
from black.nodes import Visitor
from black.output import out
from black.parsing import lib2to3_parse
from blib2to3.pgen2 import token
from blib2to3.pytree import Leaf, Node, type_repr
LN = Union[Leaf, ... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/black/numerics.py | src/black/numerics.py | """
Formatting numeric literals.
"""
from blib2to3.pytree import Leaf
def format_hex(text: str) -> str:
"""
Formats a hexadecimal string like "0x12B3"
"""
before, after = text[:2], text[2:]
return f"{before}{after.upper()}"
def format_scientific_notation(text: str) -> str:
"""Formats a nume... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/black/output.py | src/black/output.py | """Nice output for Black.
The double calls are for patching purposes in tests.
"""
import json
import re
import tempfile
from typing import Any
from click import echo, style
from mypy_extensions import mypyc_attr
@mypyc_attr(patchable=True)
def _out(message: str | None = None, nl: bool = True, **styles: Any) -> No... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/black/schema.py | src/black/schema.py | import importlib.resources
import json
from typing import Any
def get_schema(tool_name: str = "black") -> Any:
"""Get the stored complete schema for black's settings."""
assert tool_name == "black", "Only black is supported."
pkg = "black.resources"
fname = "black.schema.json"
schema = importlib... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/black/rusty.py | src/black/rusty.py | """An error-handling model influenced by that used by the Rust programming language
See https://doc.rust-lang.org/book/ch09-00-error-handling.html.
"""
from typing import Generic, TypeVar, Union
T = TypeVar("T")
E = TypeVar("E", bound=Exception)
class Ok(Generic[T]):
def __init__(self, value: T) -> None:
... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/black/brackets.py | src/black/brackets.py | """Builds on top of nodes.py to track brackets."""
from collections.abc import Iterable, Sequence
from dataclasses import dataclass, field
from typing import Final, Union
from black.nodes import (
BRACKET,
CLOSING_BRACKETS,
COMPARATORS,
LOGIC_OPERATORS,
MATH_OPERATORS,
OPENING_BRACKETS,
UN... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/black/nodes.py | src/black/nodes.py | """
blib2to3 Node/Leaf transformation-related utility functions.
"""
from collections.abc import Iterator
from typing import Final, Generic, Literal, TypeGuard, TypeVar, Union
from mypy_extensions import mypyc_attr
from black.cache import CACHE_DIR
from black.mode import Mode, Preview
from black.strings import get_s... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/black/__main__.py | src/black/__main__.py | from black import patched_main
patched_main()
| python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/black/const.py | src/black/const.py | DEFAULT_LINE_LENGTH = 88
DEFAULT_EXCLUDES = r"/(\.direnv|\.eggs|\.git|\.hg|\.ipynb_checkpoints|\.mypy_cache|\.nox|\.pytest_cache|\.ruff_cache|\.tox|\.svn|\.venv|\.vscode|__pypackages__|_build|buck-out|build|dist|venv)/" # noqa: B950
DEFAULT_INCLUDES = r"(\.pyi?|\.ipynb)$"
STDIN_PLACEHOLDER = "__BLACK_STDIN_FILENAME__"... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/black/files.py | src/black/files.py | import io
import os
import sys
from collections.abc import Iterable, Iterator, Sequence
from functools import lru_cache
from pathlib import Path
from re import Pattern
from typing import TYPE_CHECKING, Any, Union
from mypy_extensions import mypyc_attr
from packaging.specifiers import InvalidSpecifier, Specifier, Speci... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/black/parsing.py | src/black/parsing.py | """
Parse Python code and perform AST validation.
"""
import ast
import sys
import warnings
from collections.abc import Collection, Iterator
from black.mode import VERSION_TO_FEATURES, Feature, TargetVersion, supports_feature
from black.nodes import syms
from blib2to3 import pygram
from blib2to3.pgen2 import driver
f... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/black/strings.py | src/black/strings.py | """
Simple formatting on strings. Further string formatting code is in trans.py.
"""
import re
import sys
from functools import lru_cache
from re import Match, Pattern
from typing import Final
from black._width_table import WIDTH_TABLE
from blib2to3.pytree import Leaf
STRING_PREFIX_CHARS: Final = "fturbFTURB" # All... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/black/comments.py | src/black/comments.py | import re
from collections.abc import Collection, Iterator
from dataclasses import dataclass
from functools import lru_cache
from typing import Final, Union
from black.mode import Mode, Preview
from black.nodes import (
CLOSING_BRACKETS,
STANDALONE_COMMENT,
STATEMENT,
WHITESPACE,
container_of,
... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/black/__init__.py | src/black/__init__.py | import io
import json
import platform
import re
import sys
import tokenize
import traceback
from collections.abc import (
Collection,
Generator,
MutableMapping,
Sequence,
)
from contextlib import nullcontext
from dataclasses import replace
from datetime import datetime, timezone
from enum import Enum
fr... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | true |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/black/_width_table.py | src/black/_width_table.py | # Generated by make_width_table.py
# wcwidth 0.2.6
# Unicode 15.0.0
from typing import Final
WIDTH_TABLE: Final[list[tuple[int, int, int]]] = [
(0, 0, 0),
(1, 31, -1),
(127, 159, -1),
(768, 879, 0),
(1155, 1161, 0),
(1425, 1469, 0),
(1471, 1471, 0),
(1473, 1474, 0),
(1476, 1477, 0),... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/black/cache.py | src/black/cache.py | """Caching of formatted files with feature-based invalidation."""
import hashlib
import os
import pickle
import sys
import tempfile
from collections.abc import Iterable
from dataclasses import dataclass, field
from pathlib import Path
from typing import NamedTuple
from platformdirs import user_cache_dir
from _black_... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/black/concurrency.py | src/black/concurrency.py | """
Formatting many files at once via multiprocessing. Contains entrypoint and utilities.
NOTE: this module is only imported if we need to format several files at once.
"""
from __future__ import annotations
import asyncio
import logging
import os
import signal
import sys
import traceback
from collections.abc import... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/black/linegen.py | src/black/linegen.py | """
Generating lines of code.
"""
import re
import sys
from collections.abc import Collection, Iterator
from dataclasses import replace
from enum import Enum, auto
from functools import partial, wraps
from typing import Union, cast
from black.brackets import (
COMMA_PRIORITY,
DOT_PRIORITY,
STRING_PRIORITY... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | true |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/black/ranges.py | src/black/ranges.py | """Functions related to Black's formatting by line ranges feature."""
import difflib
from collections.abc import Collection, Iterator, Sequence
from dataclasses import dataclass
from black.nodes import (
LN,
STANDALONE_COMMENT,
Leaf,
Node,
Visitor,
first_leaf,
furthest_ancestor_with_last_l... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/black/resources/__init__.py | src/black/resources/__init__.py | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false | |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/blackd/client.py | src/blackd/client.py | import aiohttp
from aiohttp.typedefs import StrOrURL
import black
_DEFAULT_HEADERS = {"Content-Type": "text/plain; charset=utf-8"}
class BlackDClient:
def __init__(
self,
url: StrOrURL = "http://localhost:9090",
line_length: int | None = None,
skip_source_first_line: bool = False... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/blackd/__main__.py | src/blackd/__main__.py | import blackd
blackd.patched_main()
| python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/blackd/middlewares.py | src/blackd/middlewares.py | from collections.abc import Awaitable, Callable, Iterable
from aiohttp.typedefs import Middleware
from aiohttp.web_middlewares import middleware
from aiohttp.web_request import Request
from aiohttp.web_response import StreamResponse
Handler = Callable[[Request], Awaitable[StreamResponse]]
def cors(allow_headers: It... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/blackd/__init__.py | src/blackd/__init__.py | import asyncio
import logging
from concurrent.futures import Executor, ProcessPoolExecutor
from datetime import datetime, timezone
from functools import cache, partial
from multiprocessing import freeze_support
try:
from aiohttp import web
from multidict import MultiMapping
from .middlewares import cors
e... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/test_ipynb.py | tests/test_ipynb.py | import contextlib
import pathlib
import re
from contextlib import AbstractContextManager
from contextlib import ExitStack as does_not_raise
from dataclasses import replace
import pytest
from _pytest.monkeypatch import MonkeyPatch
from click.testing import CliRunner
from black import (
Mode,
NothingChanged,
... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/test_format.py | tests/test_format.py | from collections.abc import Iterator
from dataclasses import replace
from typing import Any
from unittest.mock import patch
import pytest
import black
from black.mode import TargetVersion
from tests.util import (
all_data_cases,
assert_format,
dump_to_stderr,
read_data,
read_data_with_mode,
)
@p... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/test_trans.py | tests/test_trans.py | from black.trans import iter_fexpr_spans
def test_fexpr_spans() -> None:
def check(
string: str, expected_spans: list[tuple[int, int]], expected_slices: list[str]
) -> None:
spans = list(iter_fexpr_spans(string))
# Checking slices isn't strictly necessary, but it's easier to verify at... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/util.py | tests/util.py | import argparse
import functools
import os
import shlex
import sys
import unittest
from collections.abc import Collection, Iterator
from contextlib import contextmanager
from dataclasses import dataclass, field, replace
from functools import partial
from pathlib import Path
from typing import Any
import black
from bla... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/test_tokenize.py | tests/test_tokenize.py | """Tests for the blib2to3 tokenizer."""
import sys
import textwrap
from dataclasses import dataclass
import black
from blib2to3.pgen2 import token, tokenize
@dataclass
class Token:
type: str
string: str
start: tokenize.Coord
end: tokenize.Coord
def get_tokens(text: str) -> list[Token]:
"""Retu... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/test_docs.py | tests/test_docs.py | """
Test that the docs are up to date.
"""
import re
from collections.abc import Sequence
from itertools import islice
from pathlib import Path
import pytest
from black.mode import UNSTABLE_FEATURES, Preview
DOCS_PATH = Path("docs/the_black_code_style/future_style.md")
def check_feature_list(
lines: Sequenc... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/optional.py | tests/optional.py | """
Allows configuring optional test markers in config, see pyproject.toml.
Run optional tests with `pytest --run-optional=...`.
Mark tests to run only if an optional test ISN'T selected by prepending the mark with
"no_".
You can specify a "no_" prefix straight in config, in which case you can mark tests
to run when... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/conftest.py | tests/conftest.py | import pytest
pytest_plugins = ["tests.optional"]
PRINT_FULL_TREE: bool = False
PRINT_TREE_DIFF: bool = True
def pytest_addoption(parser: pytest.Parser) -> None:
parser.addoption(
"--print-full-tree",
action="store_true",
default=False,
help="print full syntax trees on failed tes... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/test_black.py | tests/test_black.py | #!/usr/bin/env python3
import asyncio
import inspect
import io
import itertools
import logging
import multiprocessing
import os
import re
import sys
import textwrap
import types
from collections.abc import Callable, Iterator, Sequence
from concurrent.futures import ThreadPoolExecutor
from contextlib import contextmana... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | true |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/__init__.py | tests/__init__.py | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false | |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/test_schema.py | tests/test_schema.py | import importlib.metadata
def test_schema_entrypoint() -> None:
(black_ep,) = importlib.metadata.entry_points(
group="validate_pyproject.tool_schema", name="black"
)
black_fn = black_ep.load()
schema = black_fn()
assert schema == black_fn("black")
assert schema["properties"]["line-len... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/test_ranges.py | tests/test_ranges.py | """Test the black.ranges module."""
import pytest
from black.ranges import adjusted_lines, sanitized_lines
@pytest.mark.parametrize(
"lines",
[[(1, 1)], [(1, 3)], [(1, 1), (3, 4)]],
)
def test_no_diff(lines: list[tuple[int, int]]) -> None:
source = """\
import re
def func():
pass
"""
assert lines =... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/test_blackd.py | tests/test_blackd.py | import gc
import re
from unittest.mock import patch
import pytest
from click.testing import CliRunner
from tests.util import DETERMINISTIC_HEADER, read_data
try:
from aiohttp import web
from aiohttp.test_utils import AioHTTPTestCase
import blackd
import blackd.client
except ImportError as e:
rai... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/test_no_ipynb.py | tests/test_no_ipynb.py | import pathlib
import pytest
from click.testing import CliRunner
from black import jupyter_dependencies_are_installed, main
from tests.util import get_case_path
pytestmark = pytest.mark.no_jupyter
runner = CliRunner()
def test_ipynb_diff_with_no_change_single() -> None:
jupyter_dependencies_are_installed.cach... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/remove_await_parens.py | tests/data/cases/remove_await_parens.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():... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/fmtskip8.py | tests/data/cases/fmtskip8.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... | 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_parens1.py | tests/data/cases/trailing_comma_optional_parens1.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(... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/pep_572_do_not_remove_parens.py | tests/data/cases/pep_572_do_not_remove_parens.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/format_unicode_escape_seq.py | tests/data/cases/format_unicode_escape_seq.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/comments_in_double_parens.py | tests/data/cases/comments_in_double_parens.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 (
... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/power_op_spacing.py | tests/data/cases/power_op_spacing.py | 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 = 5**~4
b = 5 ** f()
c = -(5**2)
d = 5 ** f["hi"]
e = lazy(lambda **kwargs: 5)
f = f() ** 5
g = a.b**c.d
h = 5 ** funcs.f()
... | 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.py | tests/data/cases/line_ranges_fmt_off.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/fmtonoff5.py | tests/data/cases/fmtonoff5.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/comments6.py | tests/data/cases/comments6.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, ... | 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_decorator.py | tests/data/cases/line_ranges_fmt_off_decorator.py | # flags: --line-ranges=12-12 --line-ranges=21-21
# NOTE: If you need to modify this file, pay special attention to the --line-ranges=
# flag above as it's formatting specifically these lines.
# Regression test for an edge case involving decorators and fmt: off/on.
class MyClass:
# fmt: off
@decorator ( )
... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/return_annotation_brackets.py | tests/data/cases/return_annotation_brackets.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/line_ranges_diff_edge_case.py | tests/data/cases/line_ranges_diff_edge_case.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/is_simple_lookup_for_doublestar_expression.py | tests/data/cases/is_simple_lookup_for_doublestar_expression.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/pattern_matching_style.py | tests/data/cases/pattern_matching_style.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)
... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/pattern_matching_simple.py | tests/data/cases/pattern_matching_simple.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/bytes_docstring.py | tests/data/cases/bytes_docstring.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/dummy_implementations.py | tests/data/cases/dummy_implementations.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/module_docstring_1.py | tests/data/cases/module_docstring_1.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."""... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/fmtskip12.py | tests/data/cases/fmtskip12.py | # flags: --preview
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: c... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/comment_type_hint.py | tests/data/cases/comment_type_hint.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
| python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/pattern_matching_long.py | tests/data/cases/pattern_matching_long.py | # flags: --minimum-version=3.10
match x:
case "abcd" | "abcd" | "abcd" :
pass
case "abcd" | "abcd" | "abcd" | "abcd" | "abcd" | "abcd" | "abcd" | "abcd" | "abcd" | "abcd" | "abcd" | "abcd" | "abcd" | "abcd" | "abcd":
pass
case xxxxxxxxxxxxxxxxxxxxxxx:
pass
# output
match x:
cas... | 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_39.py | tests/data/cases/context_managers_autodetect_39.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
... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/attribute_access_on_number_literals.py | tests/data/cases/attribute_access_on_number_literals.py | x = 123456789 .bit_count()
x = (123456).__abs__()
x = .1.is_integer()
x = 1. .imag
x = 1E+1.imag
x = 1E-1.real
x = 123456789.123456789.hex()
x = 123456789.123456789E123456789 .real
x = 123456789E123456789 .conjugate()
x = 123456789J.real
x = 123456789.123456789J.__add__(0b1011.bit_length())
x = 0XB1ACC.conjugate()
x = ... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/tuple_with_stmt.py | tests/data/cases/tuple_with_stmt.py | # don't remove the brackets here, it changes the meaning of the code.
# even though the code will always trigger a runtime error
with (name_5, name_4), name_5:
pass
with c, (a, b):
pass
with c, (a, b), d:
pass
with c, (a, b, e, f, g), d:
pass
def test_tuple_as_contextmanager():
from contextl... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/bracketmatch.py | tests/data/cases/bracketmatch.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/import_spacing.py | tests/data/cases/import_spacing.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 ... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/tricky_unicode_symbols.py | tests/data/cases/tricky_unicode_symbols.py | ä = 1
µ = 2
蟒 = 3
x󠄀 = 4
មុ = 1
Q̇_per_meter = 4
A᧚ = 3
A፩ = 8
| 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.py | tests/data/cases/remove_except_types_parens.py | # flags: --preview --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
exc... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/raw_docstring.py | tests/data/cases/raw_docstring.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"""
| python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/fmtonoff2.py | tests/data/cases/fmtonoff2.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/pattern_matching_generic.py | tests/data/cases/pattern_matching_generic.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... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/preview_import_line_collapse.py | tests/data/cases/preview_import_line_collapse.py | # flags: --preview
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 impor... | 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__east_asian_width.py | tests/data/cases/preview_long_strings__east_asian_width.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 = '中文測試:代碼點數量少,但在真正的終端模擬器或編輯器中呈現時太長,因此需要換... | python | MIT | c3cc5a95d4f72e6ccc27ebae23344fce8cc70786 | 2026-01-04T14:40:23.735327Z | false |
psf/black | https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/tests/data/cases/python38.py | tests/data/cases/python38.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... | 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_parens2.py | tests/data/cases/trailing_comma_optional_parens2.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
| 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.