Skip to content

Commit

Permalink
fix up deprecation warnings in response to @bnavigator review
Browse files Browse the repository at this point in the history
  • Loading branch information
murrayrm committed Jan 24, 2021
1 parent f633874 commit ff5fb39
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 33 deletions.
33 changes: 16 additions & 17 deletions control/lti.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,40 +52,39 @@ def __init__(self, inputs=1, outputs=1, dt=None):
self.dt = dt

#
# Getter and setter functions for legacy input/output attributes
# Getter and setter functions for legacy state attributes
#
# For this iteration, generate a pending deprecation warning whenever
# the getter/setter is called. For a future iteration, turn it into a
# deprecation warning.
# For this iteration, generate a deprecation warning whenever the
# getter/setter is called. For a future iteration, turn it into a
# future warning, so that users will see it.
#

@property
def inputs(self):
raise PendingDeprecationWarning(
"The LTI `inputs` attribute will be deprecated in a future "
"release. Use `ninputs` instead.")
warn("The LTI `inputs` attribute will be deprecated in a future "
"release. Use `ninputs` instead.",
PendingDeprecationWarning, stacklevel=2)
return self.ninputs

@inputs.setter
def inputs(self, value):
raise PendingDeprecationWarning(
"The LTI `inputs` attribute will be deprecated in a future "
"release. Use `ninputs` instead.")

warn("The LTI `inputs` attribute will be deprecated in a future "
"release. Use `ninputs` instead.",
PendingDeprecationWarning, stacklevel=2)
self.ninputs = value

@property
def outputs(self):
raise PendingDeprecationWarning(
"The LTI `outputs` attribute will be deprecated in a future "
"release. Use `noutputs` instead.")
warn("The LTI `outputs` attribute will be deprecated in a future "
"release. Use `noutputs` instead.",
PendingDeprecationWarning, stacklevel=2)
return self.noutputs

@outputs.setter
def outputs(self, value):
raise PendingDeprecationWarning(
"The LTI `outputs` attribute will be deprecated in a future "
"release. Use `noutputs` instead.")
warn("The LTI `outputs` attribute will be deprecated in a future "
"release. Use `noutputs` instead.",
PendingDeprecationWarning, stacklevel=2)
self.noutputs = value

def isdtime(self, strict=False):
Expand Down
19 changes: 9 additions & 10 deletions control/statesp.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,24 +333,23 @@ def __init__(self, *args, **kwargs):
#
# Getter and setter functions for legacy state attributes
#
# For this iteration, generate a pending deprecation warning whenever
# the getter/setter is called. For a future iteration, turn it into a
# deprecation warning.
# For this iteration, generate a deprecation warning whenever the
# getter/setter is called. For a future iteration, turn it into a
# future warning, so that users will see it.
#

@property
def states(self):
raise PendingDeprecationWarning(
"The StateSpace `states` attribute will be deprecated in a future "
"release. Use `nstates` instead.")
warn("The StateSpace `states` attribute will be deprecated in a "
"future release. Use `nstates` instead.",
PendingDeprecationWarning, stacklevel=2)
return self.nstates

@states.setter
def states(self, value):
raise PendingDeprecationWarning(
"The StateSpace `states` attribute will be deprecated in a future "
"release. Use `nstates` instead.")
# raise PendingDeprecationWarning(
warn("The StateSpace `states` attribute will be deprecated in a "
"future release. Use `nstates` instead.",
PendingDeprecationWarning, stacklevel=2)
self.nstates = value

def _remove_useless_states(self):
Expand Down
15 changes: 9 additions & 6 deletions control/tests/lti_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,16 @@ def test_squeeze_exceptions(self, fcn):
sys([[0.1, 1], [1, 10]])
evalfr(sys, [[0.1, 1], [1, 10]])

with pytest.raises(PendingDeprecationWarning, match="LTI `inputs`"):
assert sys.inputs == sys.ninputs
with pytest.warns(PendingDeprecationWarning, match="LTI `inputs`"):
ninputs = sys.inputs
assert ninputs == sys.ninputs

with pytest.raises(PendingDeprecationWarning, match="LTI `outputs`"):
assert sys.outputs == sys.noutputs
with pytest.warns(PendingDeprecationWarning, match="LTI `outputs`"):
noutputs = sys.outputs
assert noutputs == sys.noutputs

if isinstance(sys, ct.StateSpace):
with pytest.raises(
with pytest.warns(
PendingDeprecationWarning, match="StateSpace `states`"):
assert sys.states == sys.nstates
nstates = sys.states
assert nstates == sys.nstates

0 comments on commit ff5fb39

Please sign in to comment.