Skip to content

Commit a9d9b69

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

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-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

+39-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import itertools
2222
import logging
23+
import sys
2324
import typing
2425
import warnings
2526

@@ -40,9 +41,46 @@
4041

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

4785

4886
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)