Skip to content

Commit c4c0b10

Browse files
committed
setValue deprecation
1 parent 2453e1a commit c4c0b10

28 files changed

Lines changed: 206 additions & 190 deletions

docs/source/extending.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ can be adapted as::
108108
setter = SimpleAtom.set, attr = "x")
109109

110110
Thus, when ``xpar.getValue()`` is called, it in turn calls
111-
``SimpleAtom.get(atom, "x")``. ``xpar.setValue(value)`` calls
111+
``SimpleAtom.get(atom, "x")``. ``xpar.set_value(value)`` calls
112112
``SimpleAtom.set(atom, "x", value)``.
113113

114114
If the attributes of an object cannot be accessed in one of these three ways,

src/diffpy/srfit/equation/equationmod.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
these! > b = Argument(name="b") > add.addLiteral(a) > add.addLiteral(b)
2626
> # make an Equation instance and pass the root > eq = Equation(root =
2727
add) > eq(a=3, b=4) # returns 7 > eq(a=2) # remembers b=4, returns 6 >
28-
eq.a.setValue(-3) > eq.b.setValue(3) > eq() # uses last assignment of a
29-
and b, returns 0
28+
eq.a.set_value(-3) > eq.b.set_value(3) > eq() # uses last assignment of
29+
a and b, returns 0
3030
3131
See the class documentation for more information.
3232
"""
@@ -193,14 +193,14 @@ def __call__(self, *args, **kw):
193193
if idx >= len(self.argdict):
194194
raise ValueError("Too many arguments")
195195
arg = self.args[idx]
196-
arg.setValue(val)
196+
arg.set_value(val)
197197

198198
# Process kw
199199
for name, val in kw.items():
200200
arg = self.argdict.get(name)
201201
if arg is None:
202202
raise ValueError("No argument named '%s' here" % name)
203-
arg.setValue(val)
203+
arg.set_value(val)
204204

205205
self._value = self.root.getValue()
206206
return self._value

src/diffpy/srfit/equation/literals/abcs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class ArgumentABC(LiteralABC):
5252
"""
5353

5454
@abstractmethod
55-
def setValue(self, value):
55+
def set_value(self, value):
5656
"""Set the value of the argument."""
5757
pass
5858

src/diffpy/srfit/equation/literals/argument.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ class Argument(Literal, ArgumentABC):
3737
A flag indicating whether this is considered a constant.
3838
Constants may be given special treatment by the Visitors.
3939
_value
40-
The value of the Argument. Modified with 'setValue'.
40+
The value of the Argument. Modified with 'set_value'.
4141
value
42-
Property for 'getValue' and 'setValue'.
42+
Property for 'getValue' and 'set_value'.
4343
"""
4444

4545
const = None
@@ -59,7 +59,7 @@ def getValue(self):
5959
"""Get the value of this Literal."""
6060
return self._value
6161

62-
def setValue(self, val):
62+
def set_value(self, val):
6363
"""Set the value of the Literal.
6464
6565
Attributes
@@ -77,7 +77,7 @@ def setValue(self, val):
7777
return
7878

7979
value = property(
80-
lambda self: self.getValue(), lambda self, val: self.setValue(val)
80+
lambda self: self.getValue(), lambda self, val: self.set_value(val)
8181
)
8282

8383

src/diffpy/srfit/fitbase/constraint.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def update(self):
8282
val = self.eq()
8383
# This will only change the Parameter if val is different from the
8484
# currently stored value.
85-
self.par.setValue(val)
85+
self.par.set_value(val)
8686
return
8787

8888
def _validate(self):
@@ -107,7 +107,7 @@ def _validate(self):
107107
# Try to get the value of eq.
108108
try:
109109
val = self.eq()
110-
self.par.setValue(val)
110+
self.par.set_value(val)
111111
except TypeError:
112112
raise SrFitError("eq cannot be evaluated")
113113
finally:

src/diffpy/srfit/fitbase/fitrecipe.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ def add_variable(
759759
raise ValueError("The parameter '%s' is constrained" % par)
760760
var = ParameterProxy(name, par)
761761
if value is not None:
762-
var.setValue(value)
762+
var.set_value(value)
763763
self._add_parameter(var)
764764
if fixed:
765765
self.fix(var)
@@ -1185,7 +1185,7 @@ def constrain(self, par, con, ns={}):
11851185
val = con.getValue()
11861186
if val is None:
11871187
val = par.getValue()
1188-
con.setValue(val)
1188+
con.set_value(val)
11891189

11901190
if par in self._parameters.values():
11911191
self.fix(par)
@@ -1352,7 +1352,7 @@ def _set_parameters_from_dict(self, params_dict):
13521352
parameter names and values."""
13531353
for param_name, param_value in params_dict.items():
13541354
if param_name in self._parameters:
1355-
self._parameters[param_name].setValue(param_value)
1355+
self._parameters[param_name].set_value(param_value)
13561356
else:
13571357
print(
13581358
f"Warning: Parameter '{param_name}' from results "
@@ -1742,7 +1742,7 @@ def _apply_values(self, p):
17421742
return
17431743
vargen = (v for v in self._parameters.values() if self.is_free(v))
17441744
for var, pval in zip(vargen, p):
1745-
var.setValue(pval)
1745+
var.set_value(pval)
17461746
return
17471747

17481748
def _update_configuration(self):

src/diffpy/srfit/fitbase/parameter.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@
3434
from diffpy.srfit.interface import _parameter_interface
3535
from diffpy.srfit.util.argbinders import bind2nd
3636
from diffpy.srfit.util.nameutils import validateName
37+
from diffpy.utils._deprecator import build_deprecation_message, deprecated
38+
39+
parameter_base = "diffpy.srfit.fitbase.Parameter"
40+
removal_version = "4.0.0"
41+
setValue_dep_msg = build_deprecation_message(
42+
parameter_base, "setValue", "set_value", removal_version
43+
)
3744

3845

3946
class Parameter(_parameter_interface, Argument, Validatable):
@@ -46,9 +53,9 @@ class Parameter(_parameter_interface, Argument, Validatable):
4653
const
4754
A flag indicating whether this is considered a constant.
4855
_value
49-
The value of the Parameter. Modified with 'setValue'.
56+
The value of the Parameter. Modified with 'set_value'.
5057
value
51-
Property for 'getValue' and 'setValue'.
58+
Property for 'getValue' and 'set_value'.
5259
constrained
5360
A flag indicating if the Parameter is constrained
5461
(default False).
@@ -81,7 +88,7 @@ def __init__(self, name, value=None, const=False):
8188
Argument.__init__(self, name, value, const)
8289
return
8390

84-
def setValue(self, val):
91+
def set_value(self, val):
8592
"""Set the value of the Parameter and the bounds.
8693
8794
Attributes
@@ -100,9 +107,18 @@ def setValue(self, val):
100107
self
101108
Returns self so that mutators can be chained.
102109
"""
103-
Argument.setValue(self, val)
110+
Argument.set_value(self, val)
104111
return self
105112

113+
@deprecated(setValue_dep_msg)
114+
def setValue(self, val):
115+
"""This function has been deprecated and will be removed in
116+
version 4.0.0.
117+
118+
Please use diffpy.srfit.fitbase.Parameter.set_value instead.
119+
"""
120+
return self.set_value(val)
121+
106122
def setConst(self, const=True, value=None):
107123
"""Toggle the Parameter as constant.
108124
@@ -123,7 +139,7 @@ def setConst(self, const=True, value=None):
123139
"""
124140
self.const = bool(const)
125141
if value is not None:
126-
self.setValue(value)
142+
self.set_value(value)
127143
return self
128144

129145
def boundRange(self, lb=None, ub=None):
@@ -254,9 +270,9 @@ def _observers(self):
254270

255271
# wrap Parameter methods to use the target object ------------------------
256272

257-
@wraps(Parameter.setValue)
258-
def setValue(self, val):
259-
return self.par.setValue(val)
273+
@wraps(Parameter.set_value)
274+
def set_value(self, val):
275+
return self.par.set_value(val)
260276

261277
@wraps(Parameter.getValue)
262278
def getValue(self):
@@ -293,8 +309,8 @@ def _validate(self):
293309
class ParameterAdapter(Parameter):
294310
"""An adapter for parameter-like objects.
295311
296-
This class wraps an object as a Parameter. The getValue and setValue
297-
methods defer to the data of the wrapped object.
312+
This class wraps an object as a Parameter. The getValue and
313+
set_value methods defer to the data of the wrapped object.
298314
"""
299315

300316
def __init__(self, name, obj, getter=None, setter=None, attr=None):
@@ -359,7 +375,7 @@ def getValue(self):
359375
"""Get the value of the Parameter."""
360376
return self.getter(self.obj)
361377

362-
def setValue(self, value):
378+
def set_value(self, value):
363379
"""Set the value of the Parameter."""
364380
if value != self.getValue():
365381
self.setter(self.obj, value)

src/diffpy/srfit/fitbase/profile.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,19 @@ def __init__(self):
136136
# We want x, y, ycalc and dy to stay in-sync with xpar, ypar and dypar
137137
x = property(
138138
lambda self: self.xpar.getValue(),
139-
lambda self, val: self.xpar.setValue(val),
139+
lambda self, val: self.xpar.set_value(val),
140140
)
141141
y = property(
142142
lambda self: self.ypar.getValue(),
143-
lambda self, val: self.ypar.setValue(val),
143+
lambda self, val: self.ypar.set_value(val),
144144
)
145145
dy = property(
146146
lambda self: self.dypar.getValue(),
147-
lambda self, val: self.dypar.setValue(val),
147+
lambda self, val: self.dypar.set_value(val),
148148
)
149149
ycalc = property(
150150
lambda self: self.ycpar.getValue(),
151-
lambda self, val: self.ycpar.setValue(val),
151+
lambda self, val: self.ycpar.set_value(val),
152152
)
153153

154154
# We want xobs, yobs and dyobs to be read-only

src/diffpy/srfit/interface/interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ParameterInterface(object):
3636
"""Mix-in class for enhancing the Parameter interface."""
3737

3838
def __lshift__(self, v):
39-
"""SetValue with <<
39+
"""set_value with <<
4040
4141
Think of '<<' as injecting a value
4242

src/diffpy/srfit/pdf/basepdfgenerator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def processMetaData(self):
174174
val = self.meta.get(name)
175175
if val is not None:
176176
par = self.get(name)
177-
par.setValue(val)
177+
par.set_value(val)
178178

179179
return
180180

0 commit comments

Comments
 (0)