fix unary op detection (#1600)
This commit is contained in:
parent
d1ad8730e3
commit
820f38708f
@ -3297,12 +3297,12 @@ def do_match(self, line: Line) -> TMatchResult:
|
|||||||
# if the leaves in the parsed string include a PERCENT, we need to
|
# if the leaves in the parsed string include a PERCENT, we need to
|
||||||
# make sure the initial LPAR is NOT preceded by an operator with
|
# make sure the initial LPAR is NOT preceded by an operator with
|
||||||
# higher or equal precedence to PERCENT
|
# higher or equal precedence to PERCENT
|
||||||
if (
|
if is_valid_index(idx - 2):
|
||||||
is_valid_index(idx - 2)
|
# mypy can't quite follow unless we name this
|
||||||
and token.PERCENT in {leaf.type for leaf in LL[idx - 1 : next_idx]}
|
before_lpar = LL[idx - 2]
|
||||||
and (
|
if token.PERCENT in {leaf.type for leaf in LL[idx - 1 : next_idx]} and (
|
||||||
(
|
(
|
||||||
LL[idx - 2].type
|
before_lpar.type
|
||||||
in {
|
in {
|
||||||
token.STAR,
|
token.STAR,
|
||||||
token.AT,
|
token.AT,
|
||||||
@ -3318,12 +3318,12 @@ def do_match(self, line: Line) -> TMatchResult:
|
|||||||
)
|
)
|
||||||
or (
|
or (
|
||||||
# only unary PLUS/MINUS
|
# only unary PLUS/MINUS
|
||||||
not is_valid_index(idx - 3)
|
before_lpar.parent
|
||||||
and (LL[idx - 2].type in {token.PLUS, token.MINUS})
|
and before_lpar.parent.type == syms.factor
|
||||||
|
and (before_lpar.type in {token.PLUS, token.MINUS})
|
||||||
)
|
)
|
||||||
)
|
):
|
||||||
):
|
continue
|
||||||
continue
|
|
||||||
|
|
||||||
# Should be followed by a non-empty RPAR...
|
# Should be followed by a non-empty RPAR...
|
||||||
if (
|
if (
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
b + ("" % a)
|
b + ("" % a)
|
||||||
-("" % a)
|
-("" % a)
|
||||||
b - ("" % a)
|
b - ("" % a)
|
||||||
|
b + -("" % a)
|
||||||
~("" % a)
|
~("" % a)
|
||||||
2 ** ("" % a)
|
2 ** ("" % a)
|
||||||
await ("" % a)
|
await ("" % a)
|
||||||
@ -32,6 +33,7 @@
|
|||||||
b + "" % a
|
b + "" % a
|
||||||
-("" % a)
|
-("" % a)
|
||||||
b - "" % a
|
b - "" % a
|
||||||
|
b + -("" % a)
|
||||||
~("" % a)
|
~("" % a)
|
||||||
2 ** ("" % a)
|
2 ** ("" % a)
|
||||||
await ("" % a)
|
await ("" % a)
|
||||||
|
Loading…
Reference in New Issue
Block a user