Skip to content

Commit 42e2286

Browse files
committed
Improve typing for HigherOrderFormulaBuilder by adding overloads
Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 658d1e8 commit 42e2286

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,18 @@ def __init__(self, engine: FormulaEngine | FormulaEngine3Phase) -> None:
547547
] = deque()
548548
self._steps.append((TokenType.COMPONENT_METRIC, engine))
549549

550+
@overload
551+
def _push(
552+
self, oper: str, other: _CompositionType1Phase
553+
) -> HigherOrderFormulaBuilder:
554+
...
555+
556+
@overload
557+
def _push(
558+
self, oper: str, other: _CompositionType3Phase
559+
) -> HigherOrderFormulaBuilder3Phase:
560+
...
561+
550562
def _push(
551563
self, oper: str, other: _CompositionType
552564
) -> HigherOrderFormulaBuilder | HigherOrderFormulaBuilder3Phase:
@@ -569,6 +581,14 @@ def _push(
569581
)
570582
return self
571583

584+
@overload
585+
def __add__(self, other: _CompositionType1Phase) -> HigherOrderFormulaBuilder:
586+
...
587+
588+
@overload
589+
def __add__(self, other: _CompositionType3Phase) -> HigherOrderFormulaBuilder3Phase:
590+
...
591+
572592
def __add__(
573593
self, other: _CompositionType
574594
) -> HigherOrderFormulaBuilder | HigherOrderFormulaBuilder3Phase:
@@ -584,6 +604,14 @@ def __add__(
584604
"""
585605
return self._push("+", other)
586606

607+
@overload
608+
def __sub__(self, other: _CompositionType1Phase) -> HigherOrderFormulaBuilder:
609+
...
610+
611+
@overload
612+
def __sub__(self, other: _CompositionType3Phase) -> HigherOrderFormulaBuilder3Phase:
613+
...
614+
587615
def __sub__(
588616
self,
589617
other: _CompositionType,
@@ -600,6 +628,14 @@ def __sub__(
600628
"""
601629
return self._push("-", other)
602630

631+
@overload
632+
def __mul__(self, other: _CompositionType1Phase) -> HigherOrderFormulaBuilder:
633+
...
634+
635+
@overload
636+
def __mul__(self, other: _CompositionType3Phase) -> HigherOrderFormulaBuilder3Phase:
637+
...
638+
603639
def __mul__(
604640
self,
605641
other: _CompositionType,
@@ -616,6 +652,16 @@ def __mul__(
616652
"""
617653
return self._push("*", other)
618654

655+
@overload
656+
def __truediv__(self, other: _CompositionType1Phase) -> HigherOrderFormulaBuilder:
657+
...
658+
659+
@overload
660+
def __truediv__(
661+
self, other: _CompositionType3Phase
662+
) -> HigherOrderFormulaBuilder3Phase:
663+
...
664+
619665
def __truediv__(
620666
self,
621667
other: _CompositionType,

0 commit comments

Comments
 (0)