More informative repr for Repository objects#352
Conversation
|
Isn't the standard way of doing it more along the lines of |
|
The docs say "For many types, this function [repr] makes an attempt to return a string that would yield an object with the same value when passed to eval(), otherwise the representation is a string enclosed in angle brackets that contains the name of the type of the object together with additional information often including the name and address of the object." If the object can practically be reconstructed in a single line of code, the constructor form is generally preferred. In the standard library, classes in the decimal, fractions, collections and ast modules work like this, for example. |
|
Actually, the docs for the |
|
Does a Note that for collections drops the module name >>> from collections import defaultdict
>>> repr(defaultdict(int))
"defaultdict(<type 'int'>, {})"so just On Tue, Mar 25, 2014 at 7:03 PM, Thomas Kluyver notifications@github.comwrote:
|
|
Yes, I was assuming that there's no important state stored in the I feel like I've seen modules that keep the module name in as well, though I can't find any at the moment. It seems better to me to be unambiguous, but I'm happy with dropping the module name if others prefer that. |
|
|
|
Thanks! |
Before, with the default Python repr:
After, with a repr that shows how to construct this object (which is recommended where practical):