_format module
- class pyflyby._format.FormatParams(max_line_length=None, max_line_length_default=79, wrap_paren=True, indent=4, hanging_indent='never', use_black=False)
- classmethod coerce(arg=None)
Return
argas an instance ofcls.>>> FormatParams.coerce(None) <FormatParams {}>
argmay beNone, or any FormatParams; parameters thatclsdoes not have are dropped.- Return type:
Self
- hanging_indent: str = 'never'
- indent: int = 4
- max_line_length: int | float | None = None
- max_line_length_default: int = 79
- replace(**kwargs)
Return a copy of
selfwith the given parameters overridden.>>> FormatParams(max_line_length=20).replace(wrap_paren=False) <FormatParams {'max_line_length': 20, 'wrap_paren': False}>
The result has the same class as
self, so subclass-only parameters are preserved.- Return type:
Self
- use_black: bool = False
- wrap_paren: bool = True
- pyflyby._format.fill(tokens, sep=(', ', ''), prefix='', suffix='', newline='\\n', max_line_length=80)
Given a sequences of strings, fill them into a single string with up to
max_line_lengthcharacters each.>>> fill(["'hello world'", "'hello two'"], ... prefix=("print ", " "), suffix=(" \\", ""), ... max_line_length=25) "print 'hello world', \\\n 'hello two'\n"
- Parameters:
tokens (
Sequence[str]) – Sequence of strings to fill. There must be at least one token.sep (
Union[str,Tuple[str,str]]) – Separator string to append to each token. If a 2-element tuple, then indicates the separator between tokens and the separator after the last token. Trailing whitespace is removed from each line before appending the suffix, but not from between tokens on the same line.prefix (
Union[str,Tuple[str,str]]) – String to prepend at the beginning of each line. If a 2-element tuple, then indicates the prefix for the first line and prefix for subsequent lines.suffix (
Union[str,Tuple[str,str]]) – String to append to the end of each line. If a 2-element tuple, then indicates the suffix for all lines except the last, and the suffix for the last line.
- Return type:
str- Returns:
Filled string.
- pyflyby._format.pyfill(prefix, tokens, params=<FormatParams {}>)
Fill a Python statement.
>>> print(pyfill('print ', ["foo.bar", "baz", "quux", "quuuuux"]), end='') print foo.bar, baz, quux, quuuuux >>> print(pyfill('print ', ["foo.bar", "baz", "quux", "quuuuux"], ... FormatParams(max_line_length=15, hanging_indent='auto')), end='') print (foo.bar, baz, quux, quuuuux) >>> print(pyfill('print ', ["foo.bar", "baz", "quux", "quuuuux"], ... FormatParams(max_line_length=14, hanging_indent='auto')), end='') print ( foo.bar, baz, quux, quuuuux)
- Parameters:
prefix (
str) – Prefix for first line.tokens (
Sequence[str]) – Sequence of string tokens
- Return type:
strstr