From 85a96b8f0efa577e4844901416ed0ba924f8084b Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Wed, 11 Mar 2026 12:07:35 +0100 Subject: [PATCH] Allow Size/Size division to calculate ratio The result is a float number (unitless). Signed-off-by: Robert Baldyga --- type_def/size.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/type_def/size.py b/type_def/size.py index b262a16..af8b0ed 100644 --- a/type_def/size.py +++ b/type_def/size.py @@ -5,6 +5,8 @@ # SPDX-License-Identifier: BSD-3-Clause # +from __future__ import annotations + import enum import math import random @@ -181,7 +183,10 @@ def __rmul__(self, other: float | int): return Size(math.ceil(self.get_value() * other)) @multimethod - def __truediv__(self, other: float | int): + def __truediv__(self, other: float | int | Size): + if isinstance(other, Size): + other = other.get_value() + return math.ceil(self.get_value() / other) if other == 0: raise ValueError("Divisor must not be equal to 0.") return Size(math.ceil(self.get_value() / other))