Message92792
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 ;-). |
|
Date |
User |
Action |
Args |
2009-09-17 19:53:39 | theller | set | recipients:
+ theller, jaraco |
2009-09-17 19:53:39 | theller | set | messageid: <1253217219.26.0.428566741169.issue5042@psf.upfronthosting.co.za> |
2009-09-17 19:53:37 | theller | link | issue5042 messages |
2009-09-17 19:53:37 | theller | create | |
|