Enable Do not use Mutable Default Args Error
Flake8 currently ignores do not use mutable default arguments error Enable B006 for more thorough testing of code Change-Id: I5b08a56f945158c3b3c23574c048363e59da6001 Story: 2004515 Task: 30172 Signed-off-by: Eric Barrett <eric.barrett@windriver.com>
This commit is contained in:
parent
be6a275753
commit
687ed8c747
@ -21,8 +21,10 @@ class AuthTokenMiddleware(auth_token.AuthProtocol):
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, app, conf, public_api_routes=[]):
|
||||
def __init__(self, app, conf, public_api_routes=None):
|
||||
self.smapi_app = app
|
||||
if public_api_routes is None:
|
||||
public_api_routes = []
|
||||
self.public_api_routes = set(public_api_routes)
|
||||
|
||||
super(AuthTokenMiddleware, self).__init__(app, conf)
|
||||
|
@ -56,7 +56,9 @@ class PeriodicService(rpc_service.Service, periodic_task.PeriodicTasks):
|
||||
context=admin_context)
|
||||
|
||||
|
||||
def prepare_service(argv=[]):
|
||||
def prepare_service(argv=None):
|
||||
if argv is None:
|
||||
argv = []
|
||||
rpc.set_defaults(control_exchange='sm_api')
|
||||
cfg.set_defaults(log.log_opts,
|
||||
default_log_levels=['amqplib=WARN',
|
||||
|
@ -34,8 +34,8 @@ class DBError(Exception):
|
||||
class DBDuplicateEntry(DBError):
|
||||
"""Wraps an implementation specific exception."""
|
||||
|
||||
def __init__(self, columns=[], inner_exception=None):
|
||||
self.columns = columns
|
||||
def __init__(self, columns=None, inner_exception=None):
|
||||
self.columns = columns if columns is not None else []
|
||||
super(DBDuplicateEntry, self).__init__(inner_exception)
|
||||
|
||||
|
||||
|
@ -33,10 +33,12 @@ class CommandFilter(object):
|
||||
self.args = args
|
||||
self.real_exec = None
|
||||
|
||||
def get_exec(self, exec_dirs=[]):
|
||||
def get_exec(self, exec_dirs=None):
|
||||
"""Returns existing executable, or empty string if none found."""
|
||||
if self.real_exec is not None:
|
||||
return self.real_exec
|
||||
if exec_dirs is None:
|
||||
exec_dirs = []
|
||||
self.real_exec = ""
|
||||
if self.exec_path.startswith('/'):
|
||||
if os.access(self.exec_path, os.X_OK):
|
||||
@ -53,8 +55,10 @@ class CommandFilter(object):
|
||||
"""Only check that the first argument (command) matches exec_path."""
|
||||
return os.path.basename(self.exec_path) == userargs[0]
|
||||
|
||||
def get_command(self, userargs, exec_dirs=[]):
|
||||
def get_command(self, userargs, exec_dirs=None):
|
||||
"""Returns command to execute (with sudo -u if run_as != root)."""
|
||||
if exec_dirs is None:
|
||||
exec_dirs = []
|
||||
to_exec = self.get_exec(exec_dirs=exec_dirs) or self.exec_path
|
||||
if (self.run_as != 'root'):
|
||||
# Used to run commands at lesser privileges
|
||||
@ -125,7 +129,7 @@ class PathFilter(CommandFilter):
|
||||
args_equal_or_pass and
|
||||
paths_are_within_base_dirs)
|
||||
|
||||
def get_command(self, userargs, exec_dirs=[]):
|
||||
def get_command(self, userargs, exec_dirs=None):
|
||||
command, arguments = userargs[0], userargs[1:]
|
||||
|
||||
# convert path values to canonical ones; copy other args as is
|
||||
@ -149,7 +153,7 @@ class DnsmasqFilter(CommandFilter):
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_command(self, userargs, exec_dirs=[]):
|
||||
def get_command(self, userargs, exec_dirs=None):
|
||||
to_exec = self.get_exec(exec_dirs=exec_dirs) or self.exec_path
|
||||
dnsmasq_pos = userargs.index('dnsmasq')
|
||||
return [to_exec] + userargs[dnsmasq_pos + 1:]
|
||||
|
@ -125,7 +125,7 @@ def load_filters(filters_path):
|
||||
return filterlist
|
||||
|
||||
|
||||
def match_filter(filter_list, userargs, exec_dirs=[]):
|
||||
def match_filter(filter_list, userargs, exec_dirs=None):
|
||||
"""
|
||||
Checks user command and arguments through command filters and
|
||||
returns the first matching filter.
|
||||
@ -134,6 +134,8 @@ def match_filter(filter_list, userargs, exec_dirs=[]):
|
||||
best filter match.
|
||||
"""
|
||||
first_not_executable_filter = None
|
||||
if exec_dirs is None:
|
||||
exec_dirs = []
|
||||
|
||||
for f in filter_list:
|
||||
if f.match(userargs):
|
||||
|
@ -72,9 +72,10 @@ def get_reqs_from_files(requirements_files):
|
||||
return []
|
||||
|
||||
|
||||
def parse_requirements(requirements_files=['requirements.txt',
|
||||
'tools/pip-requires']):
|
||||
def parse_requirements(requirements_files=None):
|
||||
requirements = []
|
||||
if requirements_files is None:
|
||||
requirements_files = ['requirements.txt', 'tools/pip-requires']
|
||||
for line in get_reqs_from_files(requirements_files):
|
||||
# For the requirements list, we need to inject only the portion
|
||||
# after egg= so that distutils knows the package it's looking for
|
||||
@ -101,8 +102,9 @@ def parse_requirements(requirements_files=['requirements.txt',
|
||||
return requirements
|
||||
|
||||
|
||||
def parse_dependency_links(requirements_files=['requirements.txt',
|
||||
'tools/pip-requires']):
|
||||
def parse_dependency_links(requirements_files=None):
|
||||
if requirements_files is None:
|
||||
requirements_files = ['requirements.txt', 'tools/pip-requires']
|
||||
dependency_links = []
|
||||
# dependency_links inject alternate locations to find packages listed
|
||||
# in requirements
|
||||
|
@ -85,7 +85,7 @@ def pretty_choice_list(l):
|
||||
return ', '.join("'%s'" % i for i in l)
|
||||
|
||||
|
||||
def print_list(objs, fields, field_labels, formatters={}, sortby=0):
|
||||
def print_list(objs, fields, field_labels, formatters=None, sortby=0):
|
||||
pt = prettytable.PrettyTable([f for f in field_labels],
|
||||
caching=False, print_empty=False)
|
||||
pt.align = 'l'
|
||||
@ -93,7 +93,7 @@ def print_list(objs, fields, field_labels, formatters={}, sortby=0):
|
||||
for o in objs:
|
||||
row = []
|
||||
for field in fields:
|
||||
if field in formatters:
|
||||
if formatters and field in formatters:
|
||||
row.append(formatters[field](o))
|
||||
else:
|
||||
data = getattr(o, field, '')
|
||||
@ -102,7 +102,7 @@ def print_list(objs, fields, field_labels, formatters={}, sortby=0):
|
||||
print(pt.get_string(sortby=field_labels[sortby]))
|
||||
|
||||
|
||||
def print_tuple_list(tuples, tuple_labels=[]):
|
||||
def print_tuple_list(tuples, tuple_labels=None):
|
||||
pt = prettytable.PrettyTable(['Property', 'Value'],
|
||||
caching=False, print_empty=False)
|
||||
pt.align = 'l'
|
||||
|
@ -33,7 +33,7 @@ class CommandFilter(object):
|
||||
self.args = args
|
||||
self.real_exec = None
|
||||
|
||||
def get_exec(self, exec_dirs=[]):
|
||||
def get_exec(self, exec_dirs=None):
|
||||
"""Returns existing executable, or empty string if none found."""
|
||||
if self.real_exec is not None:
|
||||
return self.real_exec
|
||||
@ -41,7 +41,7 @@ class CommandFilter(object):
|
||||
if self.exec_path.startswith('/'):
|
||||
if os.access(self.exec_path, os.X_OK):
|
||||
self.real_exec = self.exec_path
|
||||
else:
|
||||
elif exec_dirs is not None:
|
||||
for binary_path in exec_dirs:
|
||||
expanded_path = os.path.join(binary_path, self.exec_path)
|
||||
if os.access(expanded_path, os.X_OK):
|
||||
@ -53,7 +53,7 @@ class CommandFilter(object):
|
||||
"""Only check that the first argument (command) matches exec_path."""
|
||||
return os.path.basename(self.exec_path) == userargs[0]
|
||||
|
||||
def get_command(self, userargs, exec_dirs=[]):
|
||||
def get_command(self, userargs, exec_dirs=None):
|
||||
"""Returns command to execute (with sudo -u if run_as != root)."""
|
||||
to_exec = self.get_exec(exec_dirs=exec_dirs) or self.exec_path
|
||||
if (self.run_as != 'root'):
|
||||
@ -125,7 +125,7 @@ class PathFilter(CommandFilter):
|
||||
args_equal_or_pass and
|
||||
paths_are_within_base_dirs)
|
||||
|
||||
def get_command(self, userargs, exec_dirs=[]):
|
||||
def get_command(self, userargs, exec_dirs=None):
|
||||
command, arguments = userargs[0], userargs[1:]
|
||||
|
||||
# convert path values to canonical ones; copy other args as is
|
||||
@ -149,7 +149,7 @@ class DnsmasqFilter(CommandFilter):
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_command(self, userargs, exec_dirs=[]):
|
||||
def get_command(self, userargs, exec_dirs=None):
|
||||
to_exec = self.get_exec(exec_dirs=exec_dirs) or self.exec_path
|
||||
dnsmasq_pos = userargs.index('dnsmasq')
|
||||
return [to_exec] + userargs[dnsmasq_pos + 1:]
|
||||
|
@ -126,7 +126,7 @@ def load_filters(filters_path):
|
||||
return filterlist
|
||||
|
||||
|
||||
def match_filter(filter_list, userargs, exec_dirs=[]):
|
||||
def match_filter(filter_list, userargs, exec_dirs=None):
|
||||
"""check user command and args
|
||||
|
||||
Checks user command and arguments through command filters and
|
||||
@ -136,6 +136,8 @@ def match_filter(filter_list, userargs, exec_dirs=[]):
|
||||
best filter match.
|
||||
"""
|
||||
first_not_executable_filter = None
|
||||
if exec_dirs is None:
|
||||
exec_dirs = []
|
||||
|
||||
for f in filter_list:
|
||||
if f.match(userargs):
|
||||
|
3
tox.ini
3
tox.ini
@ -70,14 +70,13 @@ commands =
|
||||
# F811 redefinition of unused '<foo>' from line <x>
|
||||
# F821 undefined name 'e'
|
||||
# - bugbear -
|
||||
# B006 Do not use mutable data structures for argument defaults. (python3)
|
||||
# B008 Do not perform calls in argument defaults. The call is performed only once at function definition time.
|
||||
# B009: Do not call getattr with a constant attribute value
|
||||
# B010: Do not call setattr with a constant attribute value
|
||||
ignore= E402,
|
||||
H102,H104,H105,H106,H306,H401,H403,H404,H405,H501,
|
||||
F811,F821,
|
||||
B006,B008,B009,B010
|
||||
B008,B009,B010
|
||||
# Enable checks which are off by default
|
||||
# H106 Don’t put vim configuration in source files (off by default). SHOULD BE ENABLED.
|
||||
# H203 Use assertIs(Not)None to check for None (off by default).
|
||||
|
Loading…
x
Reference in New Issue
Block a user