From 7be7c2c90838de7d8169007af29b363dd436ab14 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Mon, 18 Jan 2021 00:54:30 -0800 Subject: [PATCH] Improve clarity of limiter_or_none logic. --- voussoirkit/spinal.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/voussoirkit/spinal.py b/voussoirkit/spinal.py index d9f0ed3..cb0b5b8 100644 --- a/voussoirkit/spinal.py +++ b/voussoirkit/spinal.py @@ -569,14 +569,19 @@ def is_xor(*args): return [bool(a) for a in args].count(True) == 1 def limiter_or_none(value): + if isinstance(value, ratelimiter.Ratelimiter): + return value + + if value is None: + return None + if isinstance(value, str): value = bytestring.parsebytes(value) - if isinstance(value, ratelimiter.Ratelimiter): - limiter = value - elif value is not None: - limiter = ratelimiter.Ratelimiter(allowance=value, period=1) - else: - limiter = None + + if not isinstance(value, (int, float)): + raise TypeError(type(value)) + + limiter = ratelimiter.Ratelimiter(allowance=value, period=1) return limiter def new_root(filepath, root):