Skip to content

Commit 9046255

Browse files
committed
flake8: equation
1 parent 191fe7d commit 9046255

5 files changed

Lines changed: 36 additions & 33 deletions

File tree

src/diffpy/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
# (c) 2008-2025 The Trustees of Columbia University in the City of New York.
55
# All rights reserved.
66
#
7-
# File coded by: Chris Farrow and Billinge Group members and community contributors.
7+
# File coded by: Chris Farrow and Billinge Group members and community
8+
# contributors.
89
#
910
# See GitHub contributions for a more detailed list of contributors.
1011
# https://github.com/diffpy/diffpy.srfit/graphs/contributors

src/diffpy/srfit/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
# (c) 2008-2025 The Trustees of Columbia University in the City of New York.
55
# All rights reserved.
66
#
7-
# File coded by: Christopher Farrow, Pavol Juhas, and members of the Billinge Group.
7+
# File coded by: Christopher Farrow, Pavol Juhas, and members of the
8+
# Billinge Group.
89
#
910
# See GitHub contributions for a more detailed list of contributors.
1011
# https://github.com/diffpy/diffpy.srfit/graphs/contributors

src/diffpy/srfit/equation/builder.py

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@
7575
> beq = c*f(a,b)
7676
> eq = beq.makeEquation()
7777
"""
78+
import inspect
79+
import numbers
80+
import token
81+
import tokenize
82+
83+
import numpy
84+
import six
85+
86+
import diffpy.srfit.equation.literals as literals
87+
from diffpy.srfit.equation.equationmod import Equation
88+
from diffpy.srfit.equation.literals.literal import Literal
7889

7990
__all__ = [
8091
"EquationFactory",
@@ -95,25 +106,15 @@
95106
_builders = {}
96107

97108

98-
import inspect
99-
import numbers
100-
101-
import numpy
102-
import six
103-
104-
import diffpy.srfit.equation.literals as literals
105-
from diffpy.srfit.equation.equationmod import Equation
106-
from diffpy.srfit.equation.literals.literal import Literal
107-
108-
109109
class EquationFactory(object):
110110
"""A Factory for equations.
111111
112112
builders -- A dictionary of BaseBuilders registered with the
113113
factory, indexed by name.
114114
newargs -- A set of new arguments created by makeEquation. This is
115115
redefined whenever makeEquation is called.
116-
equations -- Set of equations that have been built by the EquationFactory.
116+
equations -- Set of equations that have been built by the
117+
EquationFactory.
117118
"""
118119

119120
symbols = ("+", "-", "*", "/", "**", "%", "|")
@@ -213,10 +214,10 @@ def registerFunction(self, name, func, argnames):
213214
if n not in self.builders:
214215
self.registerConstant(n, 0)
215216
opbuilder = wrapFunction(name, func, len(argnames))
216-
for n in argnames:
217-
b = self.builders[n]
218-
l = b.literal
219-
opbuilder.literal.addLiteral(l)
217+
for argname in argnames:
218+
builder = self.builders[argname]
219+
argliteral = builder.literal
220+
opbuilder.literal.addLiteral(argliteral)
220221

221222
return self.registerBuilder(name, opbuilder)
222223

@@ -341,9 +342,6 @@ def _getUndefinedArgs(self, eqstr):
341342
342343
Raises SyntaxError if the equation string uses invalid syntax.
343344
"""
344-
import token
345-
import tokenize
346-
347345
interface = six.StringIO(eqstr).readline
348346
# output is an iterator. Each entry (token) is a 5-tuple
349347
# token[0] = token type
@@ -512,7 +510,7 @@ def __neg__(self):
512510
return self.__evalUnary(literals.NegationOperator)
513511

514512

515-
## These are used by the class.
513+
# These are used by the class.
516514

517515

518516
class ArgumentBuilder(BaseBuilder):
@@ -681,15 +679,18 @@ def __wrapSrFitOperators():
681679
instances in the module namespace."""
682680
opmod = literals.operators
683681
excluded_types = set((opmod.CustomOperator, opmod.UFuncOperator))
682+
684683
# check if opmod member should be wrapped as OperatorBuilder
685-
is_exported_type = lambda cls: (
686-
inspect.isclass(cls)
687-
and issubclass(cls, opmod.Operator)
688-
and not inspect.isabstract(cls)
689-
and not cls in excluded_types
690-
)
684+
def _is_exported_type(cls):
685+
return (
686+
inspect.isclass(cls)
687+
and issubclass(cls, opmod.Operator)
688+
and not inspect.isabstract(cls)
689+
and cls not in excluded_types
690+
)
691+
691692
# create OperatorBuilder objects
692-
for nm, opclass in inspect.getmembers(opmod, is_exported_type):
693+
for nm, opclass in inspect.getmembers(opmod, _is_exported_type):
693694
op = opclass()
694695
assert op.name, "Unnamed Operator should never appear here."
695696
_builders[op.name] = OperatorBuilder(op.name, op)

src/diffpy/srfit/equation/equationmod.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def __getattr__(self, name):
117117
"""Gives access to the Arguments as attributes."""
118118
# Avoid infinite loop on argdict lookup.
119119
argdict = object.__getattribute__(self, "argdict")
120-
if not name in argdict:
120+
if name not in argdict:
121121
raise AttributeError("No argument named '%s' here" % name)
122122
return argdict[name]
123123

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def addLiteral(self, literal):
122122
def getValue(self):
123123
"""Get or evaluate the value of the operator."""
124124
if self._value is None:
125-
vals = [l.value for l in self.args]
125+
vals = [arg.value for arg in self.args]
126126
self._value = self.operation(*vals)
127127
return self._value
128128

@@ -135,8 +135,8 @@ def _loopCheck(self, literal):
135135

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

142142

0 commit comments

Comments
 (0)