[merge] lazy regex
Andrew Bennetts
andrew at canonical.com
Tue Oct 10 09:53:08 BST 2006
Martin Pool wrote:
> On 10 Oct 2006, Andrew Bennetts <andrew at canonical.com> wrote:
> > Martin Pool wrote:
> > > On 9 Oct 2006, John Arbash Meinel <john at arbash-meinel.com> wrote:
> > [...]
> > > > +
> > > > +_real_re_compile = re.compile
> > >
> > > I'm not sure if it's justified, but I feel I'd like an
> > >
> > > assert _real_re_compile is not lazy_compile
> >
> > Given that this assignment happens before lazy_compile is defined, I'd say it
> > isn't justified ;)
>
> Sheesh, obviously this is a suggestion, not a patch.
>
> if re.compile is lazy_compile:
> import warnings
> warnings.warn("lazy_compile is already installed")
> _real_re_compile = re.compile
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 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?
-Andrew.
More information about the bazaar
mailing list