[Python-ideas] More helpers in reprlib (was Re: doctest)
steve at pearwood.info
Wed Feb 29 00:49:32 CET 2012
Nick Coghlan wrote:
> On Wed, Feb 29, 2012 at 8:19 AM, Barry Warsaw <barry at python.org> wrote:
>> On Feb 27, 2012, at 05:44 PM, Ian Bicking wrote:
>>> Doctest needs reliable repr's more than reversable repr's, and you can create
>>> them using that. You'll still get a lot of <foobar.Foobar object at
>>> 0x391a9df> strings, which suck... but if you are committed to doctest then
>>> maybe better to provide good __repr__ methods on your custom objects!
>> +1 even if you don't use doctests! I can't tell you how many times adding a
>> useful repr has vastly improved debugging. I urge everyone to flesh out your
>> reprs with a little bit of useful information so you can quickly identify your
>> instances at a pdb prompt.
> Since this question came up recently, what do you think of adding some
> more helpers to reprlib to make this even easier to do?
Your question is too general. Of course people should be in favour of helpers
to simplify making good reprs, but that's like asking if people are in favour
of solving world hunger. Who wouldn't be? But the answer should depend on what
the helpers do, how well they do them, and whether or not they actually help.
I fear getting carried away with enthusiasm for repr helpers and dumping a lot
of unnecessary, trivial or sub-optimal helpers in reprlib, where they will be
enshrined as "the one obvious way to do it" when perhaps they shouldn't be.
Since you are the author of them, I'm sure that they scratch your itches, but
will they scratch other people's?
I suggest publishing them as recipes on ActiveState first, and see what
feedback you get.
More information about the Python-ideas