57
57
import xml .etree .ElementTree
58
58
59
59
# if empty, use defaults
60
- _valid_extensions = set ([] )
60
+ _valid_extensions = set ()
61
61
62
62
__VERSION__ = '2.0.1'
63
63
826
826
]
827
827
828
828
# Replacement macros for CHECK/DCHECK/EXPECT_TRUE/EXPECT_FALSE
829
- _CHECK_REPLACEMENT = dict ([( macro_var , {}) for macro_var in _CHECK_MACROS ])
829
+ _CHECK_REPLACEMENT = { macro_var : {} for macro_var in _CHECK_MACROS }
830
830
831
831
for op , replacement in [('==' , 'EQ' ), ('!=' , 'NE' ),
832
832
('>=' , 'GE' ), ('>' , 'GT' ),
945
945
946
946
# Treat all headers starting with 'h' equally: .h, .hpp, .hxx etc.
947
947
# This is set by --headers flag.
948
- _hpp_headers = set ([] )
948
+ _hpp_headers = set ()
949
949
950
950
class ErrorSuppressions :
951
951
"""Class to track all error suppressions for cpplint"""
@@ -1038,13 +1038,12 @@ def GetHeaderExtensions():
1038
1038
return _hpp_headers
1039
1039
if _valid_extensions :
1040
1040
return {h for h in _valid_extensions if 'h' in h }
1041
- return set ([ 'h' , 'hh' , 'hpp' , 'hxx' , 'h++' , 'cuh' ])
1041
+ return { 'h' , 'hh' , 'hpp' , 'hxx' , 'h++' , 'cuh' }
1042
1042
1043
1043
# The allowed extensions for file names
1044
1044
# This is set by --extensions flag
1045
1045
def GetAllExtensions ():
1046
- return GetHeaderExtensions ().union (_valid_extensions or set (
1047
- ['c' , 'cc' , 'cpp' , 'cxx' , 'c++' , 'cu' ]))
1046
+ return GetHeaderExtensions ().union (_valid_extensions or {'c' , 'cc' , 'cpp' , 'cxx' , 'c++' , 'cu' })
1048
1047
1049
1048
def ProcessExtensionsOption (val ):
1050
1049
global _valid_extensions
@@ -1101,7 +1100,7 @@ def ProcessCategory(category):
1101
1100
if categories in (None , '(*)' ): # => "suppress all"
1102
1101
ProcessCategory (None )
1103
1102
elif categories .startswith ('(' ) and categories .endswith (')' ):
1104
- for category in set ( map ( lambda c : c .strip (), categories [1 :- 1 ].split (',' ))) :
1103
+ for category in { c .strip () for c in categories [1 :- 1 ].split (',' )} :
1105
1104
if category in _ERROR_CATEGORIES :
1106
1105
ProcessCategory (category )
1107
1106
elif any (c for c in _OTHER_NOLINT_CATEGORY_PREFIXES if category .startswith (c )):
@@ -6073,13 +6072,12 @@ def ExpectingFunctionArgs(clean_lines, linenum):
6073
6072
6074
6073
_re_pattern_headers_maybe_templates = []
6075
6074
for _header , _templates in _HEADERS_MAYBE_TEMPLATES :
6076
- for _template in _templates :
6077
- # Match max<type>(..., ...), max(..., ...), but not foo->max, foo.max or
6078
- # 'type::max()'.
6079
- _re_pattern_headers_maybe_templates .append (
6080
- (re .compile (r'((\bstd::)|[^>.:])\b' + _template + r'(<.*?>)?\([^\)]' ),
6081
- _template ,
6082
- _header ))
6075
+ # Match max<type>(..., ...), max(..., ...), but not foo->max, foo.max or
6076
+ # 'type::max()'.
6077
+ _re_pattern_headers_maybe_templates .extend (
6078
+ (re .compile (r'((\bstd::)|[^>.:])\b' + _template + r'(<.*?>)?\([^\)]' ),
6079
+ _template ,
6080
+ _header ) for _template in _templates )
6083
6081
6084
6082
# Map is often overloaded. Only check, if it is fully qualified.
6085
6083
# Match 'std::map<type>(...)', but not 'map<type>(...)''
@@ -6091,29 +6089,26 @@ def ExpectingFunctionArgs(clean_lines, linenum):
6091
6089
# Other scripts may reach in and modify this pattern.
6092
6090
_re_pattern_templates = []
6093
6091
for _header , _templates in _HEADERS_CONTAINING_TEMPLATES :
6094
- for _template in _templates :
6095
- _re_pattern_templates .append (
6096
- (re .compile (r'((^|(^|\s|((^|\W)::))std::)|[^>.:]\b)' + _template + r'\s*\<' ),
6097
- _template + '<>' ,
6098
- _header ))
6092
+ _re_pattern_templates .extend (
6093
+ (re .compile (r'((^|(^|\s|((^|\W)::))std::)|[^>.:]\b)' + _template + r'\s*\<' ),
6094
+ _template + '<>' ,
6095
+ _header ) for _template in _templates )
6099
6096
6100
6097
_re_pattern_types_or_objs = []
6101
6098
for _header , _types_or_objs in _HEADERS_TYPES_OR_OBJS :
6102
- for _type_or_obj in _types_or_objs :
6103
- _re_pattern_types_or_objs .append (
6104
- (re .compile (r'\b' + _type_or_obj + r'\b' ),
6105
- _type_or_obj ,
6106
- _header ))
6099
+ _re_pattern_types_or_objs .extend (
6100
+ (re .compile (r'\b' + _type_or_obj + r'\b' ),
6101
+ _type_or_obj ,
6102
+ _header ) for _type_or_obj in _types_or_objs )
6107
6103
6108
6104
_re_pattern_functions = []
6109
6105
for _header , _functions in _HEADERS_FUNCTIONS :
6110
- for _function in _functions :
6111
- # Match printf(..., ...), but not foo->printf, foo.printf or
6112
- # 'type::printf()'.
6113
- _re_pattern_functions .append (
6114
- (re .compile (r'([^>.]|^)\b' + _function + r'\([^\)]' ),
6115
- _function ,
6116
- _header ))
6106
+ # Match printf(..., ...), but not foo->printf, foo.printf or
6107
+ # 'type::printf()'.
6108
+ _re_pattern_functions .extend (
6109
+ (re .compile (r'([^>.]|^)\b' + _function + r'\([^\)]' ),
6110
+ _function ,
6111
+ _header ) for _function in _functions )
6117
6112
6118
6113
def FilesBelongToSameModule (filename_cc , filename_h ):
6119
6114
"""Check if these two filenames belong to the same module.
@@ -6750,8 +6745,8 @@ def PrintUsage(message):
6750
6745
Args:
6751
6746
message: The optional error message.
6752
6747
"""
6753
- sys .stderr .write (_USAGE % (sorted (list ( GetAllExtensions () )),
6754
- ',' .join (sorted (list ( GetAllExtensions () ))),
6748
+ sys .stderr .write (_USAGE % (sorted (GetAllExtensions ()),
6749
+ ',' .join (sorted (GetAllExtensions ())),
6755
6750
sorted (GetHeaderExtensions ()),
6756
6751
',' .join (sorted (GetHeaderExtensions ()))))
6757
6752
@@ -6933,11 +6928,8 @@ def _ExpandDirectories(filenames):
6933
6928
fullname = fullname [len ('.' + os .path .sep ):]
6934
6929
expanded .add (fullname )
6935
6930
6936
- filtered = []
6937
- for filename in expanded :
6938
- if os .path .splitext (filename )[1 ][1 :] in GetAllExtensions ():
6939
- filtered .append (filename )
6940
- return filtered
6931
+ return [filename for filename in expanded
6932
+ if os .path .splitext (filename )[1 ][1 :] in GetAllExtensions ()]
6941
6933
6942
6934
def _FilterExcludedFiles (fnames ):
6943
6935
"""Filters out files listed in the --exclude command line switch. File paths
0 commit comments