This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author theller
Recipients jaraco, theller
Date 2009-09-17.19:53:37
SpamBayes Score 7.7909346e-12
Marked as misclassified No
Message-id <1253217219.26.0.428566741169.issue5042@psf.upfronthosting.co.za>
In-reply-to
Content
The problem is the implementation of the current __init__ method, in
Modules/_ctypes/_ctypes.c, line 4024.  Rewritten in Python, and slightly
simplified it looks like this:

    def __init__(self, *args, **kw):
        """The current BUGGY __init__ method"""
        names = [f[0] for f in self._fields_]
        for n, v in zip(names, args):
            setattr(self, n, v)
        for n, v in kw.iteritems():
            setattr(self, n, v)

It assigns positional parameters to the names found in the _fields_ list
of the subclass, but it should look up all the _fields_ definitions in
all the superclasses, too.  Working pseudo Python code:

    def __init__(self, *args, **kw):
        """This is how the Structure's __init__method SHOULD be"""
        if args:
            names = []
            for tp in self.__class__.mro()[2::-1]:
                for n, _ in tp._fields_:
                    names.append(n)
            for n, v in zip(names, args):
                setattr(self, n, v)
        for n, v in kw.iteritems():
            setattr(self, n, v)

Now, I don't really want to write the above code in C ;-).
History
Date User Action Args
2009-09-17 19:53:39thellersetrecipients: + theller, jaraco
2009-09-17 19:53:39thellersetmessageid: <1253217219.26.0.428566741169.issue5042@psf.upfronthosting.co.za>
2009-09-17 19:53:37thellerlinkissue5042 messages
2009-09-17 19:53:37thellercreate