Skip to content

Commit 2e33b84

Browse files
committed
Add more type ignore to the FormulaEngine
The code already had a bunch of `type: ignore[type-arg]` because some generic types are missing the type argument. For some reason it seems like previous `mypy` versions didn't complain about this for all cases, but now it does. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 3d9e002 commit 2e33b84

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/frequenz/sdk/timeseries/formula_engine/_formula_engine.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,34 +54,36 @@
5454
}
5555
"""The dictionary of operator precedence for the shunting yard algorithm."""
5656

57+
58+
# The `FormulaEngine*` and `HigherOrderFormulaBuilder*` classes are generic, but
59+
# `TypeVar`s can't be defined on generic types, so we need to use `# type: ignore` to
60+
# avoid mypy errors, and they get treated as `FormulaEngine[Any]`, etc.
61+
#
62+
# This is not ideal, but it's the best we can do until mypy supports generic types with
63+
# `TypeVar`s.
5764
_CompositionType = Union[
58-
"FormulaEngine",
59-
"HigherOrderFormulaBuilder",
60-
"FormulaEngine3Phase",
61-
"HigherOrderFormulaBuilder3Phase",
65+
"FormulaEngine", # type: ignore[type-arg]
66+
"HigherOrderFormulaBuilder", # type: ignore[type-arg]
67+
"FormulaEngine3Phase", # type: ignore[type-arg]
68+
"HigherOrderFormulaBuilder3Phase", # type: ignore[type-arg]
6269
]
6370

6471
_CompositionType1Phase = Union[
65-
"FormulaEngine",
66-
"HigherOrderFormulaBuilder",
72+
"FormulaEngine", # type: ignore[type-arg]
73+
"HigherOrderFormulaBuilder", # type: ignore[type-arg]
6774
]
6875

6976
_CompositionType3Phase = Union[
70-
"FormulaEngine3Phase",
71-
"HigherOrderFormulaBuilder3Phase",
77+
"FormulaEngine3Phase", # type: ignore[type-arg]
78+
"HigherOrderFormulaBuilder3Phase", # type: ignore[type-arg]
7279
]
7380

74-
# The `FormulaEngine*` and `HigherOrderFormulaBuilder*` classes are generic, but
75-
# `TypeVar`s can't be defined on generic types, so we need to use `# type: ignore` to
76-
# avoid mypy errors, and they get treated as `FormulaEngine[Any]`, etc.
77-
#
78-
# This is not ideal, but it's the best we can do until mypy supports generic types with
79-
# `TypeVar`s.
8081
_GenericEngine = TypeVar(
8182
"_GenericEngine",
8283
"FormulaEngine", # type: ignore
8384
"FormulaEngine3Phase", # type: ignore
8485
)
86+
8587
_GenericHigherOrderBuilder = TypeVar(
8688
"_GenericHigherOrderBuilder",
8789
"HigherOrderFormulaBuilder", # type: ignore

0 commit comments

Comments
 (0)