Skip to content

Commit

Permalink
Fix pylint R1734 warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholmer committed Jan 2, 2025
1 parent 9edaf81 commit abfaeca
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 38 deletions.
8 changes: 4 additions & 4 deletions taxcalc/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion taxcalc/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
10 changes: 5 additions & 5 deletions taxcalc/tests/test_benefits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
6 changes: 3 additions & 3 deletions taxcalc/tests/test_calcfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions taxcalc/tests/test_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion taxcalc/tests/test_compatible_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
2 changes: 1 addition & 1 deletion taxcalc/tests/test_consumption.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions taxcalc/tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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=[])
6 changes: 3 additions & 3 deletions taxcalc/tests/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions taxcalc/tests/test_puf_var_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions taxcalc/tests/test_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions taxcalc/tests/test_reforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion taxcalc/tests/test_taxcalcio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions taxcalc/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions taxcalc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit abfaeca

Please sign in to comment.