[MERGE] init remote branches

Martin Pool mbp at canonical.com
Mon Jul 3 03:06:40 BST 2006


On  2 Jul 2006, Aaron Bentley <aaron.bentley at utoronto.ca> wrote:
> John Arbash Meinel wrote:
> > With our os-specific functions (like getcwd()) if we only import the
> > osutils module, then we can actually hijack the specific implementation
> > in the test suite, to make sure that the rest of the codebase does the
> > right thing.
> 
> I don't understand this.  It sounds like you're talking about directly
> invoking osutils.get_cwd, or os.get_cwd, and I agree that when you want
> to use both, it often makes sense to use the module name to distinguish
> functions.  But that doesn't sound like 'hijacking' to me, so I must be
> missing something.

I think John means:

alpha.py:
   from bzrlib import osutils

   def f():
     osutils.foo()


test_alpha.py:
   def some_test_function():
     osutils.foo = _fake_foo
     try:
       alpha.f()
     finally:
       ...

If alpha instead did "from bzrlib.osutils import foo" then it we
couldn't do this as easily/cleanly.

I used to prefer importing the individual names for reasons of terseness
too, but I'm starting to import submodules for new code, for these
reasons:

 - imports are smaller
 - allows us to at least try out demandload
 - means there's only one name bound to the thing - make hooking it 
   easier as john shows
 - and makes it safer to do this for variables

I'm not going to suggest we clean up everything already there but I
think it makes sense for new code.

I do think we should use just the relative name rather than
'bzrlib.transport', which just does get too long too fast.

The main risk is that it's easy to have parameters or local variables
called 'transport', 'bzrdir', etc.

-- 
Martin




More information about the bazaar mailing list