[Python-Dev] r59947 - in python/trunk:Lib/test/test_structseq.py Misc/NEWS (original) (raw)

Guido van Rossum guido at python.org
Mon Jan 14 05:15:57 CET 2008


On Jan 13, 2008 7:53 PM, Raymond Hettinger <python at rcn.com> wrote:

[Christian Heimes] > Log: > Added new an better structseq representation. E.g. repr(time.gmtime(0)) now returns 'time.structtime(tmyear=1970, tmmon=1, > tmmday=1, tmhour=0, tmmin=0, tmsec=0, tmwday=3, tmyday=1, tmisdst=0)' instead of '(1970, 1, 1, 0, 0, 0, 3, 1, 0)'. The > feature is part of #1816: sys.flags

FWIW, I was looking into something similar but didn't proceed because it would break eval(repr(s)) == s as the constructor signature wants all the args in a tuple and won't accept keywords. Still, I think what you did is a nice improvement. Here's a couple more if you want to proceed down that path: 1. Have structseq subclass from PyTupleObject so that isinstance(s, tuple) returns True. This makes the object usable whenever tuples are needed.

Hmm, is that really necessary? structseq has been in use for quite a while and this need hasn't come up -- it's been designed to be quite compatible with tuple except for isinstance checks, and that has worked well.

2. Add fields, asdict, and replace to match the API in collections.namedtuple(). The fields tuple should only include the visible positional fields while asdict() and replace() should include all of the fields whether visible or accessible only by attribute access.

Thanks for the nice work.

Raymond


Python-Dev mailing list Python-Dev at python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/guido%40python.org

-- --Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list