creating struct-seq types from Python

Martin, I've addressed this to you since you seem to be playing with the relevant code these days, but others may be interested as well. Have you looked at what it would take to create new "structure sequence" types from Python code? This seems like a reasonable thing to do, especially when an existing API returns a long(ish) tuple of fields. I'd like to be able to use it for my proposed urlparse changes (http://www.python.org/sf/624325), but there seems to be no way to get to it. What's needed to do something currently feels like too much code for what little is being done (see the patch if unsure of what I mean). Thanks! -Fred -- Fred L. Drake, Jr. <fdrake at acm.org> PythonLabs at Zope Corporation

"Fred L. Drake, Jr." <fdrake@acm.org> writes:
Have you looked at what it would take to create new "structure sequence" types from Python code?
Not really, but I think all you need to do is to expose PyStructSequence_InitType. I would recommend an interface like struct_seq(name, doc, n_in_sequence, (fields)) where fields is a list of (name,doc) tuples. You will need to temporarily allocate a PyStructSequence_Field array of len(fields)+1 elements, and put the PyStructSequence_Desc on the stack. You will also need to dynamically allocate a PyTypeObject which you return. I would put this into the new module. Regards, Martin

"Fred L. Drake, Jr." <fdrake@acm.org> writes:
Have you looked at what it would take to create new "structure sequence" types from Python code?
Not really, but I think all you need to do is to expose PyStructSequence_InitType. I would recommend an interface like struct_seq(name, doc, n_in_sequence, (fields)) where fields is a list of (name,doc) tuples. You will need to temporarily allocate a PyStructSequence_Field array of len(fields)+1 elements, and put the PyStructSequence_Desc on the stack. You will also need to dynamically allocate a PyTypeObject which you return. I would put this into the new module. Regards, Martin
participants (2)
-
Fred L. Drake, Jr.
-
martin@v.loewis.de