I have a class that represents a normalized amount of memory.
class MemoryUnit(enum.Enum):
"""Units of memory."""
GB = 'GB'
TB = 'TB'
PB = 'PB'
class Memory(BaseModel):
"""Normalized amount of memory."""
amount: int
unit: MemoryUnit
Now I want to implement basic arithmetics for this class. Addition, substraction and multiplication are easy to annotate:
def __add__(self, other: Memory) -> Memory: ...
def __sub__(self, other: Memory) -> Memory: ...
def __mul__(self, other: int) -> Memory: ...
I have a problem with division though. I see two use-cases for division:
- divide
MemorybyMemoryand get afloat(what is the ratio between two amounts of storage). - divide
Memorybyintand getMemory(what is the amount ofMemoryif divided evenly amongn)
Is there a way in mypy to annotate a function with this specific signature?