diff options
author | Ian Stapleton Cordasco <graffatcolmingov@gmail.com> | 2022-01-27 11:17:33 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-27 11:17:33 -0600 |
commit | 6678922f8d4fb6a34fb77f4f5a7992ade45aaf2f (patch) | |
tree | db7aaea2745f0d28018a3ee878a193f5eb78f6b7 | |
parent | 85decca0524afe2d9bbf607d189ce641deabc24b (diff) | |
parent | a6c3f2f86dab22debd1b1b8cf8842ae9d6aec7a0 (diff) | |
download | pep8-6678922f8d4fb6a34fb77f4f5a7992ade45aaf2f.tar.gz |
Merge pull request #1052 from PyCQA/short-circuit
use short-circuit evaluation in _is_binary_operator
-rwxr-xr-x | pycodestyle.py | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/pycodestyle.py b/pycodestyle.py index d291637..2cbc2cd 100755 --- a/pycodestyle.py +++ b/pycodestyle.py @@ -1269,20 +1269,19 @@ def explicit_line_join(logical_line, tokens): parens -= 1 +# The % character is strictly speaking a binary operator, but the +# common usage seems to be to put it next to the format parameters, +# after a line break. _SYMBOLIC_OPS = frozenset("()[]{},:.;@=%~") | frozenset(("...",)) def _is_binary_operator(token_type, text): - is_op_token = token_type == tokenize.OP - is_conjunction = text in ['and', 'or'] - # NOTE(sigmavirus24): Previously the not_a_symbol check was executed - # conditionally. Since it is now *always* executed, text may be - # None. In that case we get a TypeError for `text not in str`. - not_a_symbol = text and text not in _SYMBOLIC_OPS - # The % character is strictly speaking a binary operator, but the - # common usage seems to be to put it next to the format parameters, - # after a line break. - return ((is_op_token or is_conjunction) and not_a_symbol) + return ( + token_type == tokenize.OP or + text in {'and', 'or'} + ) and ( + text not in _SYMBOLIC_OPS + ) def _break_around_binary_operators(tokens): |