From 911d9024cc20f2701be9a761180da246d56bd2a4 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sun, 2 Jan 2022 16:20:11 +0000 Subject: [PATCH] geometry refinements --- src/textual/geometry.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/textual/geometry.py b/src/textual/geometry.py index beb926959..b9fcb2f52 100644 --- a/src/textual/geometry.py +++ b/src/textual/geometry.py @@ -119,15 +119,19 @@ class Size(NamedTuple): width, height = self return Region(0, 0, width, height) - def __add__(self, other: tuple[int, int]) -> Size: - width, height = self - width2, height2 = other - return Size(width + width2, height + height2) + def __add__(self, other: object) -> Size: + if isinstance(other, tuple): + width, height = self + width2, height2 = other + return Size(width + width2, height + height2) + return NotImplemented - def __sub__(self, other: tuple[int, int]) -> Size: - width, height = self - width2, height2 = other - return Size(width - width2, height - height2) + def __sub__(self, other: object) -> Size: + if isinstance(other, tuple): + width, height = self + width2, height2 = other + return Size(width - width2, height - height2) + return NotImplemented def contains(self, x: int, y: int) -> bool: """Check if a point is in the size. @@ -274,14 +278,14 @@ class Region(NamedTuple): """A range object for Y coordinates""" return range(self.y, self.y + self.height) - def __add__(self, other: Any) -> Region: + def __add__(self, other: object) -> Region: if isinstance(other, tuple): ox, oy = other x, y, width, height = self return Region(x + ox, y + oy, width, height) return NotImplemented - def __sub__(self, other: Any) -> Region: + def __sub__(self, other: object) -> Region: if isinstance(other, tuple): ox, oy = other x, y, width, height = self