Skip to content

Commit 0e5ca9f

Browse files
authored
Fix more pylint warnings (#143)
Fix a spurious divide-by-zero error in sedov_compare.py and gauss_diffusion_compare.py that pylint found. Most of the other fixes are for `unused-variable`, plus some instances of `consider-using-enumerate`, `consider-using-dict-items`, `consider-iterating-dictionary`, `use-dict-literal`, `useless-object-inheritance`, and `unneeded-not`. Also disable `pointless-string-statement`, since these are used for block comments in a couple places.
1 parent bf48f28 commit 0e5ca9f

24 files changed

+34
-33
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ disable = [
2020
"missing-class-docstring",
2121
"missing-function-docstring",
2222
"missing-module-docstring",
23+
"pointless-string-statement",
2324
]
2425
enable = [
2526
"useless-suppression",

pyro/advection/simulation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def dovis(self):
106106

107107
myg = self.cc_data.grid
108108

109-
_, axes, cbar_title = plot_tools.setup_axes(myg, 1)
109+
_, axes, _ = plot_tools.setup_axes(myg, 1)
110110

111111
# plot density
112112
ax = axes[0]

pyro/advection_nonuniform/simulation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def dovis(self):
131131

132132
myg = self.cc_data.grid
133133

134-
_, axes, cbar_title = plot_tools.setup_axes(myg, 1)
134+
_, axes, _ = plot_tools.setup_axes(myg, 1)
135135

136136
# plot density
137137
ax = axes[0]

pyro/analysis/convergence.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def compare(fine, coarse):
2727

2828
if __name__ == "__main__":
2929

30-
if not len(sys.argv) == 3:
30+
if len(sys.argv) != 3:
3131
print(usage)
3232
sys.exit(2)
3333

pyro/analysis/dam_compare.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def abort(string):
2424
sys.exit(2)
2525

2626

27-
if not len(sys.argv) == 2:
27+
if len(sys.argv) != 2:
2828
print(usage)
2929
sys.exit(2)
3030

pyro/analysis/gauss_diffusion_compare.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def process(file):
8888
# now bin the associated data
8989
phi_bin = np.zeros(len(ncount)-1, dtype=np.float64)
9090

91-
for n in range(len(ncount)):
91+
for n in range(1, len(ncount)):
9292

9393
# remember that there are no whichbin == 0, since that
9494
# corresponds to the left edge. So we want whichbin == 1 to
@@ -106,7 +106,7 @@ def process(file):
106106

107107
if __name__ == "__main__":
108108

109-
if not len(sys.argv) >= 2:
109+
if len(sys.argv) < 2:
110110
print(usage)
111111
sys.exit(2)
112112

pyro/analysis/incomp_converge_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"""
1717

1818

19-
if not len(sys.argv) == 2:
19+
if len(sys.argv) != 2:
2020
print(usage)
2121
sys.exit(2)
2222

pyro/analysis/sedov_compare.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
u_bin = np.zeros(len(ncount)-1, dtype=np.float64)
101101
p_bin = np.zeros(len(ncount)-1, dtype=np.float64)
102102

103-
for n in range(len(ncount)):
103+
for n in range(1, len(ncount)):
104104

105105
# remember that there are no whichbin == 0, since that corresponds
106106
# to the left edge. So we want whichbin == 1 to correspond to the

pyro/analysis/smooth_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
usage: ./smooth_error.py file
1717
"""
1818

19-
if not len(sys.argv) == 2:
19+
if len(sys.argv) != 2:
2020
print(usage)
2121
sys.exit(2)
2222

pyro/analysis/sod_compare.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def abort(string):
2121
sys.exit(2)
2222

2323

24-
if not len(sys.argv) == 2:
24+
if len(sys.argv) != 2:
2525
print(usage)
2626
sys.exit(2)
2727

pyro/compressible_react/simulation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def dovis(self):
9292
fields = [rho, magvel, p, e, X]
9393
field_names = [r"$\rho$", r"U", "p", "e", r"$X_\mathrm{fuel}$"]
9494

95-
f, axes, cbar_title = plot_tools.setup_axes(myg, len(fields))
95+
_, axes, cbar_title = plot_tools.setup_axes(myg, len(fields))
9696

9797
for n, ax in enumerate(axes):
9898
v = fields[n]

pyro/compressible_sr/c2p.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def brentq(x1, b, U, gamma, idens, ixmom, iymom, iener,
5858

5959
mflag = True
6060

61-
for i in range(ITMAX):
61+
for _ in range(ITMAX):
6262
if fa != fc and fb != fc:
6363
s = a*fb*fc / ((fa-fb) * (fa-fc)) + b*fa*fc / ((fb-fa)*(fb-fc)) + \
6464
c*fa*fb / ((fc-fa)*(fc-fb))

pyro/incompressible/incomp_interface.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def mac_vels(ng, dx, dy, dt,
3636

3737
# get the full u and v left and right states (including transverse
3838
# terms) on both the x- and y-interfaces
39+
# pylint: disable-next=unused-variable
3940
u_xl, u_xr, u_yl, u_yr, v_xl, v_xr, v_yl, v_yr = get_interface_states(ng, dx, dy, dt,
4041
u, v,
4142
ldelta_ux, ldelta_vx,

pyro/incompressible/simulation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ def dovis(self):
422422
0.5*(u.ip(1) - u.ip(-1))/myg.dx + \
423423
0.5*(v.jp(1) - v.jp(-1))/myg.dy
424424

425-
fig, axes = plt.subplots(nrows=2, ncols=2, num=1)
425+
_, axes = plt.subplots(nrows=2, ncols=2, num=1)
426426
plt.subplots_adjust(hspace=0.25)
427427

428428
fields = [u, v, vort, divU]

pyro/lm_atm/LM_atm_interface.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ def mac_vels(ng, dx, dy, dt,
240240

241241
# get the full u and v left and right states (including transverse
242242
# terms) on both the x- and y-interfaces
243+
# pylint: disable-next=unused-variable
243244
u_xl, u_xr, u_yl, u_yr, v_xl, v_xr, v_yl, v_yr = get_interface_states(ng, dx, dy, dt,
244245
u, v,
245246
ldelta_ux, ldelta_vx,

pyro/lm_atm/simulation.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -640,17 +640,15 @@ def dovis(self):
640640

641641
vort.v()[:, :] = dv - du
642642

643-
fig, axes = plt.subplots(nrows=2, ncols=2, num=1)
643+
_, axes = plt.subplots(nrows=2, ncols=2, num=1)
644644
plt.subplots_adjust(hspace=0.25)
645645

646646
fields = [rho, magvel, vort, rhoprime]
647647
field_names = [r"$\rho$", r"|U|", r"$\nabla \times U$", r"$\rho'$"]
648648

649-
for n in range(len(fields)):
649+
for n, f in enumerate(fields):
650650
ax = axes.flat[n]
651651

652-
f = fields[n]
653-
654652
img = ax.imshow(np.transpose(f.v()),
655653
interpolation="nearest", origin="lower",
656654
extent=[myg.xmin, myg.xmax, myg.ymin, myg.ymax], cmap=self.cm)
@@ -676,8 +674,8 @@ def write_extras(self, f):
676674

677675
gb = f.create_group("base state")
678676

679-
for key in self.base:
680-
gb.create_dataset(key, data=self.base[key].d)
677+
for name, state in self.base.items():
678+
gb.create_dataset(name, data=state.d)
681679

682680
def read_extras(self, f):
683681
"""

pyro/multigrid/MG.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ def smooth(self, level, nsmooth):
568568
ycoeff = self.beta/myg.dy**2
569569

570570
# do red-black G-S
571-
for i in range(nsmooth):
571+
for _ in range(nsmooth):
572572

573573
# do the red black updating in four decoupled groups
574574
#

pyro/multigrid/general_MG.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def smooth(self, level, nsmooth):
140140
beta_y = self.beta_edge[level].y
141141

142142
# do red-black G-S
143-
for i in range(nsmooth):
143+
for _ in range(nsmooth):
144144

145145
# do the red black updating in four decoupled groups
146146
#

pyro/multigrid/variable_coeff_MG.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def smooth(self, level, nsmooth):
129129
# print( "min/max eta_y: {}, {}".format(np.min(eta_y), np.max(eta_y)))
130130

131131
# do red-black G-S
132-
for i in range(nsmooth):
132+
for _ in range(nsmooth):
133133

134134
# do the red black updating in four decoupled groups
135135
#

pyro/particles/particles.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def __init__(self, sim_data, bc, n_particles, particle_generator="grid",
123123

124124
self.sim_data = sim_data
125125
self.bc = bc
126-
self.particles = dict()
126+
self.particles = {}
127127

128128
if n_particles <= 0:
129129
msg.fail("ERROR: n_particles = %s <= 0" % (n_particles))
@@ -237,7 +237,7 @@ def update_particles(self, dt, u=None, v=None):
237237
elif v is None:
238238
v = self.sim_data.get_var("y-velocity")
239239

240-
for k, p in self.particles.items():
240+
for p in self.particles.values():
241241

242242
# save old position and predict location at dt/2
243243
initial_position = p.pos()
@@ -266,7 +266,7 @@ def enforce_particle_boundaries(self):
266266
boundaries.
267267
"""
268268
old_particles = self.particles.copy()
269-
self.particles = dict()
269+
self.particles = {}
270270

271271
myg = self.sim_data.grid
272272

pyro/simulation_null.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def bc_setup(rp):
8585
return bc, bc_xodd, bc_yodd
8686

8787

88-
class NullSimulation(object):
88+
class NullSimulation:
8989

9090
def __init__(self, solver_name, problem_name, rp, timers=None, data_class=patch.CellCenterData2d):
9191
"""

pyro/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def do_tests(out_file,
110110

111111
f.write(f"\n{failed} test(s) failed\n")
112112

113-
if not f == sys.stdout:
113+
if f != sys.stdout:
114114
f.close()
115115

116116
return failed

pyro/util/io_pyro.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ def read(filename):
6363
else:
6464
bc_solver = solver_name
6565
bcmod = importlib.import_module(f"pyro.{bc_solver}.BC")
66-
for name in custom_bcs:
67-
bnd.define_bc(name, bcmod.user, is_solid=custom_bcs[name])
66+
for name, is_solid in custom_bcs.items():
67+
bnd.define_bc(name, bcmod.user, is_solid=is_solid)
6868

6969
# read in the variable info -- start by getting the names
7070
gs = f["state"]

pyro/util/runparams.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def load_params(self, pfile, no_new=0):
145145
# if we have no_new = 1, then we only want to override existing
146146
# key/values
147147
if no_new:
148-
if key not in self.params.keys():
148+
if key not in self.params:
149149
msg.warning("warning, key: %s not defined" % (key))
150150
continue
151151

@@ -186,7 +186,7 @@ def command_line_params(self, cmd_strings):
186186
key, value = item.split("=")
187187

188188
# we only want to override existing keys/values
189-
if key not in self.params.keys():
189+
if key not in self.params:
190190
msg.warning("warning, key: %s not defined" % (key))
191191
continue
192192

@@ -199,15 +199,15 @@ def get_param(self, key):
199199
input key
200200
"""
201201

202-
if self.params == {}:
202+
if not self.params:
203203
msg.warning("WARNING: runtime parameters not yet initialized")
204204
self.load_params("_defaults")
205205

206206
# debugging
207207
if key not in self.used_params:
208208
self.used_params.append(key)
209209

210-
if key in self.params.keys():
210+
if key in self.params:
211211
return self.params[key]
212212
raise KeyError(f"ERROR: runtime parameter {key} not found")
213213

0 commit comments

Comments
 (0)