From 4984e405d0d40385efaf17b8b4b2275a546c477d Mon Sep 17 00:00:00 2001 From: mhostetter Date: Thu, 30 Nov 2023 19:52:09 -0500 Subject: [PATCH] Prevent unbound return value --- src/galois/_prime.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/galois/_prime.py b/src/galois/_prime.py index c6647361a..6c007115b 100644 --- a/src/galois/_prime.py +++ b/src/galois/_prime.py @@ -172,20 +172,16 @@ def prev_prime(n: int) -> int: shifts = [29, 23, 19, 17, 13, 11, 7, 1] # Factorization wheel for basis {2, 3, 5} base = n // 30 * 30 # Wheel factorization starting point - found = False # Success flag - while not found: + while True: for shift in shifts: i = base + shift # May be bigger than n if i >= n: continue if is_prime(i): - found = True - break + return i base -= 30 - return i - @export def next_prime(n: int) -> int: @@ -219,20 +215,16 @@ def next_prime(n: int) -> int: shifts = [1, 7, 11, 13, 17, 19, 23, 29] # Factorization wheel for basis {2, 3, 5} base = n // 30 * 30 # Wheel factorization starting point. May be less than n. - found = False # Success flag - while not found: + while True: for shift in shifts: i = base + shift if i <= n: continue if is_prime(i): - found = True - break + return i base += 30 - return i - @export def random_prime(bits: int, seed: int | None = None) -> int: