[TIP] dicts in doctests
fdrake at gmail.com
Fri Sep 19 10:40:45 PDT 2008
On Fri, Sep 19, 2008 at 1:22 PM, Florian Friesdorf <flo at chaoflow.net> wrote:
> Couldn't the output of a dict's __repr__() be made stable? Where is __repr__
> used, except for printing purpose. It feels like the overhead of making the
> output of __repr__ stable, would not affect too much.
repr is very much about printing, but it's not clear that everyone
wants or needs to have ordering promises. For very simple data
structures (using a limited set of types), repr is a perfectly
reasonable serialization format. In this case, you generally don't
want to spend the cycles on ordering.
Regardless, it usually a good idea for the datatypes and basic tools
not to constrain how they're used. By not promising order, repr
remains a nice building block; if you want additional promises, they
can be implemented on top (which is what pprint does).
I'd rather repr remain as simple as possible, as it's more useful that way.
Fred L. Drake, Jr. <fdrake at gmail.com>
"Chaos is the score upon which reality is written." --Henry Miller
More information about the testing-in-python