[merge] split out repository formats

John Arbash Meinel john at arbash-meinel.com
Wed Feb 7 17:37:55 GMT 2007


Martin Pool wrote:
> On  7 Feb 2007, Robert Collins <robertc at robertcollins.net> wrote:
>> On Tue, 2007-02-06 at 08:46 -0600, John Arbash Meinel wrote:
>>> By the way, moving classes like this is pretty hard on backwards
>>> compatibility. Or at least you can import it back into the original
>>> module, but if the goal is to not load unused code, you lose that
>>> benefit. I suppose you could do it temporarily and then in the next
>>> release you can remove the local import. 
>> Isn't lazy loader an answer for that ?
> 
> I'm not sure - will it work to have a lazy loader that imports from a
> module that itself imports bzrlib.repository?
> 

The problem is that you would be lazy loading a class, and callers are
probably doing

from bzrlib.repository import Repository5

or something that would cause a new name to be bound.

So it might work if we turned our lazy objects into proxies.

If callers were doing

bzrlib.repository.Repository5

that could probably work.

Though if they are doing:

isinstance(foo, bzrlib.repository.Repository5)

then you have a bit of hit and miss, it works if the import of
Repository5 has been triggered.

But even with proxying

isinstance(foo, Repository5) won't work.


Further, we really want to give deprecation warnings if people are
accessing it directly. So a proxy function like

def Repository5(*args, **kwargs):
  symbol_versioning.warn('bzrlib.repository.Repository5 has been'
			 ' moved to'
			 ' bzrlib.repository.repofmt.weave.Repository5')
  from bzrlib.repository.repofmt.weave import Repository5
  return Repository5(*args, **kwargs)


that still fails the 'isinstance()' calls, but it fails early with
TypeError: isinstance() arg 2 must be a class, type, or tuple of classes
and types

So it should be fairly easy for callers to update their code.

Now if modules could have a __getattr__ function, we could do the lazy
loading and warning when the member is accessed. But I don't think that
is ever going to happen.

John
=:->




More information about the bazaar mailing list