formate.mini_hooks

Small but mighty hooks.

Functions:

check_ast(source)

Check the source can be parsed as a Python Abstract Syntax Tree.

noqa_reformat(source)

Pull # noqa: ... comments that immediately follow docstrings back up to the end of the correct line.

squish_stubs(source, formate_filename)

Squash type stubs by removing unnecessary blank lines.

check_ast(source)[source]

Check the source can be parsed as a Python Abstract Syntax Tree.

Parameters

source (str) – The source to check.

Raises

SyntaxError – If the source is not valid Python.

Return type

str

Returns

The source unchanged.

noqa_reformat(source)[source]

Pull # noqa: ... comments that immediately follow docstrings back up to the end of the correct line.

Parameters

source (str) – The source to reformat.

Return type

str

Returns

The reformatted source.

squish_stubs(source, formate_filename)[source]

Squash type stubs by removing unnecessary blank lines.

New in version 0.2.0.

Parameters
  • source (str) – The source to check.

  • formate_filename (Union[str, Path, PathLike]) – The name of the source file, to ensure this hook only runs on type stubs.

Return type

str

Returns

The reformatted source.