_format module
- class pyflyby._format.FormatParams(*args, **kwargs)
- _max_line_lenght_default = 79
- hanging_indent = 'never'
- indent = 4
- max_line_length = None
- use_black = False
- wrap_paren = 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_length
characters each.>>> fill(["'hello world'", "'hello two'"], ... prefix=("print ", " "), suffix=(" \\", ""), ... max_line_length=25) "print 'hello world', \\\n 'hello two'\n"
- Parameters:
tokens – Sequence of strings to fill. There must be at least one token.
sep – 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 – 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 – 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.
- 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 – Prefix for first line.
tokens – Sequence of string tokens
- Return type:
str