Consider in
, not in
, is
, is not
operators
This commit is contained in:
parent
f24635635e
commit
1dadeef47a
@ -628,6 +628,9 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md).
|
||||
|
||||
* fixed crash on dealing with optional parentheses (#193)
|
||||
|
||||
* fixed "is", "is not", "in", and "not in" not considered operators for
|
||||
splitting purposes
|
||||
|
||||
* fixed crash when dead symlinks where encountered
|
||||
|
||||
|
||||
|
45
black.py
45
black.py
@ -1746,31 +1746,54 @@ def is_split_before_delimiter(leaf: Leaf, previous: Leaf = None) -> int:
|
||||
):
|
||||
return STRING_PRIORITY
|
||||
|
||||
if leaf.type != token.NAME:
|
||||
return 0
|
||||
|
||||
if (
|
||||
leaf.type == token.NAME
|
||||
and leaf.value == "for"
|
||||
leaf.value == "for"
|
||||
and leaf.parent
|
||||
and leaf.parent.type in {syms.comp_for, syms.old_comp_for}
|
||||
):
|
||||
return COMPREHENSION_PRIORITY
|
||||
|
||||
if (
|
||||
leaf.type == token.NAME
|
||||
and leaf.value == "if"
|
||||
leaf.value == "if"
|
||||
and leaf.parent
|
||||
and leaf.parent.type in {syms.comp_if, syms.old_comp_if}
|
||||
):
|
||||
return COMPREHENSION_PRIORITY
|
||||
|
||||
if (
|
||||
leaf.type == token.NAME
|
||||
and leaf.value in {"if", "else"}
|
||||
and leaf.parent
|
||||
and leaf.parent.type == syms.test
|
||||
):
|
||||
if leaf.value in {"if", "else"} and leaf.parent and leaf.parent.type == syms.test:
|
||||
return TERNARY_PRIORITY
|
||||
|
||||
if leaf.type == token.NAME and leaf.value in LOGIC_OPERATORS and leaf.parent:
|
||||
if leaf.value == "is":
|
||||
return COMPARATOR_PRIORITY
|
||||
|
||||
if (
|
||||
leaf.value == "in"
|
||||
and leaf.parent
|
||||
and leaf.parent.type in {syms.comp_op, syms.comparison}
|
||||
and not (
|
||||
previous is not None
|
||||
and previous.type == token.NAME
|
||||
and previous.value == "not"
|
||||
)
|
||||
):
|
||||
return COMPARATOR_PRIORITY
|
||||
|
||||
if (
|
||||
leaf.value == "not"
|
||||
and leaf.parent
|
||||
and leaf.parent.type == syms.comp_op
|
||||
and not (
|
||||
previous is not None
|
||||
and previous.type == token.NAME
|
||||
and previous.value == "is"
|
||||
)
|
||||
):
|
||||
return COMPARATOR_PRIORITY
|
||||
|
||||
if leaf.value in LOGIC_OPERATORS and leaf.parent:
|
||||
return LOGIC_PRIORITY
|
||||
|
||||
return 0
|
||||
|
@ -128,7 +128,7 @@
|
||||
]
|
||||
slice[0]
|
||||
slice[0:1]
|
||||
@@ -124,103 +144,138 @@
|
||||
@@ -124,107 +144,154 @@
|
||||
numpy[-(c + 1) :, d]
|
||||
numpy[:, l[-2]]
|
||||
numpy[:, ::-1]
|
||||
@ -208,6 +208,10 @@
|
||||
-for i in (call()): ...
|
||||
-for j in (1 + (2 + 3)): ...
|
||||
-while(this and that): ...
|
||||
-a = aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp in qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
||||
-a = aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp not in qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
||||
-a = aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp is qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
||||
-a = aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp is not qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
||||
-if (
|
||||
- threading.current_thread() != threading.main_thread() and
|
||||
- threading.current_thread() != threading.main_thread() or
|
||||
@ -272,6 +276,22 @@
|
||||
+ ...
|
||||
+while this and that:
|
||||
+ ...
|
||||
+a = (
|
||||
+ aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp
|
||||
+ in qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
||||
+)
|
||||
+a = (
|
||||
+ aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp
|
||||
+ not in qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
||||
+)
|
||||
+a = (
|
||||
+ aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp
|
||||
+ is qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
||||
+)
|
||||
+a = (
|
||||
+ aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp
|
||||
+ is not qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
||||
+)
|
||||
+if (
|
||||
+ threading.current_thread() != threading.main_thread()
|
||||
+ and threading.current_thread() != threading.main_thread()
|
||||
|
@ -173,6 +173,10 @@ async def f():
|
||||
for i in (call()): ...
|
||||
for j in (1 + (2 + 3)): ...
|
||||
while(this and that): ...
|
||||
a = aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp in qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
||||
a = aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp not in qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
||||
a = aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp is qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
||||
a = aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp is not qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
||||
if (
|
||||
threading.current_thread() != threading.main_thread() and
|
||||
threading.current_thread() != threading.main_thread() or
|
||||
@ -449,6 +453,22 @@ async def f():
|
||||
...
|
||||
while this and that:
|
||||
...
|
||||
a = (
|
||||
aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp
|
||||
in qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
||||
)
|
||||
a = (
|
||||
aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp
|
||||
not in qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
||||
)
|
||||
a = (
|
||||
aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp
|
||||
is qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
||||
)
|
||||
a = (
|
||||
aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp
|
||||
is not qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
||||
)
|
||||
if (
|
||||
threading.current_thread() != threading.main_thread()
|
||||
and threading.current_thread() != threading.main_thread()
|
||||
|
Loading…
Reference in New Issue
Block a user