prime_list
prime_list(n, base_primes=None, piter=None):
LLM Docstring
Return the first n primes, using a shared incremental cache by default.
Three cases, chosen by what’s supplied:
piter=None,base_primes=None(the default call): both are pulled from the module-leveldefault_prime_iter/default_base_prime_list, a cache that’s intentionally persistent across calls.piter=None,base_primes=<a list>: a fresh iterator is built from that list withprime_iter(base_primes), instead of pulling from the unrelated global cache. Previously, supplying a custombase_primeswithout also supplying a matchingpitersilently ignored the supplied list’s content – the shared global generator’s cache won regardless, so the “custom starting list” argument didn’t do what it looked like it did.piter=<an iterator>: used as given;base_primesdefaults to a new empty list if not also supplied (so it isn’t tied to the global cache unless the caller asks for that explicitly).
In every case base_primes is still extended in place and returned;
supplying your own list lets you keep your own independent cache instead
of sharing the module-level one.
n:intnumber of primes requested
base_primes:list[int] | Nonemutable cache populated in place;
Noneselects the shared default cache (or, ifpiteris supplied, a fresh empty list)piter:collections.abc.Iterator[list[int]] | Nonecumulative prime-list iterator used to extend the cache;
Noneselects the shared default iterator, unlessbase_primeswas supplied, in which case a fresh iterator seeded from it is used:returns:list[int]the first
ncached primes