]>
git.madduck.net Git - etc/vim.git/blobdiff - src/black/lines.py
madduck's git repository
Every one of the projects in this repository is available at the canonical
URL git://git.madduck.net/madduck/pub/<projectpath> — see
each project's metadata for the exact URL.
All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@ git. madduck. net .
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
SSH access, as well as push access can be individually
arranged .
If you use my repositories frequently, consider adding the following
snippet to ~/.gitconfig and using the third clone URL listed for each
project:
[url "git://git.madduck.net/madduck/"]
insteadOf = madduck:
import sys
from typing import (
Callable,
import sys
from typing import (
Callable,
from black.nodes import STANDALONE_COMMENT, TEST_DESCENDANTS
from black.nodes import BRACKETS, OPENING_BRACKETS, CLOSING_BRACKETS
from black.nodes import syms, whitespace, replace_child, child_towards
from black.nodes import STANDALONE_COMMENT, TEST_DESCENDANTS
from black.nodes import BRACKETS, OPENING_BRACKETS, CLOSING_BRACKETS
from black.nodes import syms, whitespace, replace_child, child_towards
-from black.nodes import is_multiline_string, is_import, is_type_comment, last_two_except
+from black.nodes import is_multiline_string, is_import, is_type_comment
from black.nodes import is_one_tuple_between
# types
from black.nodes import is_one_tuple_between
# types
def can_omit_invisible_parens(
line: Line,
line_length: int,
def can_omit_invisible_parens(
line: Line,
line_length: int,
- omit_on_explode: Collection[LeafID] = (),
) -> bool:
"""Does `line` have a shape safe to reformat without optional parens around it?
) -> bool:
"""Does `line` have a shape safe to reformat without optional parens around it?
penultimate = line.leaves[-2]
last = line.leaves[-1]
penultimate = line.leaves[-2]
last = line.leaves[-1]
- if line.magic_trailing_comma:
- try:
- penultimate, last = last_two_except(line.leaves, omit=omit_on_explode)
- except LookupError:
- # Turns out we'd omit everything. We cannot skip the optional parentheses.
- return False
if (
last.type == token.RPAR
if (
last.type == token.RPAR
# unnecessary.
return True
# unnecessary.
return True
- if line.magic_trailing_comma and penultimate.type == token.COMMA:
- # The rightmost non-omitted bracket pair is the one we want to explode on.
- return True
-
if _can_omit_closing_paren(line, last=last, line_length=line_length):
return True
if _can_omit_closing_paren(line, last=last, line_length=line_length):
return True