Skip to content

Fix rest of flake8 error lambda functions (E731) #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/diffpy/srfit/equation/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,13 +662,16 @@ def __wrapSrFitOperators():
"""
opmod = literals.operators
excluded_types = set((opmod.CustomOperator, opmod.UFuncOperator))
# check if opmod member should be wrapped as OperatorBuilder
is_exported_type = lambda cls: (
inspect.isclass(cls)
and issubclass(cls, opmod.Operator)
and not inspect.isabstract(cls)
and cls not in excluded_types
)

def is_exported_type(cls):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__wrapSrFitOperators is a public function and I decided to make is_exported_type nested as well to encapsulate.

"""Check if the class should be wrapped as OperatorBuilder."""
return (
inspect.isclass(cls) and
issubclass(cls, opmod.Operator) and
not inspect.isabstract(cls) and
cls not in excluded_types
)

# create OperatorBuilder objects
for nm, opclass in inspect.getmembers(opmod, is_exported_type):
op = opclass()
Expand Down
4 changes: 1 addition & 3 deletions src/diffpy/srfit/sas/prcalculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ def __call__(self, r):
self._invertor.y = iq
self._invertor.err = diq
c, c_cov = self._invertor.invert_optimize()
calculate_pr = lambda x: self._invertor.pr(c, x)
pr = map(calculate_pr, r)

pr = map(lambda x: self._invertor.pr(c, x), r)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Directly inserted the lambda inside the map.

pr = numpy.array(pr)
return self.scale.value * pr

Expand Down
2 changes: 1 addition & 1 deletion src/diffpy/srfit/tests/testcontribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def test_releaseOldEquations(self):
def test_registerFunction(self):
"""Ensure registered function works after second setEquation call."""
fc = self.fitcontribution
fsquare = lambda x: x**2
fsquare = lambda x: x**2 # noqa: E731
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For testing, its usage seems ok, adding noqa.

fc.registerFunction(fsquare, name="fsquare")
fc.setEquation("fsquare")
fc.x.setValue(5)
Expand Down