Code
Hub
Workspaces
Following
Trending
Connect
MCP
copy
Create free account
hub
/
github.com/psf/black
/ functions
Functions
1,067 in github.com/psf/black
⨍
Functions
1,067
◇
Types & classes
148
↳
Endpoints
29
↓ 65 callers
Method
append
Add a new `leaf` to the end of the line. Unless `preformatted` is True, the `leaf` will receive a new consistent whitespace prefix an
src/black/lines.py:61
↓ 44 callers
Function
read_data
read_data('test_name') -> 'input', 'output
tests/util.py:167
↓ 25 callers
Function
assert_format
Convenience function to check that Black formats as expected. You can pass @minimum_version if you're passing code with newer syntax to guard
tests/util.py:64
↓ 24 callers
Function
format_cell
Format code in given cell of Jupyter notebook. General idea is: - if cell has trailing semicolon, remove it; - if cell has IPython m
src/black/__init__.py:968
↓ 24 callers
Method
match
Does this pattern exactly match a node? Returns True if it matches, False if not. If results is not None, it must be a dict
src/blib2to3/pytree.py:554
↓ 22 callers
Function
cache_dir
(exists: bool = True)
tests/test_black.py:81
↓ 19 callers
Function
replace
(m: Match[str])
src/black/strings.py:260
↓ 18 callers
Function
any
(*choices)
src/blib2to3/pgen2/tokenize.py:73
↓ 18 callers
Method
pop
Pop a nonterminal. (Internal)
src/blib2to3/pgen2/parse.py:380
↓ 16 callers
Method
replace
Replace this node with a new one in the parent.
src/blib2to3/pytree.py:136
↓ 15 callers
Function
is_valid_index
Returns: True iff @idx is positive AND seq[@idx] does NOT raise an IndexError.
src/black/trans.py:2400
↓ 15 callers
Method
visit
Main method to visit `node` and its children. It tries to find a `visit_*()` method for the given `node.type`, like `visit_simple_stm
src/black/nodes.py:147
↓ 14 callers
Method
assertFormatEqual
(self, expected: str, actual: str)
tests/util.py:142
↓ 14 callers
Function
get_case_path
Get case path from name
tests/util.py:156
↓ 14 callers
Function
is_valid_index_factory
Examples: ``` my_list = [1, 2, 3] is_valid_index = is_valid_index_factory(my_list) assert is_valid_index(0)
src/black/trans.py:2384
↓ 13 callers
Function
assert_collected_sources
( src: Sequence[Union[str, Path]], expected: Sequence[Union[str, Path]], *, ctx: Optional[Fake
tests/test_black.py:2138
↓ 12 callers
Method
line
Generate a line. If the line is empty, only emit if it makes sense. If the line is too long, split it first and then generate.
src/black/linegen.py:102
↓ 11 callers
Method
visit_default
Default `visit_*()` implementation. Recurses to children of `node`.
src/black/linegen.py:129
↓ 10 callers
Method
comments_after
Generate comments that should appear directly after `leaf`.
src/black/lines.py:398
↓ 10 callers
Method
parse
Pre-conditions: * @leaves[@string_idx].type == token.STRING Returns: The index directly after the last leaf
src/black/trans.py:2253
↓ 9 callers
Function
TErr
(T)ransform Err Convenience function used when working with the TResult type.
src/black/trans.py:79
↓ 9 callers
Method
append
(self)
tests/data/preview/long_strings__regression.py:109
↓ 9 callers
Method
insert_child
Equivalent to 'node.children.insert(i, child)'. This method also sets the child's parent attribute appropriately.
src/blib2to3/pytree.py:344
↓ 9 callers
Method
remove
Remove the node from the tree. Returns the position of the node in its parent's children before it was removed.
src/blib2to3/pytree.py:176
↓ 8 callers
Function
diff
Return a unified diff string between strings `a` and `b`.
src/black/output.py:58
↓ 8 callers
Function
format_file_contents
Reformat contents of a file and return new contents. If `fast` is False, additionally confirm that the reformatted code is valid by calling :
src/black/__init__.py:922
↓ 8 callers
Function
out
(message: Optional[str] = None, nl: bool = True, **styles: Any)
src/black/output.py:33
↓ 7 callers
Method
clone
(self)
src/black/lines.py:449
↓ 7 callers
Method
done
Increment the counter for successful reformatting. Write out a message.
src/black/report.py:35
↓ 7 callers
Function
err
(message: Optional[str] = None, nl: bool = True, **styles: Any)
src/black/output.py:37
↓ 7 callers
Function
parent_type
Returns: @node.parent.type, if @node is not None and has a parent. OR None, otherwise.
src/black/nodes.py:442
↓ 7 callers
Method
path_ignored
(self, path: Path, message: str)
src/black/report.py:56
↓ 7 callers
Method
run
Load the grammar tables from the text files written by pgen.
src/blib2to3/pgen2/conv.py:49
↓ 7 callers
Function
wrap_in_parentheses
Wrap `child` in parentheses. This replaces `child` with an atom holding the parentheses and the old child. That requires moving the prefix.
src/black/nodes.py:827
↓ 6 callers
Function
append_leaves
Append leaves (taken from @old_line) to @new_line, making sure to fix the underlying Node structure where appropriate. All of the leaves
src/black/lines.py:728
↓ 6 callers
Method
changed
(self)
src/blib2to3/pytree.py:169
↓ 6 callers
Method
compare_results
Helper method to test the value and exit code of a click Result.
tests/test_black.py:1785
↓ 6 callers
Method
failed
Increment the counter for failed reformatting. Write out a message.
src/black/report.py:51
↓ 6 callers
Function
get_string_prefix
Pre-conditions: * assert_is_leaf_string(@string) Returns: @string's prefix (e.g. '', 'r', 'f', or 'rf').
src/black/strings.py:99
↓ 6 callers
Method
gettoken
(self)
src/blib2to3/pgen2/pgen.py:362
↓ 6 callers
Method
invalidate_sibling_maps
(self)
src/blib2to3/pytree.py:364
↓ 6 callers
Function
invokeBlack
( args: List[str], exit_code: int = 0, ignore_config: bool = True )
tests/test_black.py:125
↓ 6 callers
Function
is_empty_par
(leaf: Leaf)
src/black/nodes.py:766
↓ 6 callers
Method
load
Load the grammar tables from a pickle file.
src/blib2to3/pgen2/grammar.py:121
↓ 6 callers
Method
loads
Load the grammar tables from a pickle bytes object.
src/blib2to3/pgen2/grammar.py:127
↓ 5 callers
Method
addarc
(self, next: "NFAState", label: Optional[Text] = None)
src/blib2to3/pgen2/pgen.py:384
↓ 5 callers
Function
get_cache_file
(mode: Mode)
src/black/cache.py:58
↓ 5 callers
Function
is_line_short_enough
For non-multiline strings, return True if `line` is no longer than `line_length`. For multiline strings, looks at the context around `line` to det
src/black/lines.py:752
↓ 5 callers
Function
is_multiline_string
Return True if `leaf` is a multiline string that actually spans many lines.
src/black/nodes.py:714
↓ 5 callers
Function
iter_fexpr_spans
Yields spans corresponding to expressions in a given f-string. Spans are half-open ranges (left inclusive, right exclusive). Assumes the
src/black/trans.py:1206
↓ 5 callers
Method
leaves
(self)
src/blib2to3/pytree.py:219
↓ 5 callers
Function
list_comments
Return a list of :class:`ProtoComment` objects parsed from the given `prefix`.
src/black/comments.py:77
↓ 5 callers
Method
max_delimiter_priority
Return the highest priority of a delimiter found on the line. Values are consistent with what `is_split_*_delimiter()` return. Raises
src/black/brackets.py:140
↓ 5 callers
Function
maybe_make_parens_invisible_in_atom
If it's safe, make the parens in the atom `node` invisible, recursively. Additionally, remove repeated, adjacent invisible parens from the atom `n
src/black/linegen.py:1335
↓ 5 callers
Function
read_jupyter_notebook
(subdir_name: str, name: str, data: bool = True)
tests/util.py:191
↓ 5 callers
Function
replace_child
Side Effects: * If @old_child.parent is set, replace @old_child with @new_child in @old_child's underlying Node structure.
src/black/nodes.py:463
↓ 5 callers
Function
type_repr
(type_num: int)
src/blib2to3/pytree.py:40
↓ 4 callers
Function
assert_is_leaf_string
Checks the pre-condition that @string has the format that you would expect of `leaf.value` where `leaf` is some Leaf such that `leaf.type ==
src/black/strings.py:118
↓ 4 callers
Function
change_directory
Context manager to temporarily chdir to a different directory.
tests/util.py:204
↓ 4 callers
Method
contains_standalone_comments
If so, needs to be split before emitting.
src/black/lines.py:219
↓ 4 callers
Method
copy
Copy the grammar.
src/blib2to3/pgen2/grammar.py:131
↓ 4 callers
Function
f
()
tests/data/py_39/python39.py:4
↓ 4 callers
Function
has_triple_quotes
Returns: True iff @string starts with three quotation characters.
src/black/strings.py:44
↓ 4 callers
Function
http_get
(url: str, *, is_json: bool = True, **kwargs: Any)
scripts/diff_shades_gha_helper.py:58
↓ 4 callers
Function
normalize_path_maybe_ignore
Normalize `path`. May return `None` if `path` was ignored. `report` is where "path ignored" output goes.
src/black/files.py:248
↓ 4 callers
Function
normalize_string_quotes
Prefer double quotes but only if it doesn't cause more escaping. Adds or removes backslashes as appropriate. Doesn't parse and fix strings ne
src/black/strings.py:179
↓ 4 callers
Function
preceding_leaf
Return the first leaf that precedes `node`, if any.
src/black/nodes.py:408
↓ 4 callers
Function
read_data_from_file
(file_name: Path)
tests/util.py:172
↓ 3 callers
Method
_get_key
Returns: A unique identifier that is used internally to map @string to a group of custom splits.
src/black/trans.py:314
↓ 3 callers
Function
_get_str_args
(args: List[ast.expr])
src/black/handle_ipynb_magics.py:302
↓ 3 callers
Function
_is_ipython_magic
Check if attribute is IPython magic. Note that the source of the abstract syntax tree will already have been processed by IPython's Trans
src/black/handle_ipynb_magics.py:287
↓ 3 callers
Method
any_open_brackets
Return True if there is an yet unmatched open bracket on the line.
src/black/brackets.py:136
↓ 3 callers
Function
check
( string: str, expected_spans: List[Tuple[int, int]], expected_slices: List[str] )
tests/test_trans.py:7
↓ 3 callers
Function
color_diff
Inject the ANSI color codes to the diff.
src/black/output.py:79
↓ 3 callers
Method
contains_unsplittable_type_ignore
(self)
src/black/lines.py:263
↓ 3 callers
Function
decode_bytes
Return a tuple of (decoded_contents, encoding, newline). `newline` is either CRLF or LF but `decoded_contents` is decoded with universal newl
src/black/__init__.py:1133
↓ 3 callers
Method
dump
Dump the grammar tables to a pickle file.
src/blib2to3/pgen2/grammar.py:100
↓ 3 callers
Function
ensure_visible
Make sure parentheses are visible. They could be invisible as part of some statements (see :func:`normalize_invisible_parens` and :func:`visi
src/black/nodes.py:859
↓ 3 callers
Method
enumerate_with_length
Return an enumeration of leaves with their length. Stops prematurely on multiline strings and standalone comments.
src/black/lines.py:428
↓ 3 callers
Method
expect
(self, type: int, value: Optional[Any] = None)
src/blib2to3/pgen2/pgen.py:353
↓ 3 callers
Function
format_float_or_int_string
Formats a float string like "1.0".
src/black/numerics.py:35
↓ 3 callers
Function
generate_matches
Generator yielding matches for a sequence of patterns and nodes. Args: patterns: a sequence of patterns nodes: a sequence of
src/blib2to3/pytree.py:962
↓ 3 callers
Function
get_cache_info
Return the information used to check if a file is already formatted or not.
src/black/cache.py:62
↓ 3 callers
Function
group
(*choices)
src/blib2to3/pgen2/tokenize.py:69
↓ 3 callers
Function
is_empty_lpar
(leaf: Leaf)
src/black/nodes.py:770
↓ 3 callers
Function
is_empty_rpar
(leaf: Leaf)
src/black/nodes.py:774
↓ 3 callers
Function
is_type_comment
Return True if the given leaf is a special comment. Only returns true for type comments for now.
src/black/nodes.py:819
↓ 3 callers
Function
is_vararg
Return True if `leaf` is a star or double star in a vararg or kwarg. If `within` includes VARARGS_PARENTS, this applies to function signatures.
src/black/nodes.py:691
↓ 3 callers
Function
line_to_string
Returns the string representation of @line. WARNING: This is known to be computationally expensive.
src/black/lines.py:1005
↓ 3 callers
Function
normalize_prefix
Leave existing extra newlines if not `inside_brackets`. Remove everything else. Note: don't use backslashes for formatting or you'll lose you
src/black/linegen.py:1095
↓ 3 callers
Method
ok
(self)
src/black/rusty.py:15
↓ 3 callers
Method
parse_rhs
(self)
src/blib2to3/pgen2/pgen.py:288
↓ 3 callers
Method
pre_order
Return a pre-order iterator for the tree. This must be implemented by the concrete subclass.
src/blib2to3/pytree.py:128
↓ 3 callers
Method
push
Push a nonterminal. (Internal)
src/blib2to3/pgen2/parse.py:368
↓ 3 callers
Function
str_width
Return the width of `line_str` as it would be displayed in a terminal or editor (which respects Unicode East Asian Width). You could utilize
src/black/strings.py:311
↓ 3 callers
Function
supports_feature
(target_versions: Set[TargetVersion], feature: Feature)
src/black/mode.py:149
↓ 3 callers
Function
unwrap_singleton_parenthesis
Returns `wrapped` if `node` is of the shape ( wrapped ). Parenthesis can be optional. Returns None otherwise
src/black/nodes.py:845
↓ 2 callers
Function
_assert_format_equal
(expected: str, actual: str)
tests/util.py:36
↓ 2 callers
Function
_first_right_hand_split
Split the line into head, body, tail starting with the last bracket pair. Note: this function should not have side effects. It's relied upon by
src/black/linegen.py:686
↓ 2 callers
Function
_format_str_once
(src_contents: str, *, mode: Mode)
src/black/__init__.py:1088
next →
1–100 of 1,067, ranked by callers