Skip to content

Commit 2efc146

Browse files
committed
Activate 'warn_return_any' mypy check
1 parent 8a84e13 commit 2efc146

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

ffcx/codegeneration/C/c_implementation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def format_section(self, section) -> str:
207207
body += "// ------------------------ \n"
208208
return comments + declarations + body
209209

210-
def format_comment(self, c) -> str:
210+
def format_comment(self, c: L.Comment) -> str:
211211
"""Format a comment."""
212212
return "// " + c.comment + "\n"
213213

ffcx/codegeneration/lnodes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ def __repr__(self):
912912
class Comment(Statement):
913913
"""Line comment(s) used for annotating the generated code with human readable remarks."""
914914

915-
def __init__(self, comment):
915+
def __init__(self, comment: str):
916916
"""Initialise."""
917917
assert isinstance(comment, str)
918918
self.comment = comment

ffcx/ir/representation.py

+38-1
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,46 @@
4040

4141
def basix_cell_from_string(string: str) -> basix.CellType:
4242
"""Convert a string to a Basix CellType."""
43+
# Note: vertex -> point, rest identity
4344
if string == "vertex":
4445
return basix.CellType.point
45-
return getattr(basix.CellType, string)
46+
elif string == "interval":
47+
return basix.CellType.interval
48+
elif string == "triangle":
49+
return basix.CellType.triangle
50+
elif string == "tetrahedron":
51+
return basix.CellType.tetrahedron
52+
elif string == "quadrilateral":
53+
return basix.CellType.quadrilateral
54+
elif string == "hexahedron":
55+
return basix.CellType.hexahedron
56+
elif string == "prism":
57+
return basix.CellType.prism
58+
elif string == "pyramid":
59+
return basix.CellType.pyramid
60+
else:
61+
raise KeyError(f"Can not map '{string}' to a basix type.")
62+
63+
# TODO: Replace on 31 Oct 2025 with (Python 3.9 does not support match):
64+
# match string:
65+
# case "vertex":
66+
# return basix.CellType.point
67+
# case "interval":
68+
# return basix.CellType.interval
69+
# case "triangle":
70+
# return basix.CellType.triangle
71+
# case "tetrahedron":
72+
# return basix.CellType.tetrahedron
73+
# case "quadrilateral":
74+
# return basix.CellType.quadrilateral
75+
# case "hexahedron":
76+
# return basix.CellType.hexahedron
77+
# case "prism":
78+
# return basix.CellType.prism
79+
# case "pyramid":
80+
# return basix.CellType.pyramid
81+
# case _:
82+
# raise KeyError(f"Can not map '{string}' to a basix type.")
4683

4784

4885
class FormIR(typing.NamedTuple):

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ disallow_untyped_defs = false
6969
disallow_any_unimported = false
7070
no_implicit_optional = false
7171
check_untyped_defs = false
72-
warn_return_any = false
72+
warn_return_any = true
7373
warn_unused_ignores = true
7474
show_error_codes = true
7575

0 commit comments

Comments
 (0)