Skip to content

Commit 8b6bfd1

Browse files
committed
check for unused keywords
1 parent cfe21de commit 8b6bfd1

9 files changed

Lines changed: 31 additions & 20 deletions

File tree

control/frdata.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,11 @@ def __init__(self, *args, **kwargs):
150150
151151
"""
152152
# TODO: discrete-time FRD systems?
153-
smooth = kwargs.get('smooth', False)
153+
smooth = kwargs.pop('smooth', False)
154+
155+
# Make sure there were no extraneous keywords
156+
if kwargs:
157+
raise TypeError("unrecognized keywords: ", str(kwargs))
154158

155159
if len(args) == 2:
156160
if not isinstance(args[0], FRD) and isinstance(args[0], LTI):

control/freqplot.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,10 @@ def bode_plot(syslist, omega=None,
221221
# Get the current figure
222222

223223
if 'sisotool' in kwargs:
224-
fig = kwargs['fig']
224+
fig = kwargs.pop('fig')
225225
ax_mag = fig.axes[0]
226226
ax_phase = fig.axes[2]
227-
sisotool = kwargs['sisotool']
228-
del kwargs['fig']
229-
del kwargs['sisotool']
227+
sisotool = kwargs.pop('sisotool')
230228
else:
231229
fig = plt.gcf()
232230
ax_mag = None

control/iosys.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def __init__(self, inputs=None, outputs=None, states=None, params={},
148148
# timebase
149149
self.dt = kwargs.pop('dt', config.defaults['control.default_dt'])
150150

151-
# Make sure there were no extraneous keyworks
151+
# Make sure there were no extraneous keywords
152152
if kwargs:
153153
raise TypeError("unrecognized keywords: ", str(kwargs))
154154

@@ -790,9 +790,9 @@ def __init__(self, updfcn, outfcn=None, inputs=None, outputs=None,
790790
params=params, dt=dt, name=name
791791
)
792792

793-
# Make sure all input arguments got parsed
793+
# Make sure there were no extraneous keywords
794794
if kwargs:
795-
raise TypeError("unknown parameters %s" % kwargs)
795+
raise TypeError("unrecognized keywords: ", str(kwargs))
796796

797797
# Check to make sure arguments are consistent
798798
if updfcn is None:
@@ -2134,7 +2134,8 @@ def _parse_signal_parameter(value, name, kwargs, end=False):
21342134
value = kwargs.pop(name)
21352135

21362136
if end and kwargs:
2137-
raise TypeError("unknown parameters %s" % kwargs)
2137+
raise TypeError("unrecognized keywords: ", str(kwargs))
2138+
21382139
return value
21392140

21402141

control/optimal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def __init__(
154154
self.minimize_kwargs.update(kwargs.pop(
155155
'minimize_kwargs', config.defaults['optimal.minimize_kwargs']))
156156

157-
# Make sure all input arguments got parsed
157+
# Make sure there were no extraneous keywords
158158
if kwargs:
159159
raise TypeError("unrecognized keyword(s): ", str(kwargs))
160160

control/pzmap.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ def pzmap(sys, plot=None, grid=None, title='Pole Zero Map', **kwargs):
9191
import warnings
9292
warnings.warn("'Plot' keyword is deprecated in pzmap; use 'plot'",
9393
FutureWarning)
94-
plot = kwargs['Plot']
94+
plot = kwargs.pop('Plot')
95+
96+
# Make sure there were no extraneous keywords
97+
if kwargs:
98+
raise TypeError("unrecognized keywords: ", str(kwargs))
9599

96100
# Get parameter values
97101
plot = config._get_param('pzmap', 'plot', plot, True)

control/rlocus.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ def root_locus(sys, kvect=None, xlim=None, ylim=None,
168168
# Check for sisotool mode
169169
sisotool = False if 'sisotool' not in kwargs else True
170170

171+
# Make sure there were no extraneous keywords
172+
if not sisotool and kwargs:
173+
raise TypeError("unrecognized keywords: ", str(kwargs))
174+
171175
# Create the Plot
172176
if plot:
173177
if sisotool:

control/tests/interconnect_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,27 +188,27 @@ def test_interconnect_exceptions():
188188

189189
# Unrecognized arguments
190190
# LinearIOSystem
191-
with pytest.raises(TypeError, match="unknown parameter"):
191+
with pytest.raises(TypeError, match="unrecognized keyword"):
192192
P = ct.LinearIOSystem(ct.rss(2, 1, 1), output_name='y')
193193

194194
# Interconnect
195-
with pytest.raises(TypeError, match="unknown parameter"):
195+
with pytest.raises(TypeError, match="unrecognized keyword"):
196196
T = ct.interconnect((P, C, sumblk), input_name='r', output='y')
197197

198198
# Interconnected system
199-
with pytest.raises(TypeError, match="unknown parameter"):
199+
with pytest.raises(TypeError, match="unrecognized keyword"):
200200
T = ct.InterconnectedSystem((P, C, sumblk), input_name='r', output='y')
201201

202202
# NonlinearIOSytem
203-
with pytest.raises(TypeError, match="unknown parameter"):
203+
with pytest.raises(TypeError, match="unrecognized keyword"):
204204
nlios = ct.NonlinearIOSystem(
205205
None, lambda t, x, u, params: u*u, input_count=1, output_count=1)
206206

207207
# Summing junction
208208
with pytest.raises(TypeError, match="input specification is required"):
209209
sumblk = ct.summing_junction()
210210

211-
with pytest.raises(TypeError, match="unknown parameter"):
211+
with pytest.raises(TypeError, match="unrecognized keyword"):
212212
sumblk = ct.summing_junction(input_count=2, output_count=2)
213213

214214

control/tests/trdata_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def test_response_copy():
208208
assert response.input_labels == ['u']
209209

210210
# Unknown keyword
211-
with pytest.raises(ValueError, match="Unknown parameter(s)*"):
211+
with pytest.raises(TypeError, match="unrecognized keywords"):
212212
response_bad_kw = response_mimo(input=0)
213213

214214

control/timeresp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,9 @@ def __call__(self, **kwargs):
480480
response.state_labels = _process_labels(
481481
state_labels, "state", response.nstates)
482482

483-
# Make sure no unknown keywords were passed
484-
if len(kwargs) != 0:
485-
raise ValueError("Unknown parameter(s) %s" % kwargs)
483+
# Make sure there were no extraneous keywords
484+
if kwargs:
485+
raise TypeError("unrecognized keywords: ", str(kwargs))
486486

487487
return response
488488

0 commit comments

Comments
 (0)