Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eb401a9

Browse files
committed
fix up deprecation warnings in response to @bnavigator review
1 parent f633874 commit eb401a9

File tree

3 files changed

+35
-34
lines changed

3 files changed

+35
-34
lines changed

control/lti.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,40 +52,39 @@ def __init__(self, inputs=1, outputs=1, dt=None):
5252
self.dt = dt
5353

5454
#
55-
# Getter and setter functions for legacy input/output attributes
55+
# Getter and setter functions for legacy state attributes
5656
#
57-
# For this iteration, generate a pending deprecation warning whenever
58-
# the getter/setter is called. For a future iteration, turn it into a
59-
# deprecation warning.
57+
# For this iteration, generate a deprecation warning whenever the
58+
# getter/setter is called. For a future iteration, turn it into a
59+
# future warning, so that users will see it.
6060
#
6161

6262
@property
6363
def inputs(self):
64-
raise PendingDeprecationWarning(
65-
"The LTI `inputs` attribute will be deprecated in a future "
66-
"release. Use `ninputs` instead.")
64+
warn("The LTI `inputs` attribute will be deprecated in a future "
65+
"release. Use `ninputs` instead.",
66+
DeprecationWarning, stacklevel=2)
6767
return self.ninputs
6868

6969
@inputs.setter
7070
def inputs(self, value):
71-
raise PendingDeprecationWarning(
72-
"The LTI `inputs` attribute will be deprecated in a future "
73-
"release. Use `ninputs` instead.")
74-
71+
warn("The LTI `inputs` attribute will be deprecated in a future "
72+
"release. Use `ninputs` instead.",
73+
DeprecationWarning, stacklevel=2)
7574
self.ninputs = value
7675

7776
@property
7877
def outputs(self):
79-
raise PendingDeprecationWarning(
80-
"The LTI `outputs` attribute will be deprecated in a future "
81-
"release. Use `noutputs` instead.")
78+
warn("The LTI `outputs` attribute will be deprecated in a future "
79+
"release. Use `noutputs` instead.",
80+
DeprecationWarning, stacklevel=2)
8281
return self.noutputs
8382

8483
@outputs.setter
8584
def outputs(self, value):
86-
raise PendingDeprecationWarning(
87-
"The LTI `outputs` attribute will be deprecated in a future "
88-
"release. Use `noutputs` instead.")
85+
warn("The LTI `outputs` attribute will be deprecated in a future "
86+
"release. Use `noutputs` instead.",
87+
DeprecationWarning, stacklevel=2)
8988
self.noutputs = value
9089

9190
def isdtime(self, strict=False):

control/statesp.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -333,24 +333,23 @@ def __init__(self, *args, **kwargs):
333333
#
334334
# Getter and setter functions for legacy state attributes
335335
#
336-
# For this iteration, generate a pending deprecation warning whenever
337-
# the getter/setter is called. For a future iteration, turn it into a
338-
# deprecation warning.
336+
# For this iteration, generate a deprecation warning whenever the
337+
# getter/setter is called. For a future iteration, turn it into a
338+
# future warning, so that users will see it.
339339
#
340340

341341
@property
342342
def states(self):
343-
raise PendingDeprecationWarning(
344-
"The StateSpace `states` attribute will be deprecated in a future "
345-
"release. Use `nstates` instead.")
343+
warn("The StateSpace `states` attribute will be deprecated in a "
344+
"future release. Use `nstates` instead.",
345+
DeprecationWarning, stacklevel=2)
346346
return self.nstates
347347

348348
@states.setter
349349
def states(self, value):
350-
raise PendingDeprecationWarning(
351-
"The StateSpace `states` attribute will be deprecated in a future "
352-
"release. Use `nstates` instead.")
353-
# raise PendingDeprecationWarning(
350+
warn("The StateSpace `states` attribute will be deprecated in a "
351+
"future release. Use `nstates` instead.",
352+
DeprecationWarning, stacklevel=2)
354353
self.nstates = value
355354

356355
def _remove_useless_states(self):

control/tests/lti_test.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,16 @@ def test_squeeze_exceptions(self, fcn):
251251
sys([[0.1, 1], [1, 10]])
252252
evalfr(sys, [[0.1, 1], [1, 10]])
253253

254-
with pytest.raises(PendingDeprecationWarning, match="LTI `inputs`"):
255-
assert sys.inputs == sys.ninputs
254+
with pytest.warns(DeprecationWarning, match="LTI `inputs`"):
255+
ninputs = sys.inputs
256+
assert ninputs == sys.ninputs
256257

257-
with pytest.raises(PendingDeprecationWarning, match="LTI `outputs`"):
258-
assert sys.outputs == sys.noutputs
258+
with pytest.warns(DeprecationWarning, match="LTI `outputs`"):
259+
noutputs = sys.outputs
260+
assert noutputs == sys.noutputs
259261

260262
if isinstance(sys, ct.StateSpace):
261-
with pytest.raises(
262-
PendingDeprecationWarning, match="StateSpace `states`"):
263-
assert sys.states == sys.nstates
263+
with pytest.warns(
264+
DeprecationWarning, match="StateSpace `states`"):
265+
nstates = sys.states
266+
assert nstates == sys.nstates

0 commit comments

Comments
 (0)