Globalize regex objects

Using re.compile() and saving the resulting regular expression object
for reuse is more efficient when the expression will be used several
times in a single program. [1]

[1] https://docs.python.org/3/library/re.html#re.compile

Change-Id: I5441b44d0bb034b7632e6805adbfd3d8895890ef
This commit is contained in:
Ngo Quoc Cuong 2017-07-12 02:21:08 -04:00
parent 431d356c8a
commit b559e2c429

View File

@ -35,6 +35,7 @@ Guidelines for writing new hacking checks
UNDERSCORE_IMPORT_FILES = ['cinder/objects/__init__.py',
'cinder/objects/manageableresources.py']
mutable_default_args = re.compile(r"^\s*def .+\((.+=\{\}|.+=\[\])")
translated_log = re.compile(
r"(.)*LOG\.(audit|debug|error|info|warn|warning|critical|exception)"
"\(\s*_\(\s*('|\")")
@ -141,7 +142,6 @@ def no_translate_logs(logical_line, filename):
def no_mutable_default_args(logical_line):
msg = "N322: Method's default argument shouldn't be mutable!"
mutable_default_args = re.compile(r"^\s*def .+\((.+=\{\}|.+=\[\])")
if mutable_default_args.match(logical_line):
yield (0, msg)