Skip to content

Commit

Permalink
Fix argument-formatter. (#288)
Browse files Browse the repository at this point in the history
* Check that we never get to _afmt on CI

* Add failing test

* Fix string formatter

* Fix formatting
  • Loading branch information
jorgensd authored May 29, 2024
1 parent c73b28f commit ea144b0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
16 changes: 16 additions & 0 deletions test/test_check_arities.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,19 @@ def test_complex_arities():

with pytest.raises(ArityMismatch):
compute_form_data(inner(conj(v), u) * dx, complex_mode=True)


def test_product_arity():
cell = tetrahedron
D = Mesh(FiniteElement("Lagrange", cell, 1, (3,), identity_pullback, H1))
V = FunctionSpace(D, FiniteElement("Lagrange", cell, 2, (3,), identity_pullback, H1))
v = TestFunction(V)
u = TrialFunction(V)

with pytest.raises(ArityMismatch):
F = inner(u, u) * dx
compute_form_data(F, complex_mode=True)

with pytest.raises(ArityMismatch):
L = inner(v, v) * dx
compute_form_data(L, complex_mode=False)
6 changes: 4 additions & 2 deletions ufl/algorithms/check_arities.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Check arities."""

from itertools import chain
from typing import Tuple

from ufl.classes import Argument, Zero
from ufl.corealg.map_dag import map_expr_dag
Expand All @@ -14,9 +15,10 @@ class ArityMismatch(BaseException):
pass


def _afmt(atuple):
def _afmt(atuple: Tuple[Argument, bool]) -> str:
"""Return a string representation of an arity tuple."""
return tuple(f"conj({arg})" if conj else str(arg) for arg, conj in atuple)
arg, conj = atuple
return f"conj({arg})" if conj else str(arg)


class ArityChecker(MultiFunction):
Expand Down

0 comments on commit ea144b0

Please sign in to comment.