[Python-ideas] re.compile_lazy - on first use compiled regexes
masklinn at masklinn.net
Sat Mar 23 19:00:03 CET 2013
On 2013-03-23, at 16:33 , Antoine Pitrou wrote:
> 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")
Yes, I'm not even sure the argument is needed: functools.partial (or a
lambda) can be used for that and lazy_compute/compute_once would take a
function of arity 0 as parameter.
More information about the Python-ideas