Skip to content

Commit bf0244a

Browse files
authored
Merge pull request #79 from bobleesj/cookie-lambda-direct
Fix flake8 error lambda functions (E731) with direct substitution
2 parents 563de3f + 02ce549 commit bf0244a

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

src/diffpy/srfit/fitbase/fithook.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ def postcall(self, recipe, chiv):
150150
print("Variables")
151151
vnames = recipe.getNames()
152152
vals = recipe.getValues()
153-
byname = lambda nv: sortKeyForNumericString(nv[0])
154-
items = sorted(zip(vnames, vals), key=byname)
153+
items = sorted(zip(vnames, vals), key=lambda nv: sortKeyForNumericString(nv[0]))
155154
for name, val in items:
156155
print(" %s = %f" % (name, val))
157156
return

src/diffpy/srfit/fitbase/recipeorganizer.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -730,8 +730,7 @@ def clearConstraints(self, recurse=False):
730730
self.unconstrain(*self._constraints)
731731

732732
if recurse:
733-
f = lambda m: hasattr(m, "clearConstraints")
734-
for m in filter(f, self._iterManaged()):
733+
for m in filter(lambda m: hasattr(m, "clearConstraints"), self._iterManaged()):
735734
m.clearConstraints(recurse)
736735
return
737736

@@ -813,17 +812,15 @@ def clearRestraints(self, recurse=False):
813812
self.unrestrain(*self._restraints)
814813

815814
if recurse:
816-
f = lambda m: hasattr(m, "clearRestraints")
817-
for m in filter(f, self._iterManaged()):
815+
for m in filter(lambda m: hasattr(m, "clearRestraints"), self._iterManaged()):
818816
m.clearRestraints(recurse)
819817
return
820818

821819
def _getConstraints(self, recurse=True):
822820
"""Get the constrained Parameters for this and managed sub-objects."""
823821
constraints = {}
824822
if recurse:
825-
f = lambda m: hasattr(m, "_getConstraints")
826-
for m in filter(f, self._iterManaged()):
823+
for m in filter(lambda m: hasattr(m, "_getConstraints"), self._iterManaged()):
827824
constraints.update(m._getConstraints(recurse))
828825

829826
constraints.update(self._constraints)
@@ -837,8 +834,7 @@ def _getRestraints(self, recurse=True):
837834
"""
838835
restraints = set(self._restraints)
839836
if recurse:
840-
f = lambda m: hasattr(m, "_getRestraints")
841-
for m in filter(f, self._iterManaged()):
837+
for m in filter(lambda m: hasattr(m, "_getRestraints"), self._iterManaged()):
842838
restraints.update(m._getRestraints(recurse))
843839

844840
return restraints

src/diffpy/srfit/tests/testbuilder.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def testParseEquation(self):
157157
eq.x.setValue(x)
158158
eq.B.setValue(B)
159159
eq.C.setValue(C)
160-
f = lambda A, x, B, C: A * sin(0.5 * x) + divide(B, C)
160+
f = lambda A, x, B, C: A * sin(0.5 * x) + divide(B, C) # noqa: E731
161161
self.assertTrue(array_equal(eq(), f(A, x, B, C)))
162162

163163
# Make sure that the arguments of eq are listed in the order in which
@@ -170,7 +170,7 @@ def testParseEquation(self):
170170
sigma = 0.1
171171
eq.x.setValue(x)
172172
eq.sigma.setValue(sigma)
173-
f = lambda x, sigma: sqrt(e ** (-0.5 * (x / sigma) ** 2))
173+
f = lambda x, sigma: sqrt(e ** (-0.5 * (x / sigma) ** 2)) # noqa: E731
174174
self.assertTrue(numpy.allclose(eq(), f(x, sigma)))
175175

176176
self.assertEqual(eq.args, [eq.x, eq.sigma])
@@ -246,7 +246,7 @@ def _f(a, b):
246246
sigma = builder.ArgumentBuilder(name="sigma", value=0.1)
247247
beq = sqrt(e ** (-0.5 * (x / sigma) ** 2))
248248
eq = beq.getEquation()
249-
f = lambda x, sigma: sqrt(e ** (-0.5 * (x / sigma) ** 2))
249+
f = lambda x, sigma: sqrt(e ** (-0.5 * (x / sigma) ** 2)) # noqa: E731
250250
self.assertTrue(numpy.allclose(eq(), numpy.sqrt(e ** (-0.5 * (_x / 0.1) ** 2))))
251251

252252
# Equation with Equation

0 commit comments

Comments
 (0)