From 339383adcf9028f0471cf44daf3aa2efc256b49b Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 30 Jul 2024 19:41:27 +0300 Subject: [PATCH 1/5] raise an OverflowError like micropython for too big a value --- adafruit_ticks.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/adafruit_ticks.py b/adafruit_ticks.py index 5585d2b..01259a6 100644 --- a/adafruit_ticks.py +++ b/adafruit_ticks.py @@ -122,6 +122,8 @@ def ticks_ms() -> int: def ticks_add(ticks: int, delta: int) -> int: "Add a delta to a base number of ticks, performing wraparound at 2**29ms." + if delta <= -_TICKS_PERIOD/2 or delta >= _TICKS_PERIOD/2: + raise OverflowError("ticks interval overflow") return (ticks + delta) % _TICKS_PERIOD From 5946e8366a9a64e392974bfb606dc6037348370b Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Mon, 5 Aug 2024 18:13:42 +0300 Subject: [PATCH 2/5] run black --- adafruit_ticks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_ticks.py b/adafruit_ticks.py index 01259a6..b8d46d9 100644 --- a/adafruit_ticks.py +++ b/adafruit_ticks.py @@ -122,7 +122,7 @@ def ticks_ms() -> int: def ticks_add(ticks: int, delta: int) -> int: "Add a delta to a base number of ticks, performing wraparound at 2**29ms." - if delta <= -_TICKS_PERIOD/2 or delta >= _TICKS_PERIOD/2: + if delta <= -_TICKS_PERIOD / 2 or delta >= _TICKS_PERIOD / 2: raise OverflowError("ticks interval overflow") return (ticks + delta) % _TICKS_PERIOD From 97d6a3eb1d0a6916c7d4aaa0d074ade39e43cdfd Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Fri, 9 Aug 2024 20:13:03 +0300 Subject: [PATCH 3/5] Update adafruit_ticks.py Co-authored-by: Dan Halbert --- adafruit_ticks.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adafruit_ticks.py b/adafruit_ticks.py index b8d46d9..835853a 100644 --- a/adafruit_ticks.py +++ b/adafruit_ticks.py @@ -122,9 +122,9 @@ def ticks_ms() -> int: def ticks_add(ticks: int, delta: int) -> int: "Add a delta to a base number of ticks, performing wraparound at 2**29ms." - if delta <= -_TICKS_PERIOD / 2 or delta >= _TICKS_PERIOD / 2: - raise OverflowError("ticks interval overflow") - return (ticks + delta) % _TICKS_PERIOD + if -_TICKS_HALFPERIOD < delta < _TICKS_HALFPERIOD: + return (ticks + delta) % _TICKS_PERIOD + raise OverflowError("ticks interval overflow") def ticks_diff(ticks1: int, ticks2: int) -> int: From b8a4e11f101efeb00f3c33d4cd89e4ba0e7e3f56 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Fri, 9 Aug 2024 20:14:58 +0300 Subject: [PATCH 4/5] fix indentation --- adafruit_ticks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_ticks.py b/adafruit_ticks.py index 835853a..2fa517b 100644 --- a/adafruit_ticks.py +++ b/adafruit_ticks.py @@ -124,7 +124,7 @@ def ticks_add(ticks: int, delta: int) -> int: "Add a delta to a base number of ticks, performing wraparound at 2**29ms." if -_TICKS_HALFPERIOD < delta < _TICKS_HALFPERIOD: return (ticks + delta) % _TICKS_PERIOD - raise OverflowError("ticks interval overflow") + raise OverflowError("ticks interval overflow") def ticks_diff(ticks1: int, ticks2: int) -> int: From 892cca38f78ed30d863390b6f592c6c1b7171aba Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 9 Aug 2024 17:02:14 -0400 Subject: [PATCH 5/5] fix formatting --- adafruit_ticks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_ticks.py b/adafruit_ticks.py index 2fa517b..3efb0ad 100644 --- a/adafruit_ticks.py +++ b/adafruit_ticks.py @@ -122,7 +122,7 @@ def ticks_ms() -> int: def ticks_add(ticks: int, delta: int) -> int: "Add a delta to a base number of ticks, performing wraparound at 2**29ms." - if -_TICKS_HALFPERIOD < delta < _TICKS_HALFPERIOD: + if -_TICKS_HALFPERIOD < delta < _TICKS_HALFPERIOD: return (ticks + delta) % _TICKS_PERIOD raise OverflowError("ticks interval overflow")