Look at actual parenthesis when generating ignored leafs.

Fixes #385
This commit is contained in:
Zsolt Dollenstein 2018-07-22 14:47:42 +01:00
parent df965b0558
commit e94a41f92a
3 changed files with 74 additions and 13 deletions

View File

@ -823,6 +823,7 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md).
### 18.8b0
* fix parsing of `__future__` imports with renames (#389)
* fix scope of `# fmt: off` when directly preceding `yield` and other nodes (#385)
### 18.6b4

View File

@ -797,18 +797,6 @@ def show(cls, code: Union[str, Leaf, Node]) -> None:
syms.testlist_gexp,
syms.testlist_star_expr,
}
SURROUNDED_BY_BRACKETS = {
syms.typedargslist,
syms.arglist,
syms.subscriptlist,
syms.vfplist,
syms.import_as_names,
syms.yield_expr,
syms.testlist_gexp,
syms.testlist_star_expr,
syms.listmaker,
syms.dictsetmaker,
}
TEST_DESCENDANTS = {
syms.test,
syms.lambdef,
@ -1853,7 +1841,7 @@ def container_of(leaf: Leaf) -> LN:
if parent.type == syms.file_input:
break
if parent.type in SURROUNDED_BY_BRACKETS:
if parent.prev_sibling is not None and parent.prev_sibling.type in BRACKETS:
break
container = parent

View File

@ -48,6 +48,39 @@ def spaces2(result= _core.Value(None)):
# fmt: off
key: 'value',
}
def subscriptlist():
atom[
# fmt: off
'some big and',
'complex subscript',
# fmt: on
goes + here, andhere,
]
def import_as_names():
# fmt: off
from hello import a, b
'unformatted'
# fmt: on
def testlist_star_expr():
# fmt: off
a , b = *hello
'unformatted'
# fmt: on
def yield_expr():
# fmt: off
yield hello
'unformatted'
# fmt: on
'formatted'
# fmt: off
( yield hello )
'unformatted'
# fmt: on
def example(session):
# fmt: off
result = session\
@ -142,6 +175,7 @@ def single_literal_yapf_disable():
xxxxxxxxxx_xxxxxxxxxxx_xxxxxxx_xxxxxxxxx=5
)
# fmt: off
yield 'hello'
# No formatting to the end of the file
l=[1,2,3]
d={'a':1,
@ -219,6 +253,43 @@ def spaces2(result=_core.Value(None)):
}
def subscriptlist():
atom[
# fmt: off
'some big and',
'complex subscript',
# fmt: on
goes + here,
andhere,
]
def import_as_names():
# fmt: off
from hello import a, b
'unformatted'
# fmt: on
def testlist_star_expr():
# fmt: off
a , b = *hello
'unformatted'
# fmt: on
def yield_expr():
# fmt: off
yield hello
'unformatted'
# fmt: on
"formatted"
# fmt: off
( yield hello )
'unformatted'
# fmt: on
def example(session):
# fmt: off
result = session\
@ -327,6 +398,7 @@ def single_literal_yapf_disable():
xxxxxxxxxx_xxxxxxxxxxx_xxxxxxx_xxxxxxxxx=5,
)
# fmt: off
yield 'hello'
# No formatting to the end of the file
l=[1,2,3]
d={'a':1,