Skip to content

Commit ff4d668

Browse files
authored
Merge pull request #138 from cadenmyers13/rm-camelcase-privatefuncs
fix: change camelcase to snakecase in all private functions
2 parents 256d9e1 + 32d69ab commit ff4d668

35 files changed

+323
-294
lines changed

docs/examples/gaussiangenerator.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ def __init__(self, name):
8585
# This initializes various parts of the generator
8686
ProfileGenerator.__init__(self, name)
8787

88-
# Here we create new Parameters using the '_newParameter' method of
88+
# Here we create new Parameters using the '_new_parameter' method of
8989
# ProfileGenerator. The signature is
90-
# _newParameter(name, value).
90+
# _new_parameter(name, value).
9191
# See the API for full details.
92-
self._newParameter("A", 1.0)
93-
self._newParameter("x0", 0.0)
94-
self._newParameter("sigma", 1.0)
92+
self._new_parameter("A", 1.0)
93+
self._new_parameter("x0", 0.0)
94+
self._new_parameter("sigma", 1.0)
9595
return
9696

9797
def __call__(self, x):
@@ -101,7 +101,7 @@ def __call__(self, x):
101101
variable, x. We will define it as we did in gaussianrecipe.py.
102102
"""
103103
# First we must get the values of the Parameters. Since we used
104-
# _newParameter to create them, the Parameters are accessible as
104+
# _new_parameter to create them, the Parameters are accessible as
105105
# attributes by name.
106106
A = self.A.value
107107
x0 = self.x0.value

docs/source/extending.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ structures. The restraint is applied with the ``restrainBVS`` method.
236236
The purpose of the method is to create the custom ``Restraint`` object,
237237
configure it and store it. Note that the optional `sig` and `scaled` flag are
238238
passed as part of this method. Both ``_restraints`` and
239-
``_updateConfiguration`` come from ``ParameterSet``, from which
239+
``_update_configuration`` come from ``ParameterSet``, from which
240240
``SrRealParSet`` is derived. The ``_restraints`` attribute is a set of
241-
``Restraints`` on the object. The ``_updateConfiguration`` method makes any
241+
``Restraints`` on the object. The ``_update_configuration`` method makes any
242242
object containing the ``SrRealParSet`` aware of the configuration change. This
243243
gets propagated to the top-level ``FitRecipe``, if there is one. The restraint
244244
object is returned by the method so that it may be later removed.

news/rm-camelcase-privatefuncs.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* No news needed, changed private functions from camelcase to snakecase.
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
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/builder.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def makeEquation(
165165
166166
Returns a callable Literal representing the equation string.
167167
"""
168-
self._prepareBuilders(eqstr, buildargs, argclass, argkw)
168+
self._prepare_builders(eqstr, buildargs, argclass, argkw)
169169
beq = eval(eqstr, {}, self.builders)
170170
# handle scalar numbers or numpy arrays
171171
if isinstance(beq, (numbers.Number, numpy.ndarray)):
@@ -301,7 +301,7 @@ def wipeout(self, eq):
301301
eq.setRoot(nan)
302302
return
303303

304-
def _prepareBuilders(self, eqstr, buildargs, argclass, argkw):
304+
def _prepare_builders(self, eqstr, buildargs, argclass, argkw):
305305
"""Prepare builders so that equation string can be evaluated.
306306
307307
This method checks the equation string for errors and missing
@@ -332,7 +332,7 @@ def _prepareBuilders(self, eqstr, buildargs, argclass, argkw):
332332
Returns a dictionary of the name, BaseBuilder pairs.
333333
"""
334334

335-
eqargs = self._getUndefinedArgs(eqstr)
335+
eqargs = self._get_undefined_args(eqstr)
336336

337337
# Raise an error if there are arguments that need to be created, but
338338
# this is disallowed.
@@ -353,7 +353,7 @@ def _prepareBuilders(self, eqstr, buildargs, argclass, argkw):
353353

354354
return
355355

356-
def _getUndefinedArgs(self, eqstr):
356+
def _get_undefined_args(self, eqstr):
357357
"""Get the undefined arguments from eqstr.
358358
359359
This tokenizes eqstr and extracts undefined arguments. An
@@ -441,7 +441,7 @@ def getEquation(self):
441441
eq = Equation(name, self.literal)
442442
return eq
443443

444-
def __evalBinary(self, other, OperatorClass, onleft=True):
444+
def __eval_binary(self, other, OperatorClass, onleft=True):
445445
"""Evaluate a binary function.
446446
447447
Other can be an BaseBuilder or a constant.
@@ -479,7 +479,7 @@ def __evalBinary(self, other, OperatorClass, onleft=True):
479479
opbuilder.literal = op
480480
return opbuilder
481481

482-
def __evalUnary(self, OperatorClass):
482+
def __eval_unary(self, OperatorClass):
483483
"""Evaluate a unary function."""
484484
op = OperatorClass()
485485
op.addLiteral(self.literal)
@@ -488,28 +488,30 @@ def __evalUnary(self, OperatorClass):
488488
return opbuilder
489489

490490
def __add__(self, other):
491-
return self.__evalBinary(other, literals.AdditionOperator)
491+
return self.__eval_binary(other, literals.AdditionOperator)
492492

493493
def __radd__(self, other):
494-
return self.__evalBinary(other, literals.AdditionOperator, False)
494+
return self.__eval_binary(other, literals.AdditionOperator, False)
495495

496496
def __sub__(self, other):
497-
return self.__evalBinary(other, literals.SubtractionOperator)
497+
return self.__eval_binary(other, literals.SubtractionOperator)
498498

499499
def __rsub__(self, other):
500-
return self.__evalBinary(other, literals.SubtractionOperator, False)
500+
return self.__eval_binary(other, literals.SubtractionOperator, False)
501501

502502
def __mul__(self, other):
503-
return self.__evalBinary(other, literals.MultiplicationOperator)
503+
return self.__eval_binary(other, literals.MultiplicationOperator)
504504

505505
def __rmul__(self, other):
506-
return self.__evalBinary(other, literals.MultiplicationOperator, False)
506+
return self.__eval_binary(
507+
other, literals.MultiplicationOperator, False
508+
)
507509

508510
def __truediv__(self, other):
509-
return self.__evalBinary(other, literals.DivisionOperator)
511+
return self.__eval_binary(other, literals.DivisionOperator)
510512

511513
def __rtruediv__(self, other):
512-
return self.__evalBinary(other, literals.DivisionOperator, False)
514+
return self.__eval_binary(other, literals.DivisionOperator, False)
513515

514516
# Python 2 Compatibility -------------------------------------------------
515517

@@ -520,19 +522,21 @@ def __rtruediv__(self, other):
520522
# ------------------------------------------------------------------------
521523

522524
def __pow__(self, other):
523-
return self.__evalBinary(other, literals.ExponentiationOperator)
525+
return self.__eval_binary(other, literals.ExponentiationOperator)
524526

525527
def __rpow__(self, other):
526-
return self.__evalBinary(other, literals.ExponentiationOperator, False)
528+
return self.__eval_binary(
529+
other, literals.ExponentiationOperator, False
530+
)
527531

528532
def __mod__(self, other):
529-
return self.__evalBinary(other, literals.RemainderOperator)
533+
return self.__eval_binary(other, literals.RemainderOperator)
530534

531535
def __rmod__(self, other):
532-
return self.__evalBinary(other, literals.RemainderOperator, False)
536+
return self.__eval_binary(other, literals.RemainderOperator, False)
533537

534538
def __neg__(self):
535-
return self.__evalUnary(literals.NegationOperator)
539+
return self.__eval_unary(literals.NegationOperator)
536540

537541

538542
# These are used by the class.
@@ -706,7 +710,7 @@ def getBuilder(name):
706710
return _builders[name]
707711

708712

709-
def __wrapNumpyOperators():
713+
def __wrap_numpy_operators():
710714
"""Export all numpy operators as OperatorBuilder instances in the module
711715
namespace."""
712716
for name in dir(numpy):
@@ -716,11 +720,11 @@ def __wrapNumpyOperators():
716720
return
717721

718722

719-
__wrapNumpyOperators()
723+
__wrap_numpy_operators()
720724

721725

722726
# Register other functions as well
723-
def __wrapSrFitOperators():
727+
def __wrap_srfit_operators():
724728
"""Export all non-base operators from the
725729
diffpy.srfit.equation.literals.operators module as OperatorBuilder
726730
instances in the module namespace."""
@@ -744,6 +748,6 @@ def _is_exported_type(cls):
744748
return
745749

746750

747-
__wrapSrFitOperators()
751+
__wrap_srfit_operators()
748752

749753
# End of file

src/diffpy/srfit/equation/equationmod.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ def operation(self, *args, **kw):
125125
"""
126126
return self.__call__(*args, **kw)
127127

128-
def _getArgs(self):
128+
def _get_args(self):
129129
return list(self.argdict.values())
130130

131-
args = property(_getArgs)
131+
args = property(_get_args)
132132

133133
def __getattr__(self, name):
134134
"""Gives access to the Arguments as attributes."""

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def addLiteral(self, literal):
113113
Raises ValueError if the literal causes a self-reference.
114114
"""
115115
# Make sure we don't have self-reference
116-
self._loopCheck(literal)
116+
self._loop_check(literal)
117117
self.args.append(literal)
118118
literal.addObserver(self._flush)
119119
self._flush(other=(self,))
@@ -128,15 +128,15 @@ def getValue(self):
128128

129129
value = property(lambda self: self.getValue())
130130

131-
def _loopCheck(self, literal):
131+
def _loop_check(self, literal):
132132
"""Check if a literal causes self-reference."""
133133
if literal is self:
134134
raise ValueError("'%s' causes self-reference" % literal)
135135

136136
# Check to see if I am a dependency of the literal.
137137
if hasattr(literal, "args"):
138138
for lit_arg in literal.args:
139-
self._loopCheck(lit_arg)
139+
self._loop_check(lit_arg)
140140
return
141141

142142

src/diffpy/srfit/equation/visitors/printer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def onOperator(self, op):
8787
"""Process an Operator node."""
8888
# We have to deal with infix operators
8989
if op.name != op.symbol and op.nin == 2:
90-
self._onInfix(op)
90+
self._on_infix(op)
9191
return self.output
9292

9393
self.output += str(op.name) + "("
@@ -111,7 +111,7 @@ def onEquation(self, eq):
111111
eq.root.identify(self)
112112
return self.output
113113

114-
def _onInfix(self, op):
114+
def _on_infix(self, op):
115115
"""Process infix operators."""
116116
self.output += "("
117117
op.args[0].identify(self)

src/diffpy/srfit/equation/visitors/swapper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def onOperator(self, op):
105105
# Validate the new literal. If it fails, we need to restore the
106106
# old one
107107
try:
108-
op._loopCheck(newlit)
108+
op._loop_check(newlit)
109109
except ValueError:
110110
# Restore the old literal
111111
op.args.insert(idx, oldlit)
@@ -135,9 +135,9 @@ def onEquation(self, eq):
135135
eq.setRoot(self.newlit)
136136
return
137137

138-
# Now move into the equation. We have to do a _loopCheck to make sure
138+
# Now move into the equation. We have to do a _loop_check to make sure
139139
# that we won't have any loops in the equation.
140-
eq._loopCheck(self.newlit)
140+
eq._loop_check(self.newlit)
141141
eq.root.identify(self)
142142

143143
# Reset the root in case anything changed underneath.

src/diffpy/srfit/fitbase/configurable.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ def __init__(self):
3737
self._configobjs = set()
3838
return
3939

40-
def _updateConfiguration(self):
40+
def _update_configuration(self):
4141
"""Notify Configurables in hierarchy of configuration change."""
4242
for obj in self._configobjs:
43-
obj._updateConfiguration()
43+
obj._update_configuration()
4444
return
4545

46-
def _storeConfigurable(self, obj):
46+
def _store_configurable(self, obj):
4747
"""Store a Configurable.
4848
4949
The passed obj is only stored if it is a a Configurable,

src/diffpy/srfit/fitbase/fitcontribution.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def addProfileGenerator(self, gen, name=None):
188188
# Register the generator with the equation factory and add it as a
189189
# managed object.
190190
self._eqfactory.registerOperator(name, gen)
191-
self._addObject(gen, self._generators, True)
191+
self._add_object(gen, self._generators, True)
192192

193193
# If we have a profile, set the profile of the generator.
194194
if self.profile is not None:
@@ -231,7 +231,7 @@ def setEquation(self, eqstr, ns={}):
231231

232232
# Register any new Parameters.
233233
for par in self._eqfactory.newargs:
234-
self._addParameter(par)
234+
self._add_parameter(par)
235235

236236
# Register eq as an operator
237237
self._eqfactory.registerOperator("eq", eq)

0 commit comments

Comments
 (0)