[Python-ideas] re.compile_lazy - on first use compiled regexes

Antoine Pitrou solipsis at pitrou.net
Sat Mar 23 16:33:49 CET 2013

On Sat, 23 Mar 2013 16:30:39 +0100
Masklinn <masklinn at masklinn.net> wrote:
> Right, but in this case while I called it a cache the semantics really
> is a lazy singleton: only create the regex object when it's needed, but
> keep it around once it's been created.

Perhaps we need a functools.lazy_compute() function:

  pat = functools.lazy_compute(re.compile, r"my very long regex")



More information about the Python-ideas mailing list