@@ -221,6 +221,22 @@ def __sub__(self, other: Self) -> Self:
221221 difference ._base_value = self ._base_value - other ._base_value
222222 return difference
223223
224+ def __mul__ (self , percent : Percentage ) -> Self :
225+ """Return the product of this quantity and a percentage.
226+
227+ Args:
228+ percent: The percentage.
229+
230+ Returns:
231+ The product of this quantity and a percentage.
232+ """
233+ if not isinstance (percent , Percentage ):
234+ return NotImplemented
235+
236+ product = type (self ).__new__ (type (self ))
237+ product ._base_value = self ._base_value * percent .as_fraction ()
238+ return product
239+
224240 def __gt__ (self , other : Self ) -> bool :
225241 """Return whether this quantity is greater than another.
226242
@@ -423,18 +439,42 @@ def as_megawatts(self) -> float:
423439 """
424440 return self ._base_value / 1e6
425441
426- def __mul__ (self , duration : timedelta ) -> Energy :
442+ @overload # type: ignore
443+ def __mul__ (self , other : Percentage ) -> Self :
444+ """Return a power from multiplying this power by the given percentage.
445+
446+ Args:
447+ other: The percentage to multiply by.
448+ """
449+
450+ @overload
451+ def __mul__ (self , other : timedelta ) -> Energy :
427452 """Return an energy from multiplying this power by the given duration.
428453
429454 Args:
430- duration: The duration to multiply by.
455+ other: The duration to multiply by.
456+ """
457+
458+ def __mul__ (self , other : Percentage | timedelta ) -> Self | Energy :
459+ """Return a power or energy from multiplying this power by the given value.
460+
461+ Args:
462+ other: The percentage or duration to multiply by.
431463
432464 Returns:
433- An energy from multiplying this power by the given duration.
465+ A power or energy.
466+
467+ Raises:
468+ TypeError: If the given value is not a percentage or duration.
434469 """
435- return Energy .from_watt_hours (
436- self ._base_value * duration .total_seconds () / 3600.0
437- )
470+ if isinstance (other , Percentage ):
471+ return super ().__mul__ (other )
472+ if isinstance (other , timedelta ):
473+ return Energy .from_watt_hours (
474+ self ._base_value * other .total_seconds () / 3600.0
475+ )
476+
477+ return NotImplemented
438478
439479 @overload
440480 def __truediv__ (self , other : Current ) -> Voltage :
@@ -527,16 +567,40 @@ def as_milliamperes(self) -> float:
527567 """
528568 return self ._base_value * 1e3
529569
530- def __mul__ (self , voltage : Voltage ) -> Power :
570+ @overload # type: ignore
571+ def __mul__ (self , other : Percentage ) -> Self :
572+ """Return a power from multiplying this power by the given percentage.
573+
574+ Args:
575+ other: The percentage to multiply by.
576+ """
577+
578+ @overload
579+ def __mul__ (self , other : Voltage ) -> Power :
531580 """Multiply the current by a voltage to get a power.
532581
533582 Args:
534- voltage: The voltage.
583+ other: The voltage.
584+ """
585+
586+ def __mul__ (self , other : Percentage | Voltage ) -> Self | Power :
587+ """Return a current or power from multiplying this current by the given value.
588+
589+ Args:
590+ other: The percentage or voltage to multiply by.
535591
536592 Returns:
537- The power.
593+ A current or power.
594+
595+ Raises:
596+ TypeError: If the given value is not a percentage or voltage.
538597 """
539- return Power .from_watts (self ._base_value * voltage ._base_value )
598+ if isinstance (other , Percentage ):
599+ return super ().__mul__ (other )
600+ if isinstance (other , Voltage ):
601+ return Power .from_watts (self ._base_value * other ._base_value )
602+
603+ return NotImplemented
540604
541605
542606class Voltage (
@@ -612,16 +676,40 @@ def as_kilovolts(self) -> float:
612676 """
613677 return self ._base_value / 1e3
614678
615- def __mul__ (self , current : Current ) -> Power :
679+ @overload # type: ignore
680+ def __mul__ (self , other : Percentage ) -> Self :
681+ """Return a power from multiplying this power by the given percentage.
682+
683+ Args:
684+ other: The percentage to multiply by.
685+ """
686+
687+ @overload
688+ def __mul__ (self , other : Current ) -> Power :
616689 """Multiply the voltage by the current to get the power.
617690
618691 Args:
619- current: The current to multiply the voltage with.
692+ other: The current to multiply the voltage with.
693+ """
694+
695+ def __mul__ (self , other : Percentage | Current ) -> Self | Power :
696+ """Return a voltage or power from multiplying this voltage by the given value.
697+
698+ Args:
699+ other: The percentage or current to multiply by.
620700
621701 Returns:
622- The calculated power.
702+ The calculated voltage or power.
703+
704+ Raises:
705+ TypeError: If the given value is not a percentage or current.
623706 """
624- return Power .from_watts (self ._base_value * current ._base_value )
707+ if isinstance (other , Percentage ):
708+ return super ().__mul__ (other )
709+ if isinstance (other , Current ):
710+ return Power .from_watts (self ._base_value * other ._base_value )
711+
712+ return NotImplemented
625713
626714
627715class Energy (
0 commit comments