Skip to content

Commit 61d845d

Browse files
authored
Merge pull request #167 from cadenmyers13/setvalue-dep
Deprecate: deprecate `setValue` and remove deprecated Python2 objects
2 parents 89a5558 + bb99611 commit 61d845d

30 files changed

+323
-230
lines changed

.codecov.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ coverage:
55
target: auto # use the coverage from the base commit, fail if coverage is lower
66
threshold: 0% # allow the coverage to drop by
77

8+
ignore:
9+
- "tests/test_speed.py" # ignore performance testing in test coverage.
10+
811
comment:
912
layout: " diff, flags, files"
1013
behavior: default

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,

news/setvalue-dep.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* Added ``set_value`` method to ``diffpy.srfit.fitbase.Parameter``.
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* Deprecated ``setValue`` method in ``diffpy.srfit.fitbase.Parameter`` for removal in 4.0.0.
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

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: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,30 @@
1616

1717
__all__ = ["LiteralABC", "ArgumentABC", "OperatorABC"]
1818

19+
from abc import ABC, abstractmethod
1920

20-
from abc import ABCMeta, abstractmethod, abstractproperty
2121

22-
import six
23-
24-
25-
@six.add_metaclass(ABCMeta)
26-
class LiteralABC(object):
22+
class LiteralABC(ABC):
2723
"""Abstract Base Class for Literal.
2824
2925
See Literal for usage.
3026
"""
3127

3228
@abstractmethod
3329
def identify(self, visitor):
30+
"""Identify this literal using a visitor."""
3431
pass
3532

3633
@abstractmethod
3734
def getValue(self):
35+
"""Return the value of the literal."""
3836
pass
3937

40-
name = abstractproperty(None, None)
38+
@property
39+
@abstractmethod
40+
def name(self):
41+
"""Name of the literal."""
42+
pass
4143

4244

4345
# End class LiteralABC
@@ -50,11 +52,21 @@ class ArgumentABC(LiteralABC):
5052
"""
5153

5254
@abstractmethod
53-
def setValue(self, value):
55+
def set_value(self, value):
56+
"""Set the value of the argument."""
5457
pass
5558

56-
const = abstractproperty(None, None)
57-
value = abstractproperty(None, None)
59+
@property
60+
@abstractmethod
61+
def const(self):
62+
"""Whether the argument is constant."""
63+
pass
64+
65+
@property
66+
@abstractmethod
67+
def value(self):
68+
"""Value of the argument."""
69+
pass
5870

5971

6072
# End class ArgumentABC
@@ -68,14 +80,44 @@ class OperatorABC(LiteralABC):
6880

6981
@abstractmethod
7082
def addLiteral(self, literal):
83+
"""Add a literal argument to the operator."""
84+
pass
85+
86+
@property
87+
@abstractmethod
88+
def args(self):
89+
"""Arguments of the operator."""
90+
pass
91+
92+
@property
93+
@abstractmethod
94+
def nin(self):
95+
"""Number of input arguments."""
7196
pass
7297

73-
args = abstractproperty(None, None)
74-
nin = abstractproperty(None, None)
75-
nout = abstractproperty(None, None)
76-
operation = abstractproperty(None, None)
77-
symbol = abstractproperty(None, None)
78-
value = abstractproperty(None, None)
98+
@property
99+
@abstractmethod
100+
def nout(self):
101+
"""Number of outputs."""
102+
pass
103+
104+
@property
105+
@abstractmethod
106+
def operation(self):
107+
"""Callable implementing the operator."""
108+
pass
109+
110+
@property
111+
@abstractmethod
112+
def symbol(self):
113+
"""Symbol representing the operator."""
114+
pass
115+
116+
@property
117+
@abstractmethod
118+
def value(self):
119+
"""Value produced by the operator."""
120+
pass
79121

80122

81123
# End class OperatorABC

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

0 commit comments

Comments
 (0)