Skip to content

Commit

Permalink
Merge pull request #2859 from martinholmer/pylint-fixes
Browse files Browse the repository at this point in the history
Eliminate pylint warnings
  • Loading branch information
martinholmer authored Jan 6, 2025
2 parents 17bd940 + 3223cdd commit 02d84f7
Show file tree
Hide file tree
Showing 42 changed files with 1,019 additions and 802 deletions.
13 changes: 5 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,17 @@ tctest-jit:
TOPLEVEL_JSON_FILES := $(shell ls -l ./*json | awk '{print $$9}')
TAXCALC_JSON_FILES := $(shell ls -l ./taxcalc/*json | awk '{print $$9}')
TESTS_JSON_FILES := $(shell ls -l ./taxcalc/tests/*json | awk '{print $$9}')
PYLINT_FILES := $(shell grep -rl --include="*py" disable=locally-disabled .)
PYLINT_OPTIONS = --disable=locally-disabled --score=no --jobs=4 --disable=R0801
RECIPE_FILES := $(shell ls -l ./docs/recipes/recipe*.ipynb | awk '{print $$9}')
RECIPE_IGNORE = C0103,C0111,E0401,E1120,R0913,R0914,W0401,W0614,R0801
RECIPE_OPTIONS = --disable=$(RECIPE_IGNORE) --score=no --jobs=4
PYLINT_DISABLE = locally-disabled,duplicate-code,cyclic-import
PYLINT_OPTIONS = --disable=$(PYLINT_DISABLE) --score=no --jobs=4
EXCLUDED_PATHS = taxcalc/validation,docs/guide

.PHONY=cstest
cstest:
-pycodestyle . | grep -v taxcalc/validation
@-pycodestyle --ignore=W503,W504,E712 --exclude=$(EXCLUDED_PATHS) .
@-pycodestyle --ignore=E501,E121 $(TOPLEVEL_JSON_FILES)
@-pycodestyle --ignore=E501,E121 $(TAXCALC_JSON_FILES)
@-pycodestyle --ignore=E501,E121 $(TESTS_JSON_FILES)
@-pylint $(PYLINT_OPTIONS) $(PYLINT_FILES)
@-pylint $(RECIPE_OPTIONS) $(RECIPE_FILES)
@-pylint $(PYLINT_OPTIONS) --ignore-paths=$(EXCLUDED_PATHS) .

define coverage-cleanup
rm -f .coverage htmlcov/*
Expand Down
6 changes: 4 additions & 2 deletions extend_tcja.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,15 @@ def main():
"""
High-level script logic.
"""
# pylint: disable=too-many-statements

# identify last parameter name in TCJA_PARAMETERS
last_pname = list(TCJA_PARAMETERS.keys())[-1]
# calculate 2025-to-2026 parameters indexing factor
pol = taxcalc.Policy()
pirates = pol.inflation_rates()
ifactor25 = 1.0 + pirates[2025-taxcalc.Policy.JSON_START_YEAR]
ifactor28 = 1.0 + pirates[2028-taxcalc.Policy.JSON_START_YEAR]
ifactor25 = 1.0 + pirates[2025 - taxcalc.Policy.JSON_START_YEAR]
ifactor28 = 1.0 + pirates[2028 - taxcalc.Policy.JSON_START_YEAR]
# specify extend-TCJA-beyond-2025 reform
# ... get 2025 parameter values
year = 2025
Expand Down
1 change: 1 addition & 0 deletions ppp.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def integrate_fragments(fragments):
"""
Integrate specified fragments with the policy_current_law.json text.
"""
# pylint: disable=too-many-locals
p_c_l_path = Path('.') / 'taxcalc' / 'policy_current_law.json'
with open(p_c_l_path, 'r', encoding='utf-8') as ofile:
olines = ofile.readlines()
Expand Down
13 changes: 8 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
"""
Tax-Calculator setup.
"""

from setuptools import setup

with open("README.md") as f:
with open("README.md", "r", encoding="utf-8") as f:
longdesc = f.read()

version = "4.4.0"
VERSION = "4.4.0"

config = {
"description": "Tax Calculator",
"description": "Tax-Calculator",
"url": "https://github.com/PSLmodels/Tax-Calculator",
"download_url": "https://github.com/PSLmodels/Tax-Calculator",
"description": "taxcalc",
"long_description_content_type": "text/markdown",
"long_description": longdesc,
"version": version,
"version": VERSION,
"license": "CC0 1.0 Universal (CC0 1.0) Public Domain Dedication",
"packages": ["taxcalc", "taxcalc.cli"],
"include_package_data": True,
Expand Down
2 changes: 1 addition & 1 deletion taxcalc.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Metadata-Version: 2.1
Name: taxcalc
Version: 4.4.0
Summary: taxcalc
Summary: Tax-Calculator
Home-page: https://github.com/PSLmodels/Tax-Calculator
Download-URL: https://github.com/PSLmodels/Tax-Calculator
License: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
Expand Down
10 changes: 5 additions & 5 deletions taxcalc/calcfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# pylint: disable=too-many-lines
# pylint: disable=invalid-name
# pylint: disable=too-many-arguments
# pylint: disable=too-many-positional-arguments
# pylint: disable=too-many-locals

import math
Expand Down Expand Up @@ -2309,7 +2310,7 @@ def F2441(MARS, earned_p, earned_s, f2441, CDCC_c, e32800,
c32890 = earned_s # earned income of spouse when present
else:
c32890 = earned_p
c33000 = max(0., min(c32800, min(c32880, c32890)))
c33000 = max(0., min(c32800, c32880, c32890))
# credit rate is limited at high AGI
# ... first phase-down from CDCC_crt to CDCC_frt
steps_fractional = max(0., c00100 - CDCC_ps) / CDCC_po_step_size
Expand Down Expand Up @@ -2758,8 +2759,8 @@ def PersonalTaxCredit(MARS, c00100, XTOT, nu18,
# calculate Recovery Rebate Credit from CARES Act 2020 and/or ARPA 2021
if c00100 < RRC_ps[MARS - 1]:
recovery_rebate_credit = RRC_c * XTOT
recovery_rebate_credit += RRC_c_unit[MARS-1] + RRC_c_kids * nu18
elif c00100 < RRC_pe[MARS - 1] and c00100 > 0:
recovery_rebate_credit += RRC_c_unit[MARS - 1] + RRC_c_kids * nu18
elif 0 < c00100 < RRC_pe[MARS - 1]:
prt = (
(c00100 - RRC_ps[MARS - 1]) /
(RRC_pe[MARS - 1] - RRC_ps[MARS - 1])
Expand Down Expand Up @@ -3445,8 +3446,7 @@ def CTC_new(CTC_new_c, CTC_new_rt, CTC_new_c_under6_bonus,
ctc_new = min(ctc_new, ctc_new_reduced)
if ctc_new > 0. and CTC_new_refund_limited:
refund_new = max(0., ctc_new - c09200)
if not CTC_new_refund_limited_all_payroll:
limit_new = CTC_new_refund_limit_payroll_rt * ptax_oasdi
limit_new = CTC_new_refund_limit_payroll_rt * ptax_oasdi
if CTC_new_refund_limited_all_payroll:
limit_new = CTC_new_refund_limit_payroll_rt * payrolltax
limited_new = max(0., refund_new - limit_new)
Expand Down
67 changes: 34 additions & 33 deletions taxcalc/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ class instance: Calculator

def __init__(self, policy=None, records=None, verbose=False,
sync_years=True, consumption=None):
# pylint: disable=too-many-arguments,too-many-branches
# pylint: disable=too-many-arguments,too-many-positional-arguments
# pylint: disable=too-many-branches
if isinstance(policy, Policy):
self.__policy = copy.deepcopy(policy)
else:
Expand Down Expand Up @@ -286,8 +287,7 @@ def policy_param(self, param_name, param_value=None):
val = getattr(self.__policy, param_name)
if param_name.startswith("_"):
return val
else:
return val[0] # drop down a dimension.
return val[0] # drop down a dimension.
setattr(self.__policy, param_name, param_value)
return None

Expand Down 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 @@ -626,8 +626,8 @@ def mtr(self, variable_str='e00200p',
'e20100', Charity non-cash contributions;
'k1bx14p', Partnership income (also included in e26270 and e02000).
"""
# pylint: disable=too-many-arguments,too-many-statements
# pylint: disable=too-many-locals,too-many-branches
# pylint: disable=too-many-arguments,too-many-positional-arguments
# pylint: disable=too-many-locals,too-many-branches,too-many-statements
assert not zero_out_calculated_vars or not calc_all_already_called
# check validity of variable_str parameter
if variable_str not in Calculator.MTR_VALID_VARIABLES:
Expand Down Expand Up @@ -824,7 +824,9 @@ def mtr_graph(self, calc,
-------
graph that is a bokeh.plotting figure object
"""
# pylint: disable=too-many-arguments,too-many-locals
# pylint: disable=too-many-arguments,too-many-positional-arguments
# pylint: disable=too-many-locals

# check that two Calculator objects are comparable
assert isinstance(calc, Calculator)
assert calc.current_year == self.current_year
Expand All @@ -833,9 +835,8 @@ def mtr_graph(self, calc,
assert mars == 'ALL' or 1 <= mars <= 4
# check validity of income_measure
assert income_measure in ('expanded_income', 'agi', 'wages')
if income_measure == 'expanded_income':
income_variable = 'expanded_income'
elif income_measure == 'agi':
income_variable = 'expanded_income'
if income_measure == 'agi':
income_variable = 'c00100'
elif income_measure == 'wages':
income_variable = 'e00200'
Expand All @@ -848,15 +849,15 @@ def mtr_graph(self, calc,
(mtr2_ptax, mtr2_itax,
mtr2_combined) = calc.mtr(variable_str=mtr_variable,
wrt_full_compensation=mtr_wrt_full_compen)
if mtr_measure == 'combined':
mtr1 = mtr1_combined
mtr2 = mtr2_combined
elif mtr_measure == 'itax':
if mtr_measure == 'itax':
mtr1 = mtr1_itax
mtr2 = mtr2_itax
elif mtr_measure == 'ptax':
mtr1 = mtr1_ptax
mtr2 = mtr2_ptax
else:
mtr1 = mtr1_combined
mtr2 = mtr2_combined
# extract datafames needed by mtr_graph_data utility function
record_variables = ['s006', 'XTOT']
if mars != 'ALL':
Expand Down Expand Up @@ -1042,17 +1043,15 @@ def pch_graph(self, calc, pop_quantiles=False):
# construct data for graph
data = pch_graph_data(vdf, year=self.current_year,
pop_quantiles=pop_quantiles)
del vdf
del vdf1
del vdf2
# construct figure from data
fig = pch_graph_plot(data,
width=850,
height=500,
xlabel='',
ylabel='',
title='')
del data
# (see comment at end of pch_graph_plot function in utils.py)
fig = pch_graph_plot( # pylint: disable=assignment-from-no-return
data,
width=850,
height=500,
xlabel='',
ylabel='',
title='')
return fig

REQUIRED_REFORM_KEYS = set(['policy'])
Expand Down Expand Up @@ -1101,7 +1100,7 @@ def read_json_param_objects(reform, assump):
suitable as input into the GrowDiff.update_growdiff method.
"""
# construct the composite dictionary
param_dict = dict()
param_dict = {}
param_dict['policy'] = Policy.read_json_reform(reform)
param_dict['consumption'] = Consumption.read_json_update(assump)
for topkey in ['growdiff_baseline', 'growdiff_response']:
Expand Down Expand Up @@ -1165,7 +1164,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 +1188,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 All @@ -1202,7 +1201,7 @@ def lines(text, num_indent_spaces, max_line_length=77):
if params_with_diff:
mdata_base = baseline.specification(meta_data=True)
# write year
doc += '{}:\n'.format(year)
doc += f'{year}:\n'
for pname in sorted(params_with_diff):
# write updated value line
pval = getattr(updated, pname).tolist()[0]
Expand All @@ -1211,7 +1210,7 @@ def lines(text, num_indent_spaces, max_line_length=77):
pval = [bool(item) for item in pval]
else:
pval = bool(pval)
doc += ' {} : {}\n'.format(pname, pval)
doc += f' {pname} : {pval}\n'
# ... write optional param-vector-index line
if isinstance(pval, list):
labels = paramtools.consistent_labels(
Expand All @@ -1223,13 +1222,15 @@ def lines(text, num_indent_spaces, max_line_length=77):
label = _label
break
if label:
# pylint: disable=protected-access
lv = baseline._stateless_label_grid[label]
# pylint: enable=protected-access
lv = [
str(item) for item in lv
]
doc += ' ' * (
4 + len(pname)
) + '{}\n'.format(lv)
) + f'{lv}\n'
# ... write param-name line
name = mdata_base[pname]['title']
for line in lines('name: ' + name, 6):
Expand All @@ -1247,7 +1248,7 @@ def lines(text, num_indent_spaces, max_line_length=77):
pval = [bool(item) for item in pval]
elif ptype == 'bool':
pval = bool(pval)
doc += ' baseline_value: {}\n'.format(pval)
doc += f' baseline_value: {pval}\n'
else: # if baseline is GrowDiff object
# each GrowDiff parameter has zero as default value
doc += ' baseline_value: 0.0\n'
Expand Down Expand Up @@ -1399,7 +1400,7 @@ def _calc_one_year(self, zero_out_calc_vars=False):
item_phaseout = self.array('c21040').copy()
item_component_variable_names = ['c17000', 'c18300', 'c19200',
'c19700', 'c20500', 'c20800']
item_cvar = dict()
item_cvar = {}
for cvname in item_component_variable_names:
item_cvar[cvname] = self.array(cvname).copy()
self.zeroarray('c04470')
Expand Down
13 changes: 6 additions & 7 deletions taxcalc/cli/tc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def cli_tc_main():
Contains command-line interface (CLI) to Tax-Calculator TaxCalcIO class.
"""
# pylint: disable=too-many-statements,too-many-branches
# pylint: disable=too-many-return-statements
# pylint: disable=too-many-return-statements,too-many-locals

# parse command-line arguments:
usage_str = 'tc INPUT TAXYEAR {}{}{}{}{}'.format(
'[--help]\n',
Expand Down Expand Up @@ -254,12 +255,10 @@ def _compare_test_output_files():
Private function that compares expected and actual tc --test output files;
returns 0 if pass test, otherwise returns 1.
"""
explines = open(
EXPECTED_TEST_OUTPUT_FILENAME, 'r', encoding='utf-8'
).readlines()
actlines = open(
ACTUAL_TEST_OUTPUT_FILENAME, 'r', encoding='utf-8'
).readlines()
with open(EXPECTED_TEST_OUTPUT_FILENAME, 'r', encoding='utf-8') as efile:
explines = efile.readlines()
with open(ACTUAL_TEST_OUTPUT_FILENAME, 'r', encoding='utf-8') as afile:
actlines = afile.readlines()
if ''.join(explines) == ''.join(actlines):
sys.stdout.write('PASSED TEST\n')
retcode = 0
Expand Down
13 changes: 9 additions & 4 deletions taxcalc/consumption.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ def has_response(self):
parameters are one
"""
for var in Consumption.RESPONSE_VARS:
if getattr(self, 'MPC_{}'.format(var)) > 0.0:
if getattr(self, f'MPC_{var}') > 0.0:
return True
for var in Consumption.BENEFIT_VARS:
if getattr(self, 'BEN_{}_value'.format(var)) < 1.0:
if getattr(self, f'BEN_{var}_value') < 1.0:
return True
return False

Expand All @@ -84,12 +84,17 @@ def response(self, records, income_change):
raise ValueError('records is not a Records object')
for var in Consumption.RESPONSE_VARS:
records_var = getattr(records, var)
mpc_var = getattr(self, 'MPC_{}'.format(var))
mpc_var = getattr(self, f'MPC_{var}')
records_var[:] += mpc_var * income_change

def benval_params(self):
"""
Returns list of BEN_*_value parameter values
"""
return [getattr(self, 'BEN_{}_value'.format(var))
return [getattr(self, f'BEN_{var}_value')
for var in Consumption.BENEFIT_VARS]

def set_rates(self):
"""
Consumption class has no parameter indexing rates.
"""
Loading

0 comments on commit 02d84f7

Please sign in to comment.