@@ -1620,8 +1620,7 @@ def Check(self, error, filename, linenum):
1620
1620
if self .lines_in_function > trigger :
1621
1621
error_level = int (math .log2 (self .lines_in_function / base_trigger ))
1622
1622
# 50 => 0, 100 => 1, 200 => 2, 400 => 3, 800 => 4, 1600 => 5, ...
1623
- if error_level > 5 :
1624
- error_level = 5
1623
+ error_level = min (error_level , 5 )
1625
1624
error (filename , linenum , 'readability/fn_size' , error_level ,
1626
1625
'Small and focused functions are preferred:'
1627
1626
f' { self .current_function } has { self .lines_in_function } non-comment lines'
@@ -1759,8 +1758,8 @@ def _ShouldPrintError(category, confidence, filename, linenum):
1759
1758
for one_filter in _Filters ():
1760
1759
filter_cat , filter_file , filter_line = _ParseFilterSelector (one_filter [1 :])
1761
1760
category_match = category .startswith (filter_cat )
1762
- file_match = filter_file == "" or filter_file == filename
1763
- line_match = filter_line == linenum or filter_line == - 1
1761
+ file_match = filter_file in ( "" , filename )
1762
+ line_match = filter_line in ( linenum , - 1 )
1764
1763
1765
1764
if one_filter .startswith ('-' ):
1766
1765
if category_match and file_match and line_match :
@@ -3344,7 +3343,7 @@ def Update(self, filename, clean_lines, linenum, error):
3344
3343
if _MATCH_ASM .match (line ):
3345
3344
self .stack [- 1 ].inline_asm = _BLOCK_ASM
3346
3345
3347
- elif token == ';' or token == ')' :
3346
+ elif token in { ';' , ')' } :
3348
3347
# If we haven't seen an opening brace yet, but we already saw
3349
3348
# a semicolon, this is probably a forward declaration. Pop
3350
3349
# the stack for these.
@@ -3674,8 +3673,7 @@ def CheckForFunctionLengths(filename, clean_lines, linenum,
3674
3673
# If the name is all caps and underscores, figure it's a macro and
3675
3674
# ignore it, unless it's TEST or TEST_F.
3676
3675
function_name = match_result .group (1 ).split ()[- 1 ]
3677
- if function_name == 'TEST' or function_name == 'TEST_F' or (
3678
- not re .match (r'[A-Z_]+$' , function_name )):
3676
+ if function_name in {'TEST' , 'TEST_F' } or not re .match (r'[A-Z_]+$' , function_name ):
3679
3677
starting_func = True
3680
3678
3681
3679
if starting_func :
@@ -3753,7 +3751,7 @@ def CheckComment(line, filename, linenum, next_line_start, error):
3753
3751
middle_whitespace = match .group (3 )
3754
3752
# Comparisons made explicit for correctness
3755
3753
# -- pylint: disable=g-explicit-bool-comparison
3756
- if middle_whitespace != ' ' and middle_whitespace != '' :
3754
+ if middle_whitespace not in { ' ' , '' } :
3757
3755
error (filename , linenum , 'whitespace/todo' , 2 ,
3758
3756
'TODO(my_username) should be followed by a space' )
3759
3757
@@ -4973,7 +4971,7 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
4973
4971
# (of lines ending in double quotes, commas, equals, or angle brackets)
4974
4972
# because the rules for how to indent those are non-trivial.
4975
4973
if (not re .search (r'[",=><] *$' , prev ) and
4976
- (initial_spaces == 1 or initial_spaces == 3 ) and
4974
+ (initial_spaces in { 1 , 3 } ) and
4977
4975
not re .match (scope_or_label_pattern , cleansed_line ) and
4978
4976
not (clean_lines .raw_lines [linenum ] != line and
4979
4977
re .match (r'^\s*""' , line ))):
@@ -5138,8 +5136,7 @@ def _ClassifyInclude(fileinfo, include, used_angle_brackets, include_order="defa
5138
5136
target_dir_pub = os .path .normpath (target_dir + '/../public' )
5139
5137
target_dir_pub = target_dir_pub .replace ('\\ ' , '/' )
5140
5138
if target_base == include_base and (
5141
- include_dir == target_dir or
5142
- include_dir == target_dir_pub ):
5139
+ include_dir in (target_dir , target_dir_pub )):
5143
5140
return _LIKELY_MY_HEADER
5144
5141
5145
5142
# If the target and include share some initial basename
@@ -6824,7 +6821,7 @@ def ParseArguments(args):
6824
6821
output_format = val
6825
6822
elif opt == '--quiet' :
6826
6823
quiet = True
6827
- elif opt == '--verbose' or opt == '--v' :
6824
+ elif opt in { '--verbose' , '--v' } :
6828
6825
verbosity = int (val )
6829
6826
elif opt == '--filter' :
6830
6827
filters = val
0 commit comments