diff options
author | Anthony Sottile <asottile@umich.edu> | 2022-01-27 11:33:54 -0500 |
---|---|---|
committer | Anthony Sottile <asottile@umich.edu> | 2022-01-27 11:34:08 -0500 |
commit | a6c3f2f86dab22debd1b1b8cf8842ae9d6aec7a0 (patch) | |
tree | db7aaea2745f0d28018a3ee878a193f5eb78f6b7 | |
parent | 85decca0524afe2d9bbf607d189ce641deabc24b (diff) | |
download | pep8-a6c3f2f86dab22debd1b1b8cf8842ae9d6aec7a0.tar.gz |
use short-circuit evaluation in _is_binary_operator
this improves performance by about 1%
-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): |