From abfaecad47d2db0291ebe35c9147be33c968866b Mon Sep 17 00:00:00 2001 From: "martin.holmer@gmail.com" Date: Thu, 2 Jan 2025 16:25:52 -0500 Subject: [PATCH] Fix pylint R1734 warnings --- taxcalc/calculator.py | 8 ++++---- taxcalc/parameters.py | 2 +- taxcalc/tests/test_benefits.py | 10 +++++----- taxcalc/tests/test_calcfunctions.py | 6 +++--- taxcalc/tests/test_calculator.py | 4 ++-- taxcalc/tests/test_compatible_data.py | 2 +- taxcalc/tests/test_consumption.py | 2 +- taxcalc/tests/test_data.py | 6 +++--- taxcalc/tests/test_parameters.py | 6 +++--- taxcalc/tests/test_puf_var_stats.py | 4 ++-- taxcalc/tests/test_records.py | 10 +++++----- taxcalc/tests/test_reforms.py | 4 ++-- taxcalc/tests/test_taxcalcio.py | 2 +- taxcalc/tests/test_utils.py | 4 ++-- taxcalc/utils.py | 6 +++--- 15 files changed, 38 insertions(+), 38 deletions(-) diff --git a/taxcalc/calculator.py b/taxcalc/calculator.py index bfe4c1edd..0786a09c8 100644 --- a/taxcalc/calculator.py +++ b/taxcalc/calculator.py @@ -345,8 +345,8 @@ def diagnostic_table(self, num_years): max_num_years = self.__policy.end_year - self.__policy.current_year + 1 assert num_years <= max_num_years calc = copy.deepcopy(self) - yearlist = list() - varlist = list() + yearlist = [] + varlist = [] for iyr in range(1, num_years + 1): calc.calc_all() yearlist.append(calc.current_year) @@ -1165,7 +1165,7 @@ def lines(text, num_indent_spaces, max_line_length=77): return [line] # all text does not fix on one line first_line = True - line_list = list() + line_list = [] words = text.split() while words: if first_line: @@ -1189,7 +1189,7 @@ def lines(text, num_indent_spaces, max_line_length=77): baseline.set_year(year) updated.set_year(year) assert set(baseline.keys()) == set(updated.keys()) - params_with_diff = list() + params_with_diff = [] for pname in baseline.keys(): upda_value = getattr(updated, pname) base_value = getattr(baseline, pname) diff --git a/taxcalc/parameters.py b/taxcalc/parameters.py index e0b6ca511..545b2c6f8 100644 --- a/taxcalc/parameters.py +++ b/taxcalc/parameters.py @@ -752,7 +752,7 @@ def years_in_revision(revision): assumed to have a param:year:value format. """ assert isinstance(revision, dict) - years = list() + years = [] for _, paramdata in revision.items(): assert isinstance(paramdata, dict) for year, _ in paramdata.items(): diff --git a/taxcalc/tests/test_benefits.py b/taxcalc/tests/test_benefits.py index be0dbf7d8..03cf82f11 100644 --- a/taxcalc/tests/test_benefits.py +++ b/taxcalc/tests/test_benefits.py @@ -33,11 +33,11 @@ def test_benefits(tests_path, cps_fullsample): start_year = recs.current_year calc = Calculator(policy=Policy(), records=recs, verbose=False) assert calc.current_year == start_year - year_list = list() - bname_list = list() - benamt_list = list() - bencnt_list = list() - benavg_list = list() + year_list = [] + bname_list = [] + benamt_list = [] + bencnt_list = [] + benavg_list = [] for year in range(start_year, 2034 + 1): calc.advance_to_year(year) size = calc.array('XTOT') diff --git a/taxcalc/tests/test_calcfunctions.py b/taxcalc/tests/test_calcfunctions.py index c9a795d3b..b1f31f66b 100644 --- a/taxcalc/tests/test_calcfunctions.py +++ b/taxcalc/tests/test_calcfunctions.py @@ -23,7 +23,7 @@ def __init__(self): GetFuncDefs class constructor """ self.fname = '' - self.fnames = list() # function name (fname) list + self.fnames = [] # function name (fname) list self.fargs = {} # lists of function arguments indexed by fname self.cvars = {} # lists of calc vars in function indexed by fname self.rvars = {} # lists of function return vars indexed by fname @@ -41,10 +41,10 @@ def visit_FunctionDef(self, node): # pylint: disable=invalid-name """ self.fname = node.name self.fnames.append(self.fname) - self.fargs[self.fname] = list() + self.fargs[self.fname] = [] for anode in ast.iter_child_nodes(node.args): self.fargs[self.fname].append(anode.arg) - self.cvars[self.fname] = list() + self.cvars[self.fname] = [] for bodynode in node.body: if isinstance(bodynode, ast.Return): continue # skip function's Return node diff --git a/taxcalc/tests/test_calculator.py b/taxcalc/tests/test_calculator.py index 110916b31..955131b7e 100644 --- a/taxcalc/tests/test_calculator.py +++ b/taxcalc/tests/test_calculator.py @@ -38,7 +38,7 @@ def test_make_calculator(cps_subsample): with pytest.raises(ValueError): Calculator(policy=pol, records=None) with pytest.raises(ValueError): - Calculator(policy=pol, records=rec, consumption=list()) + Calculator(policy=pol, records=rec, consumption=[]) def test_make_calculator_deepcopy(cps_subsample): @@ -522,7 +522,7 @@ def test_read_bad_json_assump_file(): with pytest.raises(ValueError): Calculator.read_json_param_objects(None, 'unknown_file_name') with pytest.raises(TypeError): - Calculator.read_json_param_objects(None, list()) + Calculator.read_json_param_objects(None, []) def test_json_doesnt_exist(): diff --git a/taxcalc/tests/test_compatible_data.py b/taxcalc/tests/test_compatible_data.py index e666f8486..bb4f3098e 100644 --- a/taxcalc/tests/test_compatible_data.py +++ b/taxcalc/tests/test_compatible_data.py @@ -49,7 +49,7 @@ def valid_compatible_data(compatible_data): return True # Main logic of test_compatible_data_presence function - problem_pnames = list() + problem_pnames = [] for pname in allparams: if 'compatible_data' in allparams[pname]: compatible_data = allparams[pname]['compatible_data'] diff --git a/taxcalc/tests/test_consumption.py b/taxcalc/tests/test_consumption.py index 21c01502b..599e99b81 100644 --- a/taxcalc/tests/test_consumption.py +++ b/taxcalc/tests/test_consumption.py @@ -113,7 +113,7 @@ def test_consumption_response(cps_subsample): consump.update_consumption(consumption_response) # test incorrect call to response method with pytest.raises(ValueError): - consump.response(list(), 1) + consump.response([], 1) # test correct call to response method rec = Records.cps_constructor(data=cps_subsample) pre = copy.deepcopy(rec.e20400) diff --git a/taxcalc/tests/test_data.py b/taxcalc/tests/test_data.py index 51db63c02..7140040e1 100644 --- a/taxcalc/tests/test_data.py +++ b/taxcalc/tests/test_data.py @@ -79,10 +79,10 @@ def _extrapolate(self, year): # test Recs class for incorrect instantiation with pytest.raises(ValueError): - Recs(data=list(), start_year=2000, + Recs(data=[], start_year=2000, gfactors=None, weights=None) with pytest.raises(ValueError): - Recs(data=cps_subsample, start_year=list(), + Recs(data=cps_subsample, start_year=[], gfactors=None, weights=None) with pytest.raises(ValueError): Recs(data=cps_subsample, start_year=2000, @@ -130,4 +130,4 @@ def _extrapolate(self, year): rec._read_data(data=None) rec._read_weights(weights=None) with pytest.raises(ValueError): - rec._read_weights(weights=list()) + rec._read_weights(weights=[]) diff --git a/taxcalc/tests/test_parameters.py b/taxcalc/tests/test_parameters.py index 4440c5fa9..1fe09e765 100644 --- a/taxcalc/tests/test_parameters.py +++ b/taxcalc/tests/test_parameters.py @@ -157,8 +157,8 @@ def update_params(self, revision, assert prms.start_year == 2001 assert prms.current_year == 2001 assert prms.end_year == 2010 - assert prms.inflation_rates() == list() - assert prms.wage_growth_rates() == list() + assert prms.inflation_rates() == [] + assert prms.wage_growth_rates() == [] prms.set_year(2010) assert prms.current_year == 2010 with pytest.raises(paramtools.ValidationError): @@ -594,7 +594,7 @@ def test_read_json_revision(good_revision): # pllint: disable=private-method with pytest.raises(TypeError): # error because first obj argument is neither None nor a string - Parameters._read_json_revision(list(), '') + Parameters._read_json_revision([], '') with pytest.raises(ValueError): # error because second topkey argument must be a string Parameters._read_json_revision(good_revision, 999) diff --git a/taxcalc/tests/test_puf_var_stats.py b/taxcalc/tests/test_puf_var_stats.py index e4fc7769b..c741dd867 100644 --- a/taxcalc/tests/test_puf_var_stats.py +++ b/taxcalc/tests/test_puf_var_stats.py @@ -85,7 +85,7 @@ def calculate_corr_stats(calc, table): errmsg = '' for varname1 in table.index: var1 = calc.array(varname1) - var1_cc = list() + var1_cc = [] for varname2 in table.index: var2 = calc.array(varname2) try: @@ -105,7 +105,7 @@ def calculate_mean_stats(calc, table, year): Calculate weighted means for year. """ total_weight = calc.total_weight() - means = list() + means = [] for varname in table.index: wmean = calc.weighted_total(varname) / total_weight means.append(wmean) diff --git a/taxcalc/tests/test_records.py b/taxcalc/tests/test_records.py index cb9f3f8d6..c7055d968 100644 --- a/taxcalc/tests/test_records.py +++ b/taxcalc/tests/test_records.py @@ -13,17 +13,17 @@ def test_incorrect_Records_instantiation(cps_subsample): with pytest.raises(ValueError): - recs = Records(data=list()) + recs = Records(data=[]) with pytest.raises(ValueError): - recs = Records(data=cps_subsample, gfactors=list()) + recs = Records(data=cps_subsample, gfactors=[]) with pytest.raises(ValueError): - recs = Records(data=cps_subsample, gfactors=None, weights=list()) + recs = Records(data=cps_subsample, gfactors=None, weights=[]) with pytest.raises(ValueError): recs = Records(data=cps_subsample, gfactors=None, weights=None, - start_year=list()) + start_year=[]) with pytest.raises(ValueError): recs = Records(data=cps_subsample, gfactors=None, weights=None, - adjust_ratios=list()) + adjust_ratios=[]) def test_correct_Records_instantiation(cps_subsample): diff --git a/taxcalc/tests/test_reforms.py b/taxcalc/tests/test_reforms.py index 1447e9f98..40a65c9ff 100644 --- a/taxcalc/tests/test_reforms.py +++ b/taxcalc/tests/test_reforms.py @@ -217,7 +217,7 @@ def res_and_out_are_same(base): weights=None, adjust_ratios=None) # specify list of reform failures - failures = list() + failures = [] # specify current-law-policy Calculator object calc = Calculator(policy=Policy(), records=cases, verbose=False) calc.advance_to_year(tax_year) @@ -296,7 +296,7 @@ def reform_results(rid, reform_dict, puf_data, reform_2017_law): # calculate baseline and reform output for several years output_type = reform_dict['output_type'] num_years = 4 - results = list() + results = [] for _ in range(0, num_years): calc1.calc_all() baseline = calc1.array(output_type) diff --git a/taxcalc/tests/test_taxcalcio.py b/taxcalc/tests/test_taxcalcio.py index b81a985e2..0be17b6ea 100644 --- a/taxcalc/tests/test_taxcalcio.py +++ b/taxcalc/tests/test_taxcalcio.py @@ -238,7 +238,7 @@ def fixture_assumpfile2(): ('no-dot-csv-filename', 'no-dot-json-filename', 'no-dot-json-filename', 'no-dot-json-filename', 'no-output-directory'), - (list(), list(), list(), list(), list()), + ([], [], [], [], []), ('no-exist.csv', 'no-exist.json', 'no-exist.json', 'no-exist.json', '.'), ]) def test_ctor_errors(input_data, baseline, reform, assump, outdir): diff --git a/taxcalc/tests/test_utils.py b/taxcalc/tests/test_utils.py index 7bbfe8756..0604c2183 100644 --- a/taxcalc/tests/test_utils.py +++ b/taxcalc/tests/test_utils.py @@ -607,7 +607,7 @@ def test_mtr_graph_data(cps_subsample): income_measure='expanded_income', dollar_weighting=True) with pytest.raises(ValueError): - mtr_graph_data(None, year, mars=list()) + mtr_graph_data(None, year, mars=[]) with pytest.raises(ValueError): mtr_graph_data(None, year, mars='ALL', mtr_variable='e00200s') with pytest.raises(ValueError): @@ -636,7 +636,7 @@ def test_atr_graph_data(cps_subsample): with pytest.raises(ValueError): atr_graph_data(None, year, mars=0) with pytest.raises(ValueError): - atr_graph_data(None, year, mars=list()) + atr_graph_data(None, year, mars=[]) with pytest.raises(ValueError): atr_graph_data(None, year, atr_measure='badtax') calc.calc_all() diff --git a/taxcalc/utils.py b/taxcalc/utils.py index 5ef06b5f9..d51e5574f 100644 --- a/taxcalc/utils.py +++ b/taxcalc/utils.py @@ -761,7 +761,7 @@ def diagnostic_table_odict(vdf): assert isinstance(year_list[0], int) assert isinstance(dframe_list[0], pd.DataFrame) # construct diagnostic table - tlist = list() + tlist = [] for year, vardf in zip(year_list, dframe_list): odict = diagnostic_table_odict(vardf) ddf = pd.DataFrame(data=odict, index=[year], columns=odict.keys()) @@ -1495,8 +1495,8 @@ def ce_aftertax_expanded_income(df1, df2, ati2 = df2['expanded_income'] - df2['combined'] # calculate certainty-equivaluent after-tax income in df1 and df2 cedict['crra'] = crras - ce1 = list() - ce2 = list() + ce1 = [] + ce2 = [] for crra in crras: eu1 = expected_utility(ati1, prob, crra, cmin) ce1.append(certainty_equivalent(eu1, crra, cmin))