Unverified Commit 0626c89a authored by Łukasz Langa's avatar Łukasz Langa
Browse files

Document how to use format_str()

Closes #1064
parent e253f126
Loading
Loading
Loading
Loading
+24 −1
Changes for black.py: 24 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -746,7 +746,30 @@ def format_str(src_contents: str, *, mode: FileMode) -> FileContent:
    """Reformat a string and return new contents.

    `mode` determines formatting options, such as how many characters per line are
    allowed.
    allowed.  Example:

    >>> import black
    >>> print(black.format_str("def f(arg:str='')->None:...", mode=FileMode()))
    def f(arg: str = "") -> None:
        ...

    A more complex example:
    >>> print(
    ...   black.format_str(
    ...     "def f(arg:str='')->None: hey",
    ...     mode=black.FileMode(
    ...       target_versions={black.TargetVersion.PY36},
    ...       line_length=10,
    ...       string_normalization=False,
    ...       is_pyi=False,
    ...     ),
    ...   ),
    ... )
    def f(
        arg: str = '',
    ) -> None:
        hey

    """
    src_node = lib2to3_parse(src_contents.lstrip(), mode.target_versions)
    dst_contents = []