brk-code

black の API リファレンス

black (psf/black) の公開 API 230 件 —— クラス 27、関数 109、メソッド 94。実際のソースを静的解析して抽出した正確なシグネチャを掲載しています。

リポジトリ: psf/black

種別件数
クラス27
関数109
メソッド94

API 一覧

funcaction.main.determine_version_specifier() -> str
Determine the version of Black to install.
funcsrc.black.assert_equivalent(src:str, dst:str) -> None
Raise AssertionError if `src` and `dst` aren't equivalent.
classsrc.black.brackets.BracketTracker
Keeps track of brackets on a line.
methodsrc.black.brackets.BracketTracker.delimiter_count_with_priority(priority:Priority=0) -> int
Return the number of delimiters with the given `priority`.
methodsrc.black.brackets.BracketTracker.get_open_lsqb() -> Leaf | None
Return the most recent opening square bracket (if any).
methodsrc.black.brackets.BracketTracker.mark(leaf:Leaf) -> None
Mark `leaf` with bracket-related metadata.
methodsrc.black.brackets.BracketTracker.max_delimiter_priority(exclude:Iterable[LeafID]=()) -> Priority
Return the highest priority of a delimiter found on the line.
methodsrc.black.brackets.BracketTracker.maybe_decrement_after_for_loop_variable(leaf:Leaf) -> bool
See `maybe_increment_for_loop_variable` above for explanation.
methodsrc.black.brackets.BracketTracker.maybe_decrement_after_lambda_arguments(leaf:Leaf) -> bool
See `maybe_increment_lambda_arguments` above for explanation.
methodsrc.black.brackets.BracketTracker.maybe_increment_for_loop_variable(leaf:Leaf) -> bool
In a for loop, or comprehension, the variables are often unpacks.
methodsrc.black.brackets.BracketTracker.maybe_increment_lambda_arguments(leaf:Leaf) -> bool
In a lambda expression, there might be more than one argument.
funcsrc.black.brackets.get_leaves_inside_matching_brackets(leaves:Sequence[Leaf]) -> set[LeafID]
Return leaves that are inside matching brackets.
funcsrc.black.brackets.max_delimiter_priority_in_atom(node:LN) -> Priority
Return maximum delimiter priority inside `node`.
methodsrc.black.cache.Cache.filtered_cached(sources:Iterable[Path]) -> tuple[set[Path], set[Path]]
Split an iterable of paths in `sources` into two sets.
methodsrc.black.cache.Cache.get_file_data(path:Path) -> FileData
Return file data for path.
methodsrc.black.cache.Cache.hash_digest(path:Path) -> str
Return hash digest for path.
methodsrc.black.cache.Cache.is_changed(source:Path) -> bool
Check if source has changed compared to cached version.
methodsrc.black.cache.Cache.read(mode:Mode) -> Self
Read the cache if it exists and is well-formed.
methodsrc.black.cache.Cache.write(sources:Iterable[Path]) -> None
Update the cache file data and write a new cache file.
funcsrc.black.cache.get_cache_dir() -> Path
Get the cache directory used by black.
funcsrc.black.check_stability_and_equivalence(src_contents:str, dst_contents:str, *mode:Mode, *lines:Collection[tuple[int, int]]=()) -> None
Perform stability and equivalence checks.
classsrc.black.comments.ProtoComment
Describes a piece of syntax that is a comment.
funcsrc.black.comments.children_contains_fmt_on(container:LN, mode:Mode) -> bool
Determine if children have formatting switched on.
funcsrc.black.comments.generate_comments(leaf:LN, mode:Mode) -> Iterator[Leaf]
Clean the prefix of the `leaf` and generate comments from it, if any.
funcsrc.black.comments.is_fmt_on(container:LN, mode:Mode) -> bool
Determine whether formatting is switched on within a container.
funcsrc.black.comments.make_comment(content:str, mode:Mode) -> str
Return a consistently formatted comment from the given `content` string.
funcsrc.black.comments.normalize_trailing_prefix(leaf:LN, total_consumed:int) -> None
Normalize the prefix that's left over after generating comments.
funcsrc.black.concurrency.cancel(tasks:Iterable[asyncio.Future[Any]]) -> None
asyncio signal handler that cancels all `tasks` and reports to stderr.
funcsrc.black.concurrency.shutdown(loop:asyncio.AbstractEventLoop) -> None
Cancel all pending tasks on `loop`, wait for them, and close the loop.
funcsrc.black.decode_bytes(src:bytes, mode:Mode, *encoding_overwrite:str | None=None) -> tuple[FileContent, Encoding, NewLine]
Return a tuple of (decoded_contents, encoding, newline).
funcsrc.black.detect_target_versions(node:Node, *future_imports:set[str] | None=None) -> set[TargetVersion]
Detect the version to target based on the nodes used.
funcsrc.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.
funcsrc.black.files.get_gitignore(root:Path) -> GitIgnoreSpec
Return a GitIgnoreSpec matching gitignore content if present.
funcsrc.black.files.parse_pyproject_toml(path_config:str) -> dict[str, Any]
Parse a pyproject toml file, pulling out relevant parts for Black.
funcsrc.black.files.parse_req_python_specifier(requires_python:str) -> list[TargetVersion] | None
Parse a specifier string (i.e.
funcsrc.black.files.parse_req_python_version(requires_python:str) -> list[TargetVersion] | None
Parse a version string (i.e.
funcsrc.black.files.strip_specifier_set(specifier_set:SpecifierSet) -> SpecifierSet
Strip minor versions for some specifiers in the specifier set.
funcsrc.black.format_cell(src:str, *fast:bool, *mode:Mode) -> str
Format code in given cell of Jupyter notebook.
funcsrc.black.format_file_contents(src_contents:str, *fast:bool, *mode:Mode, *lines:Collection[tuple[int, int]]=()) -> FileContent
Reformat contents of a file and return new contents.
funcsrc.black.format_file_in_place(src:Path, fast:bool, mode:Mode, write_back:WriteBack=WriteBack.NO, lock:Any=None, *lines:Collection[tuple[int, int]]=()) -> bool
Format file under `src` path.
funcsrc.black.format_ipynb_string(src_contents:str, *fast:bool, *mode:Mode) -> FileContent
Format Jupyter notebook.
funcsrc.black.format_stdin_to_stdout(fast:bool, *content:str | None=None, *write_back:WriteBack=WriteBack.NO, *mode:Mode, *lines:Collection[tuple[int, int]]=()) -> bool
Format file on stdin.
funcsrc.black.format_str(src_contents:str, *mode:Mode, *lines:Collection[tuple[int, int]]=()) -> str
Reformat a string and return new contents.
funcsrc.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.
funcsrc.black.get_future_imports(node:Node) -> set[str]
Return a set of __future__ imports in the file.
classsrc.black.handle_ipynb_magics.CellMagicFinder
Find cell magics.
methodsrc.black.handle_ipynb_magics.CellMagicFinder.visit_Expr(node:ast.Expr) -> None
Find cell magic, extract header and body.
classsrc.black.handle_ipynb_magics.MagicFinder
Visit cell to look for get_ipython calls.
methodsrc.black.handle_ipynb_magics.MagicFinder.visit_Assign(node:ast.Assign) -> None
Look for system assign magics.
methodsrc.black.handle_ipynb_magics.MagicFinder.visit_Expr(node:ast.Expr) -> None
Look for magics in body of cell.
funcsrc.black.handle_ipynb_magics.create_token(n_chars:int) -> str
Create a randomly generated token that is n_chars characters long.
funcsrc.black.handle_ipynb_magics.get_token(src:str, magic:str, existing_tokens:Collection[str]=()) -> str
Return randomly generated token to mask IPython magic with.
funcsrc.black.handle_ipynb_magics.mask_cell(src:str) -> tuple[str, list[Replacement]]
Mask IPython magics so content becomes parseable Python code.
funcsrc.black.handle_ipynb_magics.put_trailing_semicolon_back(src:str, has_trailing_semicolon:bool) -> str
Put trailing semicolon back if cell originally had it.
funcsrc.black.handle_ipynb_magics.remove_trailing_semicolon(src:str) -> tuple[str, bool]
Remove trailing semicolon from Jupyter notebook cell.
funcsrc.black.handle_ipynb_magics.replace_cell_magics(src:str) -> tuple[str, list[Replacement]]
Replace cell magic with token.
funcsrc.black.handle_ipynb_magics.replace_magics(src:str) -> tuple[str, list[Replacement]]
Replace magics within body of cell.
funcsrc.black.handle_ipynb_magics.unmask_cell(src:str, replacements:list[Replacement]) -> str
Remove replacements from cell.
classsrc.black.linegen.LineGenerator
Generates reformatted Line objects.
methodsrc.black.linegen.LineGenerator.line(indent:int=0) -> Iterator[Line]
Generate a line.
methodsrc.black.linegen.LineGenerator.visit_DEDENT(node:Leaf) -> Iterator[Line]
Decrease indentation level, maybe yield a line.
methodsrc.black.linegen.LineGenerator.visit_ENDMARKER(leaf:Leaf) -> Iterator[Line]
End of file.
methodsrc.black.linegen.LineGenerator.visit_INDENT(node:Leaf) -> Iterator[Line]
Increase indentation level, maybe yield a line.
methodsrc.black.linegen.LineGenerator.visit_SEMI(leaf:Leaf) -> Iterator[Line]
Remove a semicolon and put the other statement on a separate line.
methodsrc.black.linegen.LineGenerator.visit_async_stmt(node:Node) -> Iterator[Line]
Visit `async def`, `async for`, `async with`.
methodsrc.black.linegen.LineGenerator.visit_atom(node:Node) -> Iterator[Line]
Visit any atom
methodsrc.black.linegen.LineGenerator.visit_decorators(node:Node) -> Iterator[Line]
Visit decorators.
methodsrc.black.linegen.LineGenerator.visit_default(node:LN) -> Iterator[Line]
Default `visit_*()` implementation.
methodsrc.black.linegen.LineGenerator.visit_funcdef(node:Node) -> Iterator[Line]
Visit function definition.
methodsrc.black.linegen.LineGenerator.visit_match_case(node:Node) -> Iterator[Line]
Visit either a match or case statement.
methodsrc.black.linegen.LineGenerator.visit_simple_stmt(node:Node) -> Iterator[Line]
Visit a statement without nested statements.
methodsrc.black.linegen.LineGenerator.visit_stmt(node:Node, keywords:set[str], parens:set[str]) -> Iterator[Line]
Visit a statement.
methodsrc.black.linegen.LineGenerator.visit_suite(node:Node) -> Iterator[Line]
Visit a suite.
methodsrc.black.linegen.LineGenerator.visit_test(node:Node) -> Iterator[Line]
Visit an `x if y else z` test
funcsrc.black.linegen.append_to_line(leaf:Leaf) -> Iterator[Line]
Append `leaf` to current line or to new line if appending impossible.
funcsrc.black.linegen.delimiter_split(line:Line, features:Collection[Feature], mode:Mode) -> Iterator[Line]
Split according to delimiters of the highest priority.
funcsrc.black.linegen.remove_with_parens(node:Node, parent:Node, mode:Mode, features:Collection[Feature]) -> None
Recursively hide optional parens in `with` statements.
funcsrc.black.linegen.standalone_comment_split(line:Line, features:Collection[Feature], mode:Mode) -> Iterator[Line]
Split standalone comments from the rest of the line.
funcsrc.black.linegen.transform_line(line:Line, mode:Mode, features:Collection[Feature]=()) -> Iterator[Line]
Transform a `line`, potentially splitting it into many lines.
classsrc.black.lines.Line
Holds leaves and comments.
methodsrc.black.lines.Line.append(leaf:Leaf, preformatted:bool=False, track_bracket:bool=False) -> None
Add a new `leaf` to the end of the line.
methodsrc.black.lines.Line.append_comment(comment:Leaf) -> bool
Add an inline or standalone comment to the line.
methodsrc.black.lines.Line.comments_after(leaf:Leaf) -> list[Leaf]
Generate comments that should appear directly after `leaf`.
methodsrc.black.lines.Line.contains_standalone_comments() -> bool
If so, needs to be split before emitting.
methodsrc.black.lines.Line.enumerate_with_length(is_reversed:bool=False) -> Iterator[tuple[Index, Leaf, int]]
Return an enumeration of leaves with their length.
methodsrc.black.lines.Line.is_chained_assignment() -> bool
Is the line a chained assignment
methodsrc.black.lines.Line.is_class() -> bool
Is this line a class definition?
methodsrc.black.lines.Line.is_class_paren_empty() -> bool
Is this a class with no base classes but using parentheses?
methodsrc.black.lines.Line.is_comment() -> bool
Is this line a standalone comment?
methodsrc.black.lines.Line.is_complex_subscript(leaf:Leaf) -> bool
Return True iff `leaf` is part of a slice with non-trivial exprs.
methodsrc.black.lines.Line.is_decorator() -> bool
Is this line a decorator?
methodsrc.black.lines.Line.is_def() -> bool
Is this a function definition?
methodsrc.black.lines.Line.is_docstring() -> bool
Is the line a docstring?
methodsrc.black.lines.Line.is_fmt_pass_converted(*first_leaf_matches:Callable[[Leaf], bool] | None=None) -> bool
Is this line converted from fmt off/skip code?
methodsrc.black.lines.Line.is_import() -> bool
Is this an import line?
methodsrc.black.lines.Line.is_with_or_async_with_stmt() -> bool
Is this a with_stmt line?
methodsrc.black.lines.Line.opens_block() -> bool
Does this line open a new level of indentation.
methodsrc.black.lines.Line.remove_trailing_comma() -> None
Remove the trailing comma and moves the comments attached to it.
classsrc.black.lines.LinesBlock
Class that holds information about a block of formatted lines.
classsrc.black.lines.RHSResult
Intermediate split result from a right hand split.
funcsrc.black.lines.can_be_split(line:Line) -> bool
Return False if the line cannot be split *for sure*.
funcsrc.black.lines.enumerate_reversed(sequence:Sequence[T]) -> Iterator[tuple[Index, T]]
Like `reversed(enumerate(sequence))` if that were possible.
funcsrc.black.lines.line_to_string(line:Line) -> str
Returns the string representation of @line.
classsrc.black.mode.Preview
Individual preview style features.
classsrc.black.nodes.Visitor
Basic lib2to3 visitor that yields things of type `T` on `visit()`.
methodsrc.black.nodes.Visitor.visit(node:LN) -> Iterator[T]
Main method to visit `node` and its children.
methodsrc.black.nodes.Visitor.visit_default(node:LN) -> Iterator[T]
Default `visit_*()` implementation.
funcsrc.black.nodes.child_towards(ancestor:Node, descendant:LN) -> LN | None
Return the child of `ancestor` that contains `descendant`.
funcsrc.black.nodes.container_of(leaf:Leaf) -> LN
Return `leaf` or one of its ancestors that is the topmost container of it.
funcsrc.black.nodes.ensure_visible(leaf:Leaf) -> None
Make sure parentheses are visible.
funcsrc.black.nodes.first_leaf(node:LN) -> Leaf | None
Returns the first leaf of the ancestor node.
funcsrc.black.nodes.first_leaf_of(node:LN) -> Leaf | None
Returns the first leaf of the node tree.
funcsrc.black.nodes.fstring_tstring_to_string(node:Node) -> Leaf
Converts an fstring or tstring node back to a string node.
funcsrc.black.nodes.get_annotation_type(leaf:Leaf) -> Literal['return', 'param', None]
Returns the type of annotation this leaf is part of, if any.
funcsrc.black.nodes.is_arith_like(node:LN) -> bool
Whether node is an arithmetic or a binary arithmetic expression
funcsrc.black.nodes.is_async_stmt_or_funcdef(leaf:Leaf) -> bool
Return True if the given leaf starts an async def/for/with statement.
funcsrc.black.nodes.is_empty_tuple(node:LN) -> bool
Return True if `node` holds an empty tuple.
funcsrc.black.nodes.is_fstring(node:Node) -> bool
Return True if the node is an f-string
funcsrc.black.nodes.is_generator(node:LN) -> bool
Return True if `node` holds a generator.
funcsrc.black.nodes.is_import(leaf:Leaf) -> bool
Return True if the given leaf starts an import statement.
funcsrc.black.nodes.is_one_tuple(node:LN) -> bool
Return True if `node` holds a tuple with one element, with or without parens.
funcsrc.black.nodes.is_part_of_annotation(leaf:Leaf) -> bool
Returns whether this leaf is part of a type annotation.
funcsrc.black.nodes.is_simple_decorator_trailer(node:LN, last:bool=False) -> bool
Return True iff `node` is a trailer valid in a simple decorator
funcsrc.black.nodes.is_simple_exponentiation(node:LN) -> bool
Whether whitespace around `**` should be removed.
funcsrc.black.nodes.is_stub_body(node:LN) -> bool
Return True if `node` is a simple statement containing an ellipsis.
funcsrc.black.nodes.is_stub_suite(node:Node) -> bool
Return True if `node` is a suite with a stub body.
funcsrc.black.nodes.is_tuple(node:LN) -> bool
Return True if `node` holds a tuple.
funcsrc.black.nodes.is_tuple_containing_star(node:LN) -> bool
Return True if `node` holds a tuple that contains a star operator.
funcsrc.black.nodes.is_tuple_containing_walrus(node:LN) -> bool
Return True if `node` holds a tuple that contains a walrus operator.
funcsrc.black.nodes.is_type_comment(leaf:Leaf, mode:Mode) -> bool
Return True if the given leaf is a type comment.
funcsrc.black.nodes.is_vararg(leaf:Leaf, within:set[NodeType]) -> bool
Return True if `leaf` is a star or double star in a vararg or kwarg.
funcsrc.black.nodes.is_walrus_assignment(node:LN) -> bool
Return True iff `node` is of the shape ( test := test )
funcsrc.black.nodes.is_with_or_async_with_stmt(leaf:Leaf) -> bool
Return True if the given leaf starts a with or async with statement.
funcsrc.black.nodes.is_yield(node:LN) -> bool
Return True if `node` holds a `yield` or `yield from` expression.
funcsrc.black.nodes.last_leaf(node:LN) -> Leaf | None
Returns the last leaf of the ancestor node.
funcsrc.black.nodes.make_simple_prefix(nl_count:int, form_feed:bool, empty_line:str='\n') -> str
Generate a normalized prefix string.
funcsrc.black.nodes.parent_type(node:LN | None) -> NodeType | None
Returns: @node.parent.type, if @node is not None and has a parent.
funcsrc.black.nodes.preceding_leaf(node:LN | None) -> Leaf | None
Return the first leaf that precedes `node`, if any.
funcsrc.black.nodes.unwrap_singleton_parenthesis(node:LN) -> LN | None
Returns `wrapped` if `node` is of the shape ( wrapped ).
funcsrc.black.nodes.whitespace(leaf:Leaf, *complex_subscript:bool, *mode:Mode) -> str
Return whitespace prefix if needed for the given `leaf`.
funcsrc.black.nodes.wrap_in_parentheses(parent:Node, child:LN, *visible:bool=True, *index:int | None=None) -> None
Wrap `child` in parentheses.
funcsrc.black.numerics.format_complex_number(text:str) -> str
Formats a complex string like `10j`
funcsrc.black.numerics.format_float_or_int_string(text:str) -> str
Formats a float string like "1.0".
funcsrc.black.numerics.format_hex(text:str) -> str
Formats a hexadecimal string like "0x12B3"
funcsrc.black.numerics.format_scientific_notation(text:str) -> str
Formats a numeric string utilizing scientific notation
funcsrc.black.numerics.normalize_numeric_literal(leaf:Leaf) -> None
Normalizes numeric (float, int, and complex) literals.
funcsrc.black.output.color_diff(contents:str) -> str
Inject the ANSI color codes to the diff.
funcsrc.black.output.diff(a:str, b:str, a_name:str, b_name:str) -> str
Return a unified diff string between strings `a` and `b`.
funcsrc.black.output.dump_to_file(*ensure_final_newline:bool=True, *output:str) -> str
Dump `output` to a temporary file.
classsrc.black.parsing.InvalidInput
Raised when input source code fails all parse attempts.
classsrc.black.parsing.SourceASTParseError
Raised when the source file cannot be parsed by ast.parse().
funcsrc.black.parsing.lib2to3_parse(src_txt:str, target_versions:Collection[TargetVersion]=()) -> Node
Given a string with source, return the lib2to3 Node.
funcsrc.black.parsing.stringify_ast(node:ast.AST) -> Iterator[str]
Simple visitor generating strings to compare ASTs by content.
funcsrc.black.ranges.convert_unchanged_lines(src_node:Node, lines:Collection[tuple[int, int]]) -> None
Converts unchanged lines to STANDALONE_COMMENT.
funcsrc.black.ranges.is_valid_line_range(lines:tuple[int, int]) -> bool
Returns whether the line range is valid.
funcsrc.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.
funcsrc.black.re_compile_maybe_verbose(regex:str) -> Pattern[str]
Compile a regular expression string in `regex`.
classsrc.black.report.NothingChanged
Raised when reformatted code is the same as source.
classsrc.black.report.Report
Provides a reformatting counter.
methodsrc.black.report.Report.done(src:Path, changed:Changed) -> None
Increment the counter for successful reformatting.
methodsrc.black.report.Report.failed(src:Path, message:BaseException) -> None
Increment the counter for failed reformatting.
methodsrc.black.report.Report.return_code() -> int
Return the exit code that the app should use.
funcsrc.black.schema.get_schema(tool_name:str='black') -> Any
Get the stored complete schema for black's settings.
funcsrc.black.strings.has_triple_quotes(string:str) -> bool
Returns: True iff @string starts with three quotation characters.
funcsrc.black.strings.lines_with_leading_tabs_expanded(s:str) -> list[str]
Splits string into lines and expands only leading tabs.
funcsrc.black.strings.normalize_string_prefix(s:str) -> str
Make all string prefixes lowercase.
funcsrc.black.strings.normalize_string_quotes(s:str) -> str
Prefer double quotes but only if it doesn't cause more escaping.
funcsrc.black.strings.sub_twice(regex:Pattern[str], replacement:str, original:str) -> str
Replace `regex` with `replacement` twice on `original`.
classsrc.black.trans.CannotTransform
Base class for errors raised by Transformers.
classsrc.black.trans.CustomSplit
A custom (i.e.
classsrc.black.trans.StringMerger
StringTransformer that merges strings together.
funcsrc.black.trans.StringMerger.make_naked(string:str, string_prefix:str) -> str
Strip @string (i.e.
classsrc.black.trans.StringSplitter
StringTransformer that splits "atom" strings (i.e.
funcsrc.black.trans.hug_power_op(line:Line, features:Collection[Feature], mode:Mode) -> Iterator[Line]
A transformer which normalizes spacing around power operators.
funcsrc.black.trans.is_expression_chained(chained_leaves:list[Leaf]) -> bool
Function to determine if the variable is a chained call.
funcsrc.black.trans.iter_fexpr_spans(s:str) -> Iterator[tuple[int, int]]
Yields spans corresponding to expressions in a given f-string.
funcsrc.black.validate_metadata(nb:MutableMapping[str, Any]) -> None
If notebook is marked as non-Python, don't format it.
classsrc.blib2to3.pgen2.conv.Converter
Grammar subclass that reads classic pgen output files.
methodsrc.blib2to3.pgen2.conv.Converter.finish_off()
Create additional useful structures.
methodsrc.blib2to3.pgen2.conv.Converter.parse_graminit_c(filename)
Parse the .c file written by pgen.
methodsrc.blib2to3.pgen2.conv.Converter.parse_graminit_h(filename)
Parse the .h file written by pgen.
methodsrc.blib2to3.pgen2.driver.Driver.parse_file(filename:Path, encoding:str | None=None, debug:bool=False) -> NL
Parse a file and return the syntax tree.
methodsrc.blib2to3.pgen2.driver.Driver.parse_string(text:str, debug:bool=False) -> NL
Parse a string and return the syntax tree.
methodsrc.blib2to3.pgen2.driver.Driver.parse_tokens(tokens:Iterable[TokenInfo], debug:bool=False) -> NL
Parse a series of tokens and return the syntax tree.
funcsrc.blib2to3.pgen2.driver.load_grammar(gt:str='Grammar.txt', gp:str | None=None, save:bool=True, force:bool=False, logger:Logger | None=None) -> Grammar
Load the grammar (maybe from a pickle).
funcsrc.blib2to3.pgen2.driver.load_packaged_grammar(grammar_source:str, cache_dir:Path | None=None) -> grammar.Grammar
Loads a grammar by doing `load_grammar(grammar_source)`.
funcsrc.blib2to3.pgen2.driver.main(*args:str) -> bool
Main program, when run as a script: produce grammar pickle files.
classsrc.blib2to3.pgen2.grammar.Grammar
Pgen parsing tables conversion class.
methodsrc.blib2to3.pgen2.grammar.Grammar.copy() -> _P
Copy the grammar.
methodsrc.blib2to3.pgen2.grammar.Grammar.dump(filename:Path) -> None
Dump the grammar tables to a pickle file.
methodsrc.blib2to3.pgen2.grammar.Grammar.load(filename:Path) -> None
Load the grammar tables from a pickle file.
methodsrc.blib2to3.pgen2.grammar.Grammar.loads(pkl:bytes) -> None
Load the grammar tables from a pickle bytes object.
methodsrc.blib2to3.pgen2.grammar.Grammar.report() -> None
Dump the grammar tables to standard output, for debugging.
classsrc.blib2to3.pgen2.parse.ParseError
Exception to signal the parser is stuck.
classsrc.blib2to3.pgen2.parse.Parser
Parser engine.
methodsrc.blib2to3.pgen2.parse.Parser.addtoken(type:int, value:str, context:Context) -> bool
Add a token; return True iff this is the end of the program.
methodsrc.blib2to3.pgen2.parse.Parser.classify(type:int, value:str, context:Context) -> list[int]
Turn a token into a label.
methodsrc.blib2to3.pgen2.parse.Parser.pop() -> None
Pop a nonterminal.
methodsrc.blib2to3.pgen2.parse.Parser.push(type:int, newdfa:DFAS, newstate:int, context:Context) -> None
Push a nonterminal.
methodsrc.blib2to3.pgen2.parse.Parser.shift(type:int, value:str, newstate:int, context:Context) -> None
Shift a token.
funcsrc.blib2to3.pgen2.parse.stack_copy(stack:list[tuple[DFAS, int, RawNode]]) -> list[tuple[DFAS, int, RawNode]]
Nodeless stack copy.
classsrc.blib2to3.pytree.Base
Abstract base class for Node and Leaf.
methodsrc.blib2to3.pytree.Base.clone() -> _P
Return a cloned (deep) copy of self.
methodsrc.blib2to3.pytree.Base.get_lineno() -> int | None
Return the line number which generated the invocant node.
methodsrc.blib2to3.pytree.Base.get_suffix() -> str
Return the string immediately following the invocant node.
methodsrc.blib2to3.pytree.Base.post_order() -> Iterator[NL]
Return a post-order iterator for the tree.
methodsrc.blib2to3.pytree.Base.pre_order() -> Iterator[NL]
Return a pre-order iterator for the tree.
methodsrc.blib2to3.pytree.Base.remove(search_start:int=0) -> int | None
Remove the node from the tree.
methodsrc.blib2to3.pytree.Base.replace(new:NL | list[NL]) -> None
Replace this node with a new one in the parent.
classsrc.blib2to3.pytree.BasePattern
A pattern is a tree matching pattern.
methodsrc.blib2to3.pytree.BasePattern.generate_matches(nodes:list[NL]) -> Iterator[tuple[int, _Results]]
Generator yielding all matches for this pattern.
methodsrc.blib2to3.pytree.BasePattern.match(node:NL, results:_Results | None=None) -> bool
Does this pattern exactly match a node?
methodsrc.blib2to3.pytree.BasePattern.match_seq(nodes:list[NL], results:_Results | None=None) -> bool
Does this pattern exactly match a sequence of nodes?
methodsrc.blib2to3.pytree.BasePattern.optimize() -> 'BasePattern'
A subclass can define this as a hook for optimizations.
classsrc.blib2to3.pytree.Leaf
Concrete implementation for leaf nodes.
methodsrc.blib2to3.pytree.Leaf.post_order() -> Iterator['Leaf']
Return a post-order iterator for the tree.
methodsrc.blib2to3.pytree.Leaf.pre_order() -> Iterator['Leaf']
Return a pre-order iterator for the tree.
methodsrc.blib2to3.pytree.Leaf.prefix() -> str
The whitespace and comments preceding this token in the input.
classsrc.blib2to3.pytree.Node
Concrete implementation for interior nodes.
methodsrc.blib2to3.pytree.Node.append_child(child:NL) -> None
Equivalent to 'node.children.append(child)'.
methodsrc.blib2to3.pytree.Node.insert_child(i:int, child:NL) -> None
Equivalent to 'node.children.insert(i, child)'.
methodsrc.blib2to3.pytree.Node.post_order() -> Iterator[NL]
Return a post-order iterator for the tree.
methodsrc.blib2to3.pytree.Node.pre_order() -> Iterator[NL]
Return a pre-order iterator for the tree.
methodsrc.blib2to3.pytree.Node.prefix() -> str
The whitespace and comments preceding this node in the input.
methodsrc.blib2to3.pytree.Node.set_child(i:int, child:NL) -> None
Equivalent to 'node.children[i] = child'.
classsrc.blib2to3.pytree.WildcardPattern
A wildcard pattern can match zero or more nodes.
methodsrc.blib2to3.pytree.WildcardPattern.match(node, results=None) -> bool
Does this pattern exactly match a node?
methodsrc.blib2to3.pytree.WildcardPattern.match_seq(nodes, results=None) -> bool
Does this pattern exactly match a sequence of nodes?
methodsrc.blib2to3.pytree.WildcardPattern.optimize() -> Any
Optimize certain stacked wildcard patterns.
funcsrc.blib2to3.pytree.convert(gr:Grammar, raw_node:RawNode) -> NL
Convert raw node information to a Node or Leaf instance.

この情報について

掲載しているシグネチャは psf/black の公開ソースコードを Python の ast モジュールで静的解析し、引数名・デフォルト値・ 型注釈・戻り値型をそのまま抽出したものです。実装コードは保存していません。 詳しくは仕組みの解説をご覧ください。

収録ライブラリ一覧(全 805 件)へ戻る