[MERGE] (0.17) reworked LogFormatter API

John Arbash Meinel john at arbash-meinel.com
Thu May 24 13:28:31 BST 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Kent Gibson wrote:
> Hi John,
> 
> Can you point out where in PEP-8 is specifies that there must be space
> in the cases you highlight?  The only section I can find relates to
> not adding extraneous space.
> 
> Not that I have a problem with it if it is the bzr way, just I don't
> see it in PEP-8.

Read the Whitespace in Expressions and Statements section thoroughly.

It starts with:
      Yes: spam(ham[1], {eggs: 2})
      No:  spam( ham[ 1 ], { eggs: 2 } )

and
      Yes: if x == 4: print x, y; x, y = y, x
      No:  if x == 4 : print x , y ; x , y = y , x

and
      Yes:

          x = 1
          y = 2
          long_variable = 3

      No:

          x             = 1
          y             = 2
          long_variable = 3

and eventually gets to:
      Yes:

          def complex(real, imag=0.0):
              return magic(r=real, i=imag)

      No:

          def complex(real, imag = 0.0):
              return magic(r = real, i = imag)

> 
> 
>> -    if show_merge is not None and show_merge_revno is None:
>> +    legacy_lf = not getattr(lf, 'log_revision', None)
> 
>> I would also probably do this as:
> 
>> legacy_lf = getattr(...) is not None
> 
> I hope you mean:
> 
> legacy_lf = getattr() is None
> 
> And I prefer my way anyway - I think it reads better.

Well, you really are checking against None, not just a parameter which
evaluates to false.

What we really want is 'hasattr()' but unfortunately hasattr() supresses
too many exceptions.

Normally I actually use the result directly. So I do:
log_revision = getattr(lf, 'log_revision', None)
if log_revision is None: # legacy
 ...

else:
   log_revision(foo)


> 
> Cheers,
> Kent.
> 

I personally don't find "not getattr()" to be especially readable. 'not
hasattr()' is more obvious, but we avoid that for other reasons.

Anyway, I've sent this to PQM, though you are welcome to submit a patch
for review if you don't like how I've done some of it.

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGVYTvJdeBCYSNAAMRAiBnAKCFsQ7A8xQjHyfp5cvOjEKOsl03OQCdHOE0
gYOYi0BzaYTMa0iYglViG7o=
=Ql+5
-----END PGP SIGNATURE-----



More information about the bazaar mailing list