black API reference
230 public APIs from black (psf/black) — 27 classes, 109 functions, 94 methods. Signatures extracted by static analysis of the actual source.
Repository: psf/black
| Kind | Count |
|---|---|
| Classes | 27 |
| Functions | 109 |
| Methods | 94 |
API list
func
action.main.determine_version_specifier() -> strDetermine the version of Black to install.
func
src.black.assert_equivalent(src:str, dst:str) -> NoneRaise AssertionError if `src` and `dst` aren't equivalent.
class
src.black.brackets.BracketTrackerKeeps track of brackets on a line.
method
src.black.brackets.BracketTracker.delimiter_count_with_priority(priority:Priority=0) -> intReturn the number of delimiters with the given `priority`.
method
src.black.brackets.BracketTracker.get_open_lsqb() -> Leaf | NoneReturn the most recent opening square bracket (if any).
method
src.black.brackets.BracketTracker.mark(leaf:Leaf) -> NoneMark `leaf` with bracket-related metadata.
method
src.black.brackets.BracketTracker.max_delimiter_priority(exclude:Iterable[LeafID]=()) -> PriorityReturn the highest priority of a delimiter found on the line.
method
src.black.brackets.BracketTracker.maybe_decrement_after_for_loop_variable(leaf:Leaf) -> boolSee `maybe_increment_for_loop_variable` above for explanation.
method
src.black.brackets.BracketTracker.maybe_decrement_after_lambda_arguments(leaf:Leaf) -> boolSee `maybe_increment_lambda_arguments` above for explanation.
method
src.black.brackets.BracketTracker.maybe_increment_for_loop_variable(leaf:Leaf) -> boolIn a for loop, or comprehension, the variables are often unpacks.
method
src.black.brackets.BracketTracker.maybe_increment_lambda_arguments(leaf:Leaf) -> boolIn a lambda expression, there might be more than one argument.
func
src.black.brackets.get_leaves_inside_matching_brackets(leaves:Sequence[Leaf]) -> set[LeafID]Return leaves that are inside matching brackets.
func
src.black.brackets.max_delimiter_priority_in_atom(node:LN) -> PriorityReturn maximum delimiter priority inside `node`.
method
src.black.cache.Cache.filtered_cached(sources:Iterable[Path]) -> tuple[set[Path], set[Path]]Split an iterable of paths in `sources` into two sets.
method
src.black.cache.Cache.get_file_data(path:Path) -> FileDataReturn file data for path.
method
src.black.cache.Cache.hash_digest(path:Path) -> strReturn hash digest for path.
method
src.black.cache.Cache.is_changed(source:Path) -> boolCheck if source has changed compared to cached version.
method
src.black.cache.Cache.read(mode:Mode) -> SelfRead the cache if it exists and is well-formed.
method
src.black.cache.Cache.write(sources:Iterable[Path]) -> NoneUpdate the cache file data and write a new cache file.
func
src.black.cache.get_cache_dir() -> PathGet the cache directory used by black.
func
src.black.check_stability_and_equivalence(src_contents:str, dst_contents:str, *mode:Mode, *lines:Collection[tuple[int, int]]=()) -> NonePerform stability and equivalence checks.
class
src.black.comments.ProtoCommentDescribes a piece of syntax that is a comment.
func
src.black.comments.children_contains_fmt_on(container:LN, mode:Mode) -> boolDetermine if children have formatting switched on.
func
src.black.comments.generate_comments(leaf:LN, mode:Mode) -> Iterator[Leaf]Clean the prefix of the `leaf` and generate comments from it, if any.
func
src.black.comments.is_fmt_on(container:LN, mode:Mode) -> boolDetermine whether formatting is switched on within a container.
func
src.black.comments.make_comment(content:str, mode:Mode) -> strReturn a consistently formatted comment from the given `content` string.
func
src.black.comments.normalize_trailing_prefix(leaf:LN, total_consumed:int) -> NoneNormalize the prefix that's left over after generating comments.
func
src.black.concurrency.cancel(tasks:Iterable[asyncio.Future[Any]]) -> Noneasyncio signal handler that cancels all `tasks` and reports to stderr.
func
src.black.concurrency.shutdown(loop:asyncio.AbstractEventLoop) -> NoneCancel all pending tasks on `loop`, wait for them, and close the loop.
func
src.black.decode_bytes(src:bytes, mode:Mode, *encoding_overwrite:str | None=None) -> tuple[FileContent, Encoding, NewLine]Return a tuple of (decoded_contents, encoding, newline).
func
src.black.detect_target_versions(node:Node, *future_imports:set[str] | None=None) -> set[TargetVersion]Detect the version to target based on the nodes used.
func
src.black.files.find_project_root(srcs:Sequence[str | Path], stdin_filename:str | None=None) -> tuple[Path, str]Return a directory containing .git, .hg, or pyproject.toml.
func
src.black.files.get_gitignore(root:Path) -> GitIgnoreSpecReturn a GitIgnoreSpec matching gitignore content if present.
func
src.black.files.parse_pyproject_toml(path_config:str) -> dict[str, Any]Parse a pyproject toml file, pulling out relevant parts for Black.
func
src.black.files.parse_req_python_specifier(requires_python:str) -> list[TargetVersion] | NoneParse a specifier string (i.e.
func
src.black.files.parse_req_python_version(requires_python:str) -> list[TargetVersion] | NoneParse a version string (i.e.
func
src.black.files.strip_specifier_set(specifier_set:SpecifierSet) -> SpecifierSetStrip minor versions for some specifiers in the specifier set.
func
src.black.format_cell(src:str, *fast:bool, *mode:Mode) -> strFormat code in given cell of Jupyter notebook.
func
src.black.format_file_contents(src_contents:str, *fast:bool, *mode:Mode, *lines:Collection[tuple[int, int]]=()) -> FileContentReformat contents of a file and return new contents.
func
src.black.format_file_in_place(src:Path, fast:bool, mode:Mode, write_back:WriteBack=WriteBack.NO, lock:Any=None, *lines:Collection[tuple[int, int]]=()) -> boolFormat file under `src` path.
func
src.black.format_ipynb_string(src_contents:str, *fast:bool, *mode:Mode) -> FileContentFormat Jupyter notebook.
func
src.black.format_stdin_to_stdout(fast:bool, *content:str | None=None, *write_back:WriteBack=WriteBack.NO, *mode:Mode, *lines:Collection[tuple[int, int]]=()) -> boolFormat file on stdin.
func
src.black.format_str(src_contents:str, *mode:Mode, *lines:Collection[tuple[int, int]]=()) -> strReformat a string and return new contents.
func
src.black.get_features_used(node:Node, *future_imports:set[str] | None=None) -> set[Feature]Return a set of (relatively) new Python features used in this file.
func
src.black.get_future_imports(node:Node) -> set[str]Return a set of __future__ imports in the file.
class
src.black.handle_ipynb_magics.CellMagicFinderFind cell magics.
method
src.black.handle_ipynb_magics.CellMagicFinder.visit_Expr(node:ast.Expr) -> NoneFind cell magic, extract header and body.
class
src.black.handle_ipynb_magics.MagicFinderVisit cell to look for get_ipython calls.
method
src.black.handle_ipynb_magics.MagicFinder.visit_Assign(node:ast.Assign) -> NoneLook for system assign magics.
method
src.black.handle_ipynb_magics.MagicFinder.visit_Expr(node:ast.Expr) -> NoneLook for magics in body of cell.
func
src.black.handle_ipynb_magics.create_token(n_chars:int) -> strCreate a randomly generated token that is n_chars characters long.
func
src.black.handle_ipynb_magics.get_token(src:str, magic:str, existing_tokens:Collection[str]=()) -> strReturn randomly generated token to mask IPython magic with.
func
src.black.handle_ipynb_magics.mask_cell(src:str) -> tuple[str, list[Replacement]]Mask IPython magics so content becomes parseable Python code.
func
src.black.handle_ipynb_magics.put_trailing_semicolon_back(src:str, has_trailing_semicolon:bool) -> strPut trailing semicolon back if cell originally had it.
func
src.black.handle_ipynb_magics.remove_trailing_semicolon(src:str) -> tuple[str, bool]Remove trailing semicolon from Jupyter notebook cell.
func
src.black.handle_ipynb_magics.replace_cell_magics(src:str) -> tuple[str, list[Replacement]]Replace cell magic with token.
func
src.black.handle_ipynb_magics.replace_magics(src:str) -> tuple[str, list[Replacement]]Replace magics within body of cell.
func
src.black.handle_ipynb_magics.unmask_cell(src:str, replacements:list[Replacement]) -> strRemove replacements from cell.
class
src.black.linegen.LineGeneratorGenerates reformatted Line objects.
method
src.black.linegen.LineGenerator.line(indent:int=0) -> Iterator[Line]Generate a line.
method
src.black.linegen.LineGenerator.visit_DEDENT(node:Leaf) -> Iterator[Line]Decrease indentation level, maybe yield a line.
method
src.black.linegen.LineGenerator.visit_ENDMARKER(leaf:Leaf) -> Iterator[Line]End of file.
method
src.black.linegen.LineGenerator.visit_INDENT(node:Leaf) -> Iterator[Line]Increase indentation level, maybe yield a line.
method
src.black.linegen.LineGenerator.visit_SEMI(leaf:Leaf) -> Iterator[Line]Remove a semicolon and put the other statement on a separate line.
method
src.black.linegen.LineGenerator.visit_async_stmt(node:Node) -> Iterator[Line]Visit `async def`, `async for`, `async with`.
method
src.black.linegen.LineGenerator.visit_atom(node:Node) -> Iterator[Line]Visit any atom
method
src.black.linegen.LineGenerator.visit_decorators(node:Node) -> Iterator[Line]Visit decorators.
method
src.black.linegen.LineGenerator.visit_default(node:LN) -> Iterator[Line]Default `visit_*()` implementation.
method
src.black.linegen.LineGenerator.visit_funcdef(node:Node) -> Iterator[Line]Visit function definition.
method
src.black.linegen.LineGenerator.visit_match_case(node:Node) -> Iterator[Line]Visit either a match or case statement.
method
src.black.linegen.LineGenerator.visit_simple_stmt(node:Node) -> Iterator[Line]Visit a statement without nested statements.
method
src.black.linegen.LineGenerator.visit_stmt(node:Node, keywords:set[str], parens:set[str]) -> Iterator[Line]Visit a statement.
method
src.black.linegen.LineGenerator.visit_suite(node:Node) -> Iterator[Line]Visit a suite.
method
src.black.linegen.LineGenerator.visit_test(node:Node) -> Iterator[Line]Visit an `x if y else z` test
func
src.black.linegen.append_to_line(leaf:Leaf) -> Iterator[Line]Append `leaf` to current line or to new line if appending impossible.
func
src.black.linegen.delimiter_split(line:Line, features:Collection[Feature], mode:Mode) -> Iterator[Line]Split according to delimiters of the highest priority.
func
src.black.linegen.remove_with_parens(node:Node, parent:Node, mode:Mode, features:Collection[Feature]) -> NoneRecursively hide optional parens in `with` statements.
func
src.black.linegen.standalone_comment_split(line:Line, features:Collection[Feature], mode:Mode) -> Iterator[Line]Split standalone comments from the rest of the line.
func
src.black.linegen.transform_line(line:Line, mode:Mode, features:Collection[Feature]=()) -> Iterator[Line]Transform a `line`, potentially splitting it into many lines.
class
src.black.lines.LineHolds leaves and comments.
method
src.black.lines.Line.append(leaf:Leaf, preformatted:bool=False, track_bracket:bool=False) -> NoneAdd a new `leaf` to the end of the line.
method
src.black.lines.Line.append_comment(comment:Leaf) -> boolAdd an inline or standalone comment to the line.
method
src.black.lines.Line.comments_after(leaf:Leaf) -> list[Leaf]Generate comments that should appear directly after `leaf`.
method
src.black.lines.Line.contains_standalone_comments() -> boolIf so, needs to be split before emitting.
method
src.black.lines.Line.enumerate_with_length(is_reversed:bool=False) -> Iterator[tuple[Index, Leaf, int]]Return an enumeration of leaves with their length.
method
src.black.lines.Line.is_chained_assignment() -> boolIs the line a chained assignment
method
src.black.lines.Line.is_class() -> boolIs this line a class definition?
method
src.black.lines.Line.is_class_paren_empty() -> boolIs this a class with no base classes but using parentheses?
method
src.black.lines.Line.is_comment() -> boolIs this line a standalone comment?
method
src.black.lines.Line.is_complex_subscript(leaf:Leaf) -> boolReturn True iff `leaf` is part of a slice with non-trivial exprs.
method
src.black.lines.Line.is_decorator() -> boolIs this line a decorator?
method
src.black.lines.Line.is_def() -> boolIs this a function definition?
method
src.black.lines.Line.is_docstring() -> boolIs the line a docstring?
method
src.black.lines.Line.is_fmt_pass_converted(*first_leaf_matches:Callable[[Leaf], bool] | None=None) -> boolIs this line converted from fmt off/skip code?
method
src.black.lines.Line.is_import() -> boolIs this an import line?
method
src.black.lines.Line.is_with_or_async_with_stmt() -> boolIs this a with_stmt line?
method
src.black.lines.Line.opens_block() -> boolDoes this line open a new level of indentation.
method
src.black.lines.Line.remove_trailing_comma() -> NoneRemove the trailing comma and moves the comments attached to it.
class
src.black.lines.LinesBlockClass that holds information about a block of formatted lines.
class
src.black.lines.RHSResultIntermediate split result from a right hand split.
func
src.black.lines.can_be_split(line:Line) -> boolReturn False if the line cannot be split *for sure*.
func
src.black.lines.enumerate_reversed(sequence:Sequence[T]) -> Iterator[tuple[Index, T]]Like `reversed(enumerate(sequence))` if that were possible.
func
src.black.lines.line_to_string(line:Line) -> strReturns the string representation of @line.
class
src.black.mode.PreviewIndividual preview style features.
class
src.black.nodes.VisitorBasic lib2to3 visitor that yields things of type `T` on `visit()`.
method
src.black.nodes.Visitor.visit(node:LN) -> Iterator[T]Main method to visit `node` and its children.
method
src.black.nodes.Visitor.visit_default(node:LN) -> Iterator[T]Default `visit_*()` implementation.
func
src.black.nodes.child_towards(ancestor:Node, descendant:LN) -> LN | NoneReturn the child of `ancestor` that contains `descendant`.
func
src.black.nodes.container_of(leaf:Leaf) -> LNReturn `leaf` or one of its ancestors that is the topmost container of it.
func
src.black.nodes.ensure_visible(leaf:Leaf) -> NoneMake sure parentheses are visible.
func
src.black.nodes.first_leaf(node:LN) -> Leaf | NoneReturns the first leaf of the ancestor node.
func
src.black.nodes.first_leaf_of(node:LN) -> Leaf | NoneReturns the first leaf of the node tree.
func
src.black.nodes.fstring_tstring_to_string(node:Node) -> LeafConverts an fstring or tstring node back to a string node.
func
src.black.nodes.get_annotation_type(leaf:Leaf) -> Literal['return', 'param', None]Returns the type of annotation this leaf is part of, if any.
func
src.black.nodes.is_arith_like(node:LN) -> boolWhether node is an arithmetic or a binary arithmetic expression
func
src.black.nodes.is_async_stmt_or_funcdef(leaf:Leaf) -> boolReturn True if the given leaf starts an async def/for/with statement.
func
src.black.nodes.is_empty_tuple(node:LN) -> boolReturn True if `node` holds an empty tuple.
func
src.black.nodes.is_fstring(node:Node) -> boolReturn True if the node is an f-string
func
src.black.nodes.is_generator(node:LN) -> boolReturn True if `node` holds a generator.
func
src.black.nodes.is_import(leaf:Leaf) -> boolReturn True if the given leaf starts an import statement.
func
src.black.nodes.is_one_tuple(node:LN) -> boolReturn True if `node` holds a tuple with one element, with or without parens.
func
src.black.nodes.is_part_of_annotation(leaf:Leaf) -> boolReturns whether this leaf is part of a type annotation.
func
src.black.nodes.is_simple_decorator_trailer(node:LN, last:bool=False) -> boolReturn True iff `node` is a trailer valid in a simple decorator
func
src.black.nodes.is_simple_exponentiation(node:LN) -> boolWhether whitespace around `**` should be removed.
func
src.black.nodes.is_stub_body(node:LN) -> boolReturn True if `node` is a simple statement containing an ellipsis.
func
src.black.nodes.is_stub_suite(node:Node) -> boolReturn True if `node` is a suite with a stub body.
func
src.black.nodes.is_tuple(node:LN) -> boolReturn True if `node` holds a tuple.
func
src.black.nodes.is_tuple_containing_star(node:LN) -> boolReturn True if `node` holds a tuple that contains a star operator.
func
src.black.nodes.is_tuple_containing_walrus(node:LN) -> boolReturn True if `node` holds a tuple that contains a walrus operator.
func
src.black.nodes.is_type_comment(leaf:Leaf, mode:Mode) -> boolReturn True if the given leaf is a type comment.
func
src.black.nodes.is_vararg(leaf:Leaf, within:set[NodeType]) -> boolReturn True if `leaf` is a star or double star in a vararg or kwarg.
func
src.black.nodes.is_walrus_assignment(node:LN) -> boolReturn True iff `node` is of the shape ( test := test )
func
src.black.nodes.is_with_or_async_with_stmt(leaf:Leaf) -> boolReturn True if the given leaf starts a with or async with statement.
func
src.black.nodes.is_yield(node:LN) -> boolReturn True if `node` holds a `yield` or `yield from` expression.
func
src.black.nodes.last_leaf(node:LN) -> Leaf | NoneReturns the last leaf of the ancestor node.
func
src.black.nodes.make_simple_prefix(nl_count:int, form_feed:bool, empty_line:str='\n') -> strGenerate a normalized prefix string.
func
src.black.nodes.parent_type(node:LN | None) -> NodeType | NoneReturns: @node.parent.type, if @node is not None and has a parent.
func
src.black.nodes.preceding_leaf(node:LN | None) -> Leaf | NoneReturn the first leaf that precedes `node`, if any.
func
src.black.nodes.unwrap_singleton_parenthesis(node:LN) -> LN | NoneReturns `wrapped` if `node` is of the shape ( wrapped ).
func
src.black.nodes.whitespace(leaf:Leaf, *complex_subscript:bool, *mode:Mode) -> strReturn whitespace prefix if needed for the given `leaf`.
func
src.black.nodes.wrap_in_parentheses(parent:Node, child:LN, *visible:bool=True, *index:int | None=None) -> NoneWrap `child` in parentheses.
func
src.black.numerics.format_complex_number(text:str) -> strFormats a complex string like `10j`
func
src.black.numerics.format_float_or_int_string(text:str) -> strFormats a float string like "1.0".
func
src.black.numerics.format_hex(text:str) -> strFormats a hexadecimal string like "0x12B3"
func
src.black.numerics.format_scientific_notation(text:str) -> strFormats a numeric string utilizing scientific notation
func
src.black.numerics.normalize_numeric_literal(leaf:Leaf) -> NoneNormalizes numeric (float, int, and complex) literals.
func
src.black.output.color_diff(contents:str) -> strInject the ANSI color codes to the diff.
func
src.black.output.diff(a:str, b:str, a_name:str, b_name:str) -> strReturn a unified diff string between strings `a` and `b`.
func
src.black.output.dump_to_file(*ensure_final_newline:bool=True, *output:str) -> strDump `output` to a temporary file.
class
src.black.parsing.InvalidInputRaised when input source code fails all parse attempts.
class
src.black.parsing.SourceASTParseErrorRaised when the source file cannot be parsed by ast.parse().
func
src.black.parsing.lib2to3_parse(src_txt:str, target_versions:Collection[TargetVersion]=()) -> NodeGiven a string with source, return the lib2to3 Node.
func
src.black.parsing.stringify_ast(node:ast.AST) -> Iterator[str]Simple visitor generating strings to compare ASTs by content.
func
src.black.ranges.convert_unchanged_lines(src_node:Node, lines:Collection[tuple[int, int]]) -> NoneConverts unchanged lines to STANDALONE_COMMENT.
func
src.black.ranges.is_valid_line_range(lines:tuple[int, int]) -> boolReturns whether the line range is valid.
func
src.black.ranges.sanitized_lines(lines:Collection[tuple[int, int]], src_contents:str) -> Collection[tuple[int, int]]Returns the valid line ranges for the given source.
func
src.black.re_compile_maybe_verbose(regex:str) -> Pattern[str]Compile a regular expression string in `regex`.
class
src.black.report.NothingChangedRaised when reformatted code is the same as source.
class
src.black.report.ReportProvides a reformatting counter.
method
src.black.report.Report.done(src:Path, changed:Changed) -> NoneIncrement the counter for successful reformatting.
method
src.black.report.Report.failed(src:Path, message:BaseException) -> NoneIncrement the counter for failed reformatting.
method
src.black.report.Report.return_code() -> intReturn the exit code that the app should use.
func
src.black.schema.get_schema(tool_name:str='black') -> AnyGet the stored complete schema for black's settings.
func
src.black.strings.has_triple_quotes(string:str) -> boolReturns: True iff @string starts with three quotation characters.
func
src.black.strings.lines_with_leading_tabs_expanded(s:str) -> list[str]Splits string into lines and expands only leading tabs.
func
src.black.strings.normalize_string_prefix(s:str) -> strMake all string prefixes lowercase.
func
src.black.strings.normalize_string_quotes(s:str) -> strPrefer double quotes but only if it doesn't cause more escaping.
func
src.black.strings.sub_twice(regex:Pattern[str], replacement:str, original:str) -> strReplace `regex` with `replacement` twice on `original`.
class
src.black.trans.CannotTransformBase class for errors raised by Transformers.
class
src.black.trans.CustomSplitA custom (i.e.
class
src.black.trans.StringMergerStringTransformer that merges strings together.
func
src.black.trans.StringMerger.make_naked(string:str, string_prefix:str) -> strStrip @string (i.e.
class
src.black.trans.StringSplitterStringTransformer that splits "atom" strings (i.e.
func
src.black.trans.hug_power_op(line:Line, features:Collection[Feature], mode:Mode) -> Iterator[Line]A transformer which normalizes spacing around power operators.
func
src.black.trans.is_expression_chained(chained_leaves:list[Leaf]) -> boolFunction to determine if the variable is a chained call.
func
src.black.trans.iter_fexpr_spans(s:str) -> Iterator[tuple[int, int]]Yields spans corresponding to expressions in a given f-string.
func
src.black.validate_metadata(nb:MutableMapping[str, Any]) -> NoneIf notebook is marked as non-Python, don't format it.
class
src.blib2to3.pgen2.conv.ConverterGrammar subclass that reads classic pgen output files.
method
src.blib2to3.pgen2.conv.Converter.finish_off()Create additional useful structures.
method
src.blib2to3.pgen2.conv.Converter.parse_graminit_c(filename)Parse the .c file written by pgen.
method
src.blib2to3.pgen2.conv.Converter.parse_graminit_h(filename)Parse the .h file written by pgen.
method
src.blib2to3.pgen2.driver.Driver.parse_file(filename:Path, encoding:str | None=None, debug:bool=False) -> NLParse a file and return the syntax tree.
method
src.blib2to3.pgen2.driver.Driver.parse_string(text:str, debug:bool=False) -> NLParse a string and return the syntax tree.
method
src.blib2to3.pgen2.driver.Driver.parse_tokens(tokens:Iterable[TokenInfo], debug:bool=False) -> NLParse a series of tokens and return the syntax tree.
func
src.blib2to3.pgen2.driver.load_grammar(gt:str='Grammar.txt', gp:str | None=None, save:bool=True, force:bool=False, logger:Logger | None=None) -> GrammarLoad the grammar (maybe from a pickle).
func
src.blib2to3.pgen2.driver.load_packaged_grammar(grammar_source:str, cache_dir:Path | None=None) -> grammar.GrammarLoads a grammar by doing `load_grammar(grammar_source)`.
func
src.blib2to3.pgen2.driver.main(*args:str) -> boolMain program, when run as a script: produce grammar pickle files.
class
src.blib2to3.pgen2.grammar.GrammarPgen parsing tables conversion class.
method
src.blib2to3.pgen2.grammar.Grammar.copy() -> _PCopy the grammar.
method
src.blib2to3.pgen2.grammar.Grammar.dump(filename:Path) -> NoneDump the grammar tables to a pickle file.
method
src.blib2to3.pgen2.grammar.Grammar.load(filename:Path) -> NoneLoad the grammar tables from a pickle file.
method
src.blib2to3.pgen2.grammar.Grammar.loads(pkl:bytes) -> NoneLoad the grammar tables from a pickle bytes object.
method
src.blib2to3.pgen2.grammar.Grammar.report() -> NoneDump the grammar tables to standard output, for debugging.
class
src.blib2to3.pgen2.parse.ParseErrorException to signal the parser is stuck.
class
src.blib2to3.pgen2.parse.ParserParser engine.
method
src.blib2to3.pgen2.parse.Parser.addtoken(type:int, value:str, context:Context) -> boolAdd a token; return True iff this is the end of the program.
method
src.blib2to3.pgen2.parse.Parser.classify(type:int, value:str, context:Context) -> list[int]Turn a token into a label.
method
src.blib2to3.pgen2.parse.Parser.pop() -> NonePop a nonterminal.
method
src.blib2to3.pgen2.parse.Parser.push(type:int, newdfa:DFAS, newstate:int, context:Context) -> NonePush a nonterminal.
method
src.blib2to3.pgen2.parse.Parser.shift(type:int, value:str, newstate:int, context:Context) -> NoneShift a token.
func
src.blib2to3.pgen2.parse.stack_copy(stack:list[tuple[DFAS, int, RawNode]]) -> list[tuple[DFAS, int, RawNode]]Nodeless stack copy.
class
src.blib2to3.pytree.BaseAbstract base class for Node and Leaf.
method
src.blib2to3.pytree.Base.clone() -> _PReturn a cloned (deep) copy of self.
method
src.blib2to3.pytree.Base.get_lineno() -> int | NoneReturn the line number which generated the invocant node.
method
src.blib2to3.pytree.Base.get_suffix() -> strReturn the string immediately following the invocant node.
method
src.blib2to3.pytree.Base.post_order() -> Iterator[NL]Return a post-order iterator for the tree.
method
src.blib2to3.pytree.Base.pre_order() -> Iterator[NL]Return a pre-order iterator for the tree.
method
src.blib2to3.pytree.Base.remove(search_start:int=0) -> int | NoneRemove the node from the tree.
method
src.blib2to3.pytree.Base.replace(new:NL | list[NL]) -> NoneReplace this node with a new one in the parent.
class
src.blib2to3.pytree.BasePatternA pattern is a tree matching pattern.
method
src.blib2to3.pytree.BasePattern.generate_matches(nodes:list[NL]) -> Iterator[tuple[int, _Results]]Generator yielding all matches for this pattern.
method
src.blib2to3.pytree.BasePattern.match(node:NL, results:_Results | None=None) -> boolDoes this pattern exactly match a node?
method
src.blib2to3.pytree.BasePattern.match_seq(nodes:list[NL], results:_Results | None=None) -> boolDoes this pattern exactly match a sequence of nodes?
method
src.blib2to3.pytree.BasePattern.optimize() -> 'BasePattern'A subclass can define this as a hook for optimizations.
class
src.blib2to3.pytree.LeafConcrete implementation for leaf nodes.
method
src.blib2to3.pytree.Leaf.post_order() -> Iterator['Leaf']Return a post-order iterator for the tree.
method
src.blib2to3.pytree.Leaf.pre_order() -> Iterator['Leaf']Return a pre-order iterator for the tree.
method
src.blib2to3.pytree.Leaf.prefix() -> strThe whitespace and comments preceding this token in the input.
class
src.blib2to3.pytree.NodeConcrete implementation for interior nodes.
method
src.blib2to3.pytree.Node.append_child(child:NL) -> NoneEquivalent to 'node.children.append(child)'.
method
src.blib2to3.pytree.Node.insert_child(i:int, child:NL) -> NoneEquivalent to 'node.children.insert(i, child)'.
method
src.blib2to3.pytree.Node.post_order() -> Iterator[NL]Return a post-order iterator for the tree.
method
src.blib2to3.pytree.Node.pre_order() -> Iterator[NL]Return a pre-order iterator for the tree.
method
src.blib2to3.pytree.Node.prefix() -> strThe whitespace and comments preceding this node in the input.
method
src.blib2to3.pytree.Node.set_child(i:int, child:NL) -> NoneEquivalent to 'node.children[i] = child'.
class
src.blib2to3.pytree.WildcardPatternA wildcard pattern can match zero or more nodes.
method
src.blib2to3.pytree.WildcardPattern.match(node, results=None) -> boolDoes this pattern exactly match a node?
method
src.blib2to3.pytree.WildcardPattern.match_seq(nodes, results=None) -> boolDoes this pattern exactly match a sequence of nodes?
method
src.blib2to3.pytree.WildcardPattern.optimize() -> AnyOptimize certain stacked wildcard patterns.
func
src.blib2to3.pytree.convert(gr:Grammar, raw_node:RawNode) -> NLConvert raw node information to a Node or Leaf instance.
About this data
These signatures were extracted from the public source of psf/black
using Python's ast module. Argument names, default values,
type annotations and return types are taken verbatim from the code.
Implementation bodies are never stored. See
how it works for details.