classification
Title: Enhance Object/structseq.c to match namedtuple and tuple api
Type: feature request
Components: Interpreter Core Versions: Python 3.0, Python 2.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: adlaiff6, christian.heimes, georg.brandl, rhettinger
Priority: low Keywords: easy

Created on 2008-01-14 04:20 by christian.heimes, last changed 2008-02-23 22:54 by rhettinger.

Files
File name Uploaded Description Edit Remove
structseq_subclasses_tuple.diff adlaiff6, 2008-01-14 07:03 patch which makes structseq a subclass of tuple
structseq.diff rhettinger, 2008-01-15 01:21 Tuple subclass patch with tests.
Messages
msg59888 (view) Author: Christian Heimes (christian.heimes) Date: 2008-01-14 04:20
Raymond Hettinger wrote:

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.

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.

3. Change the constructor to accept keyword args so that eval(repr(s))
== s works.

NOTE:
I've marked the task as easy but it's not a task for a total newbie.
It's a feasible yet challenging task for somebody who likes to get into
CPython core programming. Basic C knowledge is required!
msg59891 (view) Author: Leif Walsh (adlaiff6) Date: 2008-01-14 07:03
Here is a patch for #1.  I ran make test, and nothing was broken that
seemed to be my fault, so I assume it's okay.

Yes, it's small, it's my first one here.  I'll get to the other two
tomorrow.
msg59949 (view) Author: Raymond Hettinger (rhettinger) Date: 2008-01-15 01:21
Thanks for the patch.  I removed the whitespace changes and added some
tests to make sure structseq now works with the % formatting operator
and isinstance(t,tuple).

Am getting a sporadic segfault in test_zipimport when running "make
test", so holding-off on applying:

test_zipimport
~/py26/Lib/test/test_zipimport.py:91: ImportWarning: Not importing
directory '/home/rhettinger/py26/Modules/zlib': missing __init__.py
  ["__dummy__"])
make: *** [test] Segmentation fault
msg59955 (view) Author: Leif Walsh (adlaiff6) Date: 2008-01-15 02:01
I just svn upped (it updated zipimport) and applied your patch, and
'./python Lib/test/regrtest.py test_zipimport.py' says it's okay, so I
would go ahead and commit it.
msg59956 (view) Author: Raymond Hettinger (rhettinger) Date: 2008-01-15 02:05
Run, "make test" a few times to make sure it doesn't bomb.

The problem may be due to needing a deferred_type instead of assigning
&PyTupleObject directly.  Will look it more later.
msg59957 (view) Author: Raymond Hettinger (rhettinger) Date: 2008-01-15 03:03
It worked fine on a fresh check-out.  Committed in revision 59967.
msg62830 (view) Author: Georg Brandl (georg.brandl) Date: 2008-02-23 22:49
Is there something else to be done for this to be closed?
msg62831 (view) Author: Raymond Hettinger (rhettinger) Date: 2008-02-23 22:54
All three items are still open.  The second one is the easiest.
History
Date User Action Args
2008-02-23 22:54:01rhettingersetmessages: + msg62831
2008-02-23 22:49:45georg.brandlsetnosy: + georg.brandl
messages: + msg62830
2008-01-15 03:03:57rhettingersetmessages: + msg59957
2008-01-15 02:05:38rhettingersetmessages: + msg59956
2008-01-15 02:01:05adlaiff6setmessages: + msg59955
2008-01-15 01:21:34rhettingersetfiles: + structseq.diff
messages: + msg59949
2008-01-15 00:33:03rhettingersetassignee: rhettinger
2008-01-14 07:03:20adlaiff6setfiles: + structseq_subclasses_tuple.diff
nosy: + adlaiff6
messages: + msg59891
2008-01-14 04:20:27christian.heimescreate