cleanup pylint error: dangerous-default-value

un-suppress the pylint error check for dangerous-default value,
and update the code to fix that error

Test Plan:
PASS: system helm-override-update

Story: 2008943
Task: 43986

Signed-off-by: Jia Hu <jia.hu@windriver.com>
Change-Id: I28be0e2f0245158b72023033378e6e39f45775c8
This commit is contained in:
Jia Hu 2021-11-15 16:37:51 -05:00
parent 42f23f5211
commit bb8abd2c21
4 changed files with 62 additions and 13 deletions

View File

@ -81,7 +81,9 @@ def _wrapping_formatter_callback_decorator(subparser, command, callback):
def no_wrap_decorator_builder(callback):
def process_callback_with_no_wrap(cc, args={}):
def process_callback_with_no_wrap(cc, args=None):
if args is None:
args = {}
no_wrap = args.nowrap
# turn on/off wrapping formatters when outputting CLI results
wrapping_formatters.set_no_wrap(no_wrap)
@ -197,7 +199,10 @@ def pretty_choice_list(l):
return ', '.join("'%s'" % i for i in l)
def _sort_for_list(objs, fields, formatters={}, sortby=0, reversesort=False):
def _sort_for_list(objs, fields, formatters=None, sortby=0, reversesort=False):
if formatters is None:
formatters = {}
# Sort only if necessary
if sortby is None:
@ -359,10 +364,16 @@ def parse_date(string_data):
return re.sub(pattern, convert_date, string_data)
def print_list(objs, fields, field_labels, formatters={}, sortby=0,
reversesort=False, no_wrap_fields=[], printer=default_printer,
def print_list(objs, fields, field_labels, formatters=None, sortby=0,
reversesort=False, no_wrap_fields=None, printer=default_printer,
output_format=None):
if formatters is None:
formatters = {}
if no_wrap_fields is None:
no_wrap_fields = []
if output_format == 'yaml' or output_format == 'value':
my_dict_list = []
for o in objs:
@ -399,7 +410,14 @@ def _build_row_from_object(fields, formatters, o):
return row
def print_tuple_list(tuples, tuple_labels=[], formatters={}):
def print_tuple_list(tuples, tuple_labels=None, formatters=None):
if tuple_labels is None:
tuple_labels = []
if formatters is None:
formatters = {}
pt = prettytable.PrettyTable(['Property', 'Value'],
caching=False, print_empty=False)
pt.align = 'l'
@ -439,9 +457,15 @@ def row_height(texts):
return height
def print_long_list(objs, fields, field_labels, formatters={}, sortby=0, reversesort=False, no_wrap_fields=[],
def print_long_list(objs, fields, field_labels, formatters=None, sortby=0, reversesort=False, no_wrap_fields=None,
no_paging=False, printer=default_printer):
if formatters is None:
formatters = {}
if no_wrap_fields is None:
no_wrap_fields = []
formatters = wrapping_formatters.as_wrapping_formatters(objs, fields, field_labels, formatters,
no_wrap_fields=no_wrap_fields)

View File

@ -425,7 +425,11 @@ def wrapper_formatter_factory(ctx, field, formatter):
raise Exception("Formatter Error! Unrecognized formatter {} for field {}".format(formatter, field))
def build_column_stats_for_best_guess_formatting(objs, fields, field_labels, custom_formatters={}):
def build_column_stats_for_best_guess_formatting(objs, fields, field_labels, custom_formatters=None):
if custom_formatters is None:
custom_formatters = {}
class ColumnStats:
def __init__(self, field, field_label, custom_formatter=None):
self.field = field
@ -513,7 +517,15 @@ def build_column_stats_for_best_guess_formatting(objs, fields, field_labels, cus
"total_avg_width": total_avg_width}
def build_best_guess_formatters_using_average_widths(objs, fields, field_labels, custom_formatters={}, no_wrap_fields=[]):
def build_best_guess_formatters_using_average_widths(objs, fields, field_labels,
custom_formatters=None, no_wrap_fields=None):
if custom_formatters is None:
custom_formatters = {}
if no_wrap_fields is None:
no_wrap_fields = []
column_info = build_column_stats_for_best_guess_formatting(objs, fields, field_labels, custom_formatters)
format_spec = {}
total_avg_width = float(column_info["total_avg_width"])
@ -535,7 +547,15 @@ def build_best_guess_formatters_using_average_widths(objs, fields, field_labels,
return format_spec
def build_best_guess_formatters_using_max_widths(objs, fields, field_labels, custom_formatters={}, no_wrap_fields=[]):
def build_best_guess_formatters_using_max_widths(objs, fields, field_labels,
custom_formatters=None, no_wrap_fields=None):
if custom_formatters is None:
custom_formatters = {}
if no_wrap_fields is None:
no_wrap_fields = []
column_info = build_column_stats_for_best_guess_formatting(objs, fields, field_labels, custom_formatters)
format_spec = {}
for f in [ff for ff in fields if ff not in no_wrap_fields]:
@ -575,7 +595,7 @@ def needs_wrapping_formatters(formatters, no_wrap=None):
return True
def as_wrapping_formatters(objs, fields, field_labels, formatters, no_wrap=None, no_wrap_fields=[]):
def as_wrapping_formatters(objs, fields, field_labels, formatters, no_wrap=None, no_wrap_fields=None):
"""This function is the entry point for building the "best guess"
word wrapping formatters. A best guess formatter guesses what the best
columns widths should be for the table celldata. It does this by collecting
@ -600,6 +620,10 @@ def as_wrapping_formatters(objs, fields, field_labels, formatters, no_wrap=None,
When wrapping is required, best-guess word wrapping formatters are returned
with original parameter formatters embedded in the word wrapping formatters
"""
if no_wrap_fields is None:
no_wrap_fields = []
no_wrap = is_nowrap_set(no_wrap)
if not needs_wrapping_formatters(formatters, no_wrap):

View File

@ -47,7 +47,7 @@ class HelmManager(base.Manager):
return None
def update_overrides(self, app, name, namespace,
flag='reset', override_values={}):
flag='reset', override_values=None):
"""Update overrides for a given chart.
:param app_name: name of application
@ -59,6 +59,8 @@ class HelmManager(base.Manager):
This will return the end-user overrides for the specified chart.
"""
if override_values is None:
override_values = {}
body = {'flag': flag, 'values': override_values, 'attributes': {}}
return self._update(self._path(app) +
'?name=' + name +

View File

@ -113,7 +113,6 @@ enable=E1603,E1609,E1610,E1602,E1606,E1608,E1607,E1605,E1604,E1601,E1611,W1652,
# We are not disabling (F)atal, (E)rror
# The following warnings are disabled and should be fixed:
# fixme (notes, todo, xxx)
# W0102: dangerous-default-value
# W0105: pointless-string-statement
# W0108: unnecessary-lambda
# W0110: deprecated-lambda
@ -136,7 +135,7 @@ enable=E1603,E1609,E1610,E1602,E1606,E1608,E1607,E1605,E1604,E1601,E1611,W1652,
# W1201: logging-not-lazy
# W1401: anomalous-backslash-in-string
# W1618: no-absolute-import
disable=C, R, fixme, W0102, W0105, W0108, W0110, W0120, W0123,
disable=C, R, fixme, W0105, W0108, W0110, W0120, W0123,
W0201, W0212, W0231, W0235, W0402, W0403, W0603, W0611,
W0612, W0613, W0621, W0622, W0631, W0703, W1201, W1401,
W1618