diff --git a/pymbolic/compiler.py b/pymbolic/compiler.py index 7a3d3d752557dab7bb099e155587c3ee76376e45..a5b37781fac1d513b9f76cc56be2b0d03b5d0d97 100644 --- a/pymbolic/compiler.py +++ b/pymbolic/compiler.py @@ -94,13 +94,15 @@ class CompiledExpression: Its instances (unlike plain lambdas) are pickleable. """ - def __init__(self, expression, variables=[]): + def __init__(self, expression, variables=None): """ :arg variables: The first arguments (as strings or :class:`pymbolic.primitives.Variable` instances) to be used for the compiled function. All variables used by the expression and not present here are added in lexicographic order. """ + if variables is None: + variables = [] self._compile(expression, variables) def _compile(self, expression, variables): diff --git a/pymbolic/geometric_algebra/__init__.py b/pymbolic/geometric_algebra/__init__.py index bd542fad07f37ff5dc6ee7d777da60ad9a01dca5..572a7c7e28fdbfa2b3b768b9d376aa9d51db15d3 100644 --- a/pymbolic/geometric_algebra/__init__.py +++ b/pymbolic/geometric_algebra/__init__.py @@ -990,7 +990,7 @@ class MultiVector: result = None - for bits, coeff in self.data.items(): + for bits in self.data.keys(): grade = bit_count(bits) if result is None: result = grade diff --git a/pymbolic/geometric_algebra/mapper.py b/pymbolic/geometric_algebra/mapper.py index 2e07d6fb87f470fd6ad86b1813f4d73ee31a4529..56d5494e93d1877200b1ce5f9b95ac24924c531a 100644 --- a/pymbolic/geometric_algebra/mapper.py +++ b/pymbolic/geometric_algebra/mapper.py @@ -264,7 +264,7 @@ class DerivativeBinder(IdentityMapper): # a list of lists, the outer level presenting a sum, the inner a product result = [list(expr.children)] - for child_idx, (d_source_nabla_ids, child) in enumerate( + for child_idx, (d_source_nabla_ids, _child) in enumerate( zip(d_source_nabla_ids_per_child, expr.children)): if not d_source_nabla_ids: continue diff --git a/pymbolic/mapper/__init__.py b/pymbolic/mapper/__init__.py index d66d5fbcc0f236d7912a41a395fa74e625d88cb7..ba6731b556b86264283cd726ee5b16d3548f1ede 100644 --- a/pymbolic/mapper/__init__.py +++ b/pymbolic/mapper/__init__.py @@ -680,7 +680,7 @@ class WalkMapper(RecursiveMapper): return self.rec(expr.base, *args, **kwargs) - for exp, coeff in expr.data: + for _exp, coeff in expr.data: self.rec(coeff, *args, **kwargs) self.post_visit(expr, *args, **kwargs) @@ -710,7 +710,7 @@ class WalkMapper(RecursiveMapper): if not self.visit(expr, *args, **kwargs): return - for bits, coeff in expr.data.items(): + for _bits, coeff in expr.data.items(): self.rec(coeff) self.post_visit(expr, *args, **kwargs) diff --git a/pymbolic/mapper/c_code.py b/pymbolic/mapper/c_code.py index 1bef35d2048fcb366e7f20302a718203ace93b1f..aed3867b2bad933d0625d3575e7f230d65698c2d 100644 --- a/pymbolic/mapper/c_code.py +++ b/pymbolic/mapper/c_code.py @@ -63,7 +63,9 @@ class CCodeMapper(SimplifyingSortingStringifyMapper): def __init__(self, reverse=True, cse_prefix="_cse", complex_constant_base_type="double", - cse_name_list=[]): + cse_name_list=None): + if cse_name_list is None: + cse_name_list = [] super().__init__(reverse) self.cse_prefix = cse_prefix diff --git a/pymbolic/mapper/collector.py b/pymbolic/mapper/collector.py index 85cb3c69544d19bd1bc3660799d5bf092bc931d1..dd5fadade8fc278ee38845d5e9e34675ed17fcf7 100644 --- a/pymbolic/mapper/collector.py +++ b/pymbolic/mapper/collector.py @@ -32,7 +32,9 @@ class TermCollector(IdentityMapper): coefficients and are not used for term collection. """ - def __init__(self, parameters=set()): + def __init__(self, parameters=None): + if parameters is None: + parameters = set() self.parameters = parameters def get_dependencies(self, expr): diff --git a/pymbolic/mapper/distributor.py b/pymbolic/mapper/distributor.py index 77edd759924f0f2e7b336d489d573cc6e4606dbb..5ee2868e32e8a757ed1dc746caf10deb65dc1e27 100644 --- a/pymbolic/mapper/distributor.py +++ b/pymbolic/mapper/distributor.py @@ -120,7 +120,9 @@ class DistributeMapper(IdentityMapper): return IdentityMapper.map_power(self, expr) -def distribute(expr, parameters=set(), commutative=True): +def distribute(expr, parameters=None, commutative=True): + if parameters is None: + parameters = frozenset() if commutative: return DistributeMapper(TermCollector(parameters))(expr) else: diff --git a/pymbolic/mapper/evaluator.py b/pymbolic/mapper/evaluator.py index 889bc90b29021905bd719927405f76537809b5f2..5b1de8f54a168217cd1f69ebbc679551eab94ec3 100644 --- a/pymbolic/mapper/evaluator.py +++ b/pymbolic/mapper/evaluator.py @@ -47,10 +47,13 @@ class EvaluationMapper(RecursiveMapper, CSECachingMapperMixin): 110 """ - def __init__(self, context={}): + def __init__(self, context=None): """ :arg context: a mapping from variable names to values """ + if context is None: + context = {} + self.context = context self.common_subexp_cache = {} @@ -198,7 +201,9 @@ class FloatEvaluationMapper(EvaluationMapper): return self.rec(expr.numerator) / self.rec(expr.denominator) -def evaluate(expression, context={}): +def evaluate(expression, context=None): + if context is None: + context = {} return EvaluationMapper(context)(expression) @@ -206,5 +211,7 @@ def evaluate_kw(expression, **context): return EvaluationMapper(context)(expression) -def evaluate_to_float(expression, context={}): +def evaluate_to_float(expression, context=None): + if context is None: + context = {} return FloatEvaluationMapper(context)(expression) diff --git a/pymbolic/mapper/substitutor.py b/pymbolic/mapper/substitutor.py index 82e62f3f6c240eeede1eb4718781d57ff046ea48..c775dd178a0b3c01c756de133197493e1bc0acb5 100644 --- a/pymbolic/mapper/substitutor.py +++ b/pymbolic/mapper/substitutor.py @@ -67,7 +67,9 @@ def make_subst_func(variable_assignments): return subst_func -def substitute(expression, variable_assignments={}, **kwargs): +def substitute(expression, variable_assignments=None, **kwargs): + if variable_assignments is None: + variable_assignments = {} variable_assignments = variable_assignments.copy() variable_assignments.update(kwargs) diff --git a/pymbolic/mapper/unifier.py b/pymbolic/mapper/unifier.py index 3061a874a673f58afd8657007bc958e09c319400..577b6efb735d18afeaf375a2f01ce568a7f4b552 100644 --- a/pymbolic/mapper/unifier.py +++ b/pymbolic/mapper/unifier.py @@ -344,7 +344,7 @@ class UnidirectionalUnifier(UnifierBase): # Unify non-free-variable children of expr with children of the other # expr. - for i, my_child in enumerate(non_var_children): + for my_child in non_var_children: i_matches = [] for j, other_child in enumerate(other.children): result = self.rec(my_child, other_child, urecs) diff --git a/setup.cfg b/setup.cfg index 2089bdfcb78f4d1e7ff5ac3b9456fda4719670bc..1e8e488c97c1ecacf11005f0fb50c1b4ba091245 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,3 +6,5 @@ exclude=doc,pymbolic/polynomial.py inline-quotes = " docstring-quotes = """ multiline-quotes = """ + +# enable-flake8-bugbear diff --git a/test/test_pymbolic.py b/test/test_pymbolic.py index 2828fdfbfd6ba06ad5f8a136a604b25453c8b7b2..7908d6b09c56bc0b7507e3574e698af7985b0ce7 100644 --- a/test/test_pymbolic.py +++ b/test/test_pymbolic.py @@ -100,7 +100,7 @@ def test_no_comparison(): except TypeError: pass else: - assert False + raise AssertionError expect_typeerror(lambda: x < y) expect_typeerror(lambda: x <= y) @@ -597,7 +597,7 @@ def test_latex_mapper(): except OSError: # FIXME: Should be FileNotFoundError on Py3 pytest.skip("latex command not found") except subprocess.CalledProcessError as err: - assert False, str(err.output) + raise AssertionError(str(err.output)) finally: shutil.rmtree(latex_dir)