@@ -1103,8 +1103,7 @@ def ParseNolintSuppressions(filename, raw_line, linenum, error):
1103
1103
linenum: int, the number of the current line.
1104
1104
error: function, an error handler.
1105
1105
"""
1106
- matched = re .search (r"\bNOLINT(NEXTLINE|BEGIN|END)?\b(\([^)]+\))?" , raw_line )
1107
- if matched :
1106
+ if matched := re .search (r"\bNOLINT(NEXTLINE|BEGIN|END)?\b(\([^)]+\))?" , raw_line ):
1108
1107
no_lint_type = matched .group (1 )
1109
1108
if no_lint_type == "NEXTLINE" :
1110
1109
@@ -2460,8 +2459,7 @@ def GetIndentLevel(line):
2460
2459
Returns:
2461
2460
An integer count of leading spaces, possibly zero.
2462
2461
"""
2463
- indent = re .match (r"^( *)\S" , line )
2464
- if indent :
2462
+ if indent := re .match (r"^( *)\S" , line ):
2465
2463
return len (indent .group (1 ))
2466
2464
return 0
2467
2465
@@ -3935,8 +3933,7 @@ def CheckForFunctionLengths(filename, clean_lines, linenum, function_state, erro
3935
3933
3936
3934
starting_func = False
3937
3935
regexp = r"(\w(\w|::|\*|\&|\s)*)\(" # decls * & space::name( ...
3938
- match_result = re .match (regexp , line )
3939
- if match_result :
3936
+ if match_result := re .match (regexp , line ):
3940
3937
# If the name is all caps and underscores, figure it's a macro and
3941
3938
# ignore it, unless it's TEST or TEST_F.
3942
3939
function_name = match_result .group (1 ).split ()[- 1 ]
@@ -4410,8 +4407,7 @@ def _IsType(clean_lines, nesting_state, expr):
4410
4407
True, if token looks like a type.
4411
4408
"""
4412
4409
# Keep only the last token in the expression
4413
- last_word = re .match (r"^.*(\b\S+)$" , expr )
4414
- if last_word :
4410
+ if last_word := re .match (r"^.*(\b\S+)$" , expr ):
4415
4411
token = last_word .group (1 )
4416
4412
else :
4417
4413
token = expr
@@ -4479,9 +4475,8 @@ def CheckBracesSpacing(filename, clean_lines, linenum, nesting_state, error):
4479
4475
# And since you should never have braces at the beginning of a line,
4480
4476
# this is an easy test. Except that braces used for initialization don't
4481
4477
# follow the same rule; we often don't want spaces before those.
4482
- match = re .match (r"^(.*[^ ({>]){" , line )
4483
4478
4484
- if match :
4479
+ if match := re . match ( r"^(.*[^ ({>]){" , line ) :
4485
4480
# Try a bit harder to check for brace initialization. This
4486
4481
# happens in one of the following forms:
4487
4482
# Constructor() : initializer_list_{} { ... }
@@ -5017,8 +5012,7 @@ def CheckEmptyBlockBody(filename, clean_lines, linenum, error):
5017
5012
# We also check "if" blocks here, since an empty conditional block
5018
5013
# is likely an error.
5019
5014
line = clean_lines .elided [linenum ]
5020
- matched = re .match (r"\s*(for|while|if)\s*\(" , line )
5021
- if matched :
5015
+ if matched := re .match (r"\s*(for|while|if)\s*\(" , line ):
5022
5016
# Find the end of the conditional expression.
5023
5017
(end_line , end_linenum , end_pos ) = CloseExpression (clean_lines , linenum , line .find ("(" ))
5024
5018
@@ -5911,8 +5905,7 @@ def CheckLanguage(
5911
5905
# convention of the whole function to process multiple line to handle it.
5912
5906
# printf(
5913
5907
# boy_this_is_a_really_long_variable_that_cannot_fit_on_the_prev_line);
5914
- printf_args = _GetTextInside (line , r"(?i)\b(string)?printf\s*\(" )
5915
- if printf_args :
5908
+ if printf_args := _GetTextInside (line , r"(?i)\b(string)?printf\s*\(" ):
5916
5909
match = re .match (r"([\w.\->()]+)$" , printf_args )
5917
5910
if match and match .group (1 ) != "__VA_ARGS__" :
5918
5911
function_name = re .search (r"\b((?:string)?printf)\s*\(" , line , re .IGNORECASE ).group (1 )
@@ -6858,8 +6851,7 @@ def FilesBelongToSameModule(filename_cc, filename_h):
6858
6851
return (False , "" )
6859
6852
6860
6853
filename_cc = filename_cc [: - (len (fileinfo_cc .Extension ()))]
6861
- matched_test_suffix = re .search (_TEST_FILE_SUFFIX , fileinfo_cc .BaseName ())
6862
- if matched_test_suffix :
6854
+ if matched_test_suffix := re .search (_TEST_FILE_SUFFIX , fileinfo_cc .BaseName ()):
6863
6855
filename_cc = filename_cc [: - len (matched_test_suffix .group (1 ))]
6864
6856
6865
6857
filename_cc = filename_cc .replace ("/public/" , "/" )
@@ -7067,8 +7059,7 @@ def CheckRedundantOverrideOrFinal(filename, clean_lines, linenum, error):
7067
7059
# the declarator ends and where the virt-specifier starts to avoid
7068
7060
# false positives.
7069
7061
line = clean_lines .elided [linenum ]
7070
- declarator_end = line .rfind (")" )
7071
- if declarator_end >= 0 :
7062
+ if (declarator_end := line .rfind (")" )) >= 0 :
7072
7063
fragment = line [declarator_end :]
7073
7064
else :
7074
7065
if linenum > 1 and clean_lines .elided [linenum - 1 ].rfind (")" ) >= 0 :
0 commit comments