Skip to content

Commit

Permalink
implemented multy annotations for one argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Bombardier256 committed Jan 5, 2024
1 parent 0c4d210 commit 2a59414
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


class Distance:
def __init__(self, km: float) -> None:
def __init__(self, km: float | int) -> None:
self.km = km

def __str__(self) -> str:
Expand All @@ -12,45 +12,54 @@ def __str__(self) -> str:
def __repr__(self) -> str:
return f"Distance(km={self.km})"

def __add__(self, other: float) -> Distance:
def __add__(self, other: Distance | float | int) -> Distance:
if isinstance(other, Distance):
return Distance(
km=self.km + other.km
)
else:
return Distance(
return Distance(
km=self.km + other
)
)

def __iadd__(self, other: Distance) -> Distance:
def __iadd__(self, other: Distance | int | float) -> Distance:
if isinstance(other, Distance):
self.km += other.km
else:
self.km += other

return self

def __mul__(self, other: float) -> Distance:
def __mul__(self, other: float | int) -> Distance:
return Distance(
km=self.km * other
)

def __truediv__(self, other: float) -> Distance:
def __truediv__(self, other: float | int) -> Distance:
return Distance(
km=round(self.km / other, 2)
)

def __lt__(self, other: float) -> bool:
def __lt__(self, other: Distance | float | int) -> bool:
if isinstance(other, Distance):
return self.km < other.km
return self.km < other

def __gt__(self, other: float) -> bool:
def __gt__(self, other: Distance | float | int) -> bool:
if isinstance(other, Distance):
return self.km > other.km
return self.km > other

def __eq__(self, other: float) -> bool:
def __eq__(self, other: Distance | float | int) -> bool:
if isinstance(other, Distance):
return self.km == other.km
return self.km == other

def __le__(self, other: float) -> bool:
def __le__(self, other: Distance | float | int) -> bool:
if isinstance(other, Distance):
return self.km <= other.km
return self.km <= other

def __ge__(self, other: float) -> bool:
def __ge__(self, other: Distance | float | int) -> bool:
if isinstance(other, Distance):
return self.km >= other.km
return self.km >= other

0 comments on commit 2a59414

Please sign in to comment.