From 818b2ed90a003feee9ee49edb224726df549ef81 Mon Sep 17 00:00:00 2001
From: Marcus Mohr <marcus.mohr@lmu.de>
Date: Wed, 26 Feb 2025 14:09:05 +0100
Subject: [PATCH] Workaround for issue 46 that also passes mypy

---
 hog/operator_generation/indexing.py | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/hog/operator_generation/indexing.py b/hog/operator_generation/indexing.py
index 1680e39..218a8fe 100644
--- a/hog/operator_generation/indexing.py
+++ b/hog/operator_generation/indexing.py
@@ -27,7 +27,7 @@ from hog.symbolizer import Symbolizer
 from pystencils.integer_functions import int_div
 from pystencils import TypedSymbol
 from enum import Enum
-from typing import Tuple, List, Union
+from typing import Tuple, List, Union, cast
 
 import operator
 import sympy as sp
@@ -259,19 +259,20 @@ def linear_macro_cell_index(width: int, x: int, y: int, z: int) -> int:
 
 def facedof_index(
     level: int,
-    index: Tuple[int, int, int],
+    # Hack: see issue #46 for details
+    index: Union[Tuple[int, int], Tuple[int, int, int]],
     faceType: Union[None, EdgeType, FaceType, CellType],
     num_microfaces_per_face: sp.Symbol,
     num_microedges_per_edge: sp.Symbol,
 ) -> int:
     """Indexes triangles/faces. Used to compute offsets in volume dof indexing in 2D and AoS layout."""
 
-    # Ugly hack; why do we receive an index with only two entries,
-    # and why do we expect one with three?
+    # second part of hack for #46
+    # also see https://github.com/python/mypy/issues/1178
     if len(index) == 3:
-        x, y, _ = index
-    elif len(index) == 2:
-        x, y = index
+        x, y, _ = cast(Tuple[int, int, int], index)
+    else:
+        x, y = cast(Tuple[int, int], index)
 
     # width = num_faces_per_row_by_type(level, faceType)
     if faceType == FaceType.GRAY:
-- 
GitLab