← Back to team overview

launchpad-dev team mailing list archive

Re: Give your models some repr love!

 

On 12 February 2010 04:07, Jonathan Lange <jml@xxxxxxxxxxxxx> wrote:
>> 1. The default repr is unique. Should we try and preserve that?
>
> As a rule of thumb, I try to have repr(a) == repr(b) <==> (a == b),
> rather than (a is b). I don't know if that's standard or helps.

My rule of thumb is that the repr should be useful in debugging.  If
you are likely to see stacktraces and need to know if the objects are
the same then make the repr show that.  If they have many minor fields
but also one well-defined identity (like a Repository(url)) then the
most useful thing is to show just the most important part.

>> 2. Is there a style guide for repr?
>
> I don't know. Reckon we need one?

We have http://doc.bazaar.canonical.com/bzr.dev/developers/HACKING.html#object-string-representations
if you want to borrow it.

-- 
Martin <http://launchpad.net/~mbp/>



Follow ups

References