[merge] lazy regex

Martin Pool mbp at canonical.com
Tue Oct 10 10:04:57 BST 2006


On 10 Oct 2006, Andrew Bennetts <andrew at canonical.com> wrote:

> Sorry if I sounded a bit glib.  But seriously, how is it possible for that
> assertion (or warning) to ever trigger?  You mean for this code to be part of
> the global code executed at import time, AFAICT.  Even if you imported the
> module, then called install_lazy_compile(), then reload(lazy_regex), it still
> wouldn't trigger, because the lazy_compile in the reloaded module would not be
> the same object as the previous one.  
> 
> I'm not sure what you're trying to guard against, but whatever it is I don't
> think asserting/warning _real_re_compile is not lazy_compile would help you do
> it.  

I was thinking of something like reload, but you're quite right that
"is" won't catch that.  I guess we would need to have an attribute on
the installed function that we can probe for to see if it's "like" our
code, but at that point it's getting more complicated than the risk will
justify.

> I can see the value in "assert re.compile is not lazy_compile" in
> install_lazy_compile to catch an attempt to doubly-install the the
> lazy_regex code.  Perhaps that's what you meant?

No, I don't really mind it being idempotent to install it.  It was more
the thought of inadvertently having wrappers-around-wrappers.

-- 
Martin




More information about the bazaar mailing list