Skip to content

Commit 6678922

Browse files
authored
Merge pull request #1052 from PyCQA/short-circuit
use short-circuit evaluation in _is_binary_operator
2 parents 85decca + a6c3f2f commit 6678922

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

pycodestyle.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,20 +1269,19 @@ def explicit_line_join(logical_line, tokens):
12691269
parens -= 1
12701270

12711271

1272+
# The % character is strictly speaking a binary operator, but the
1273+
# common usage seems to be to put it next to the format parameters,
1274+
# after a line break.
12721275
_SYMBOLIC_OPS = frozenset("()[]{},:.;@=%~") | frozenset(("...",))
12731276

12741277

12751278
def _is_binary_operator(token_type, text):
1276-
is_op_token = token_type == tokenize.OP
1277-
is_conjunction = text in ['and', 'or']
1278-
# NOTE(sigmavirus24): Previously the not_a_symbol check was executed
1279-
# conditionally. Since it is now *always* executed, text may be
1280-
# None. In that case we get a TypeError for `text not in str`.
1281-
not_a_symbol = text and text not in _SYMBOLIC_OPS
1282-
# The % character is strictly speaking a binary operator, but the
1283-
# common usage seems to be to put it next to the format parameters,
1284-
# after a line break.
1285-
return ((is_op_token or is_conjunction) and not_a_symbol)
1279+
return (
1280+
token_type == tokenize.OP or
1281+
text in {'and', 'or'}
1282+
) and (
1283+
text not in _SYMBOLIC_OPS
1284+
)
12861285

12871286

12881287
def _break_around_binary_operators(tokens):

0 commit comments

Comments
 (0)