Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate pylint warnings #2859

Merged
merged 48 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
182e819
Streamline Makefile cstest target logic
martinholmer Jan 2, 2025
961c03c
Fix pylint W1514 warnings
martinholmer Jan 2, 2025
9edaf81
Fix pylint R1735 warnings
martinholmer Jan 2, 2025
abfaeca
Fix pylint R1734 warnings
martinholmer Jan 2, 2025
3542cc6
Fix pylint R1732 warnings
martinholmer Jan 2, 2025
6cacfa9
Fix pylint C0200 warnings
martinholmer Jan 3, 2025
a40a692
Fix pylint R1724 warnings
martinholmer Jan 3, 2025
9b5b760
Fix pylint R1720 warnings
martinholmer Jan 3, 2025
e0888c9
Fix pylint R1721 warnings
martinholmer Jan 3, 2025
3cb2bbe
Fix pylint E0401 warnings
martinholmer Jan 3, 2025
f304797
Fix pylint R1716 warnings
martinholmer Jan 3, 2025
2962382
Fix pylint R1714 warnings
martinholmer Jan 3, 2025
aabb7e3
Fix pylint R1710 and R1711 warnings
martinholmer Jan 3, 2025
36c86ff
Fix pylint R1703 and R1705 warnings
martinholmer Jan 3, 2025
2253d9b
Fix pylint R1736 warnings
martinholmer Jan 3, 2025
84c2439
Fix pylint R0913 and R0917 warnings
martinholmer Jan 3, 2025
c613d76
Fix pylint R0915 warnings
martinholmer Jan 3, 2025
e912937
Fix pylint R0914 warnings
martinholmer Jan 3, 2025
37b487b
Fix pylint R0902 and R0903 and R0912 warnings
martinholmer Jan 3, 2025
6182d42
Fix pylint R0401 and R0402 warnings
martinholmer Jan 4, 2025
08a20f3
Fix pylint R0022 and R0205 warnings
martinholmer Jan 4, 2025
2bfee11
Fix pylint R0133 warnings
martinholmer Jan 4, 2025
cf704ef
Fix pylint warnings in docs/guide/make/*py files
martinholmer Jan 4, 2025
9fb604c
Exclude docs/guide directory tree from cstest in Makefile
martinholmer Jan 4, 2025
dfb578c
Fix pylint C0103 warnings
martinholmer Jan 4, 2025
068bc14
Fix pylint C0114 warnings
martinholmer Jan 4, 2025
7352558
Fix pylint C0115 and C0116 warnings
martinholmer Jan 4, 2025
9c77b54
Fix pylint C0121 and C0206 warnings
martinholmer Jan 4, 2025
578eb6d
Fix pylint C0209 warnings
martinholmer Jan 5, 2025
3b60df7
Fix pylint C0325 and C0411 warnings
martinholmer Jan 5, 2025
9e2d3b9
Fix pylint C1802 and C2801 warnings
martinholmer Jan 5, 2025
58767c6
Add test of json_to_dict utility function
martinholmer Jan 5, 2025
b0f842b
Fix pylint E0602 warnings
martinholmer Jan 5, 2025
fe46574
Fix pylint E0606 warnings
martinholmer Jan 5, 2025
94855e6
Fix pylint E1101 warnings
martinholmer Jan 5, 2025
1400752
Fix typo in test_records.py
martinholmer Jan 5, 2025
f8694d5
Fix pylint E1111 and E1120 warnings; update bokeh required version
martinholmer Jan 5, 2025
5144152
Fix pylint E1121 and W0107 warnings; fix typo in prior commit
martinholmer Jan 5, 2025
ea8b9f7
Revert minimum required bokeh version to 2.4
martinholmer Jan 5, 2025
1d2df59
Fix pylint W0201 and W0212 warnings
martinholmer Jan 5, 2025
9a58081
Fix pylint W0221 and W0223 warnings
martinholmer Jan 5, 2025
7141d17
Fix pylint W0237 and W0401 warnings
martinholmer Jan 5, 2025
2f072e4
Fix pylint W0611 and W0612 warnings
martinholmer Jan 6, 2025
8131bf5
Fix pylint W0613 warnings
martinholmer Jan 6, 2025
161a41a
Fix pylint W0621 and W07073 warnings
martinholmer Jan 6, 2025
cc6f9fe
Fix pylint W1114 and W1406 warnings
martinholmer Jan 6, 2025
f286398
Fix pylint W1514 and W3301 warnings
martinholmer Jan 6, 2025
3223cdd
Fix a few pylint warnings
martinholmer Jan 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading