Author: Amaury Forgeot d'Arc <[email protected]>
Branch:
Changeset: r63845:1236a55828ce
Date: 2013-05-04 11:25 +0200
http://bitbucket.org/pypy/pypy/changeset/1236a55828ce/
Log: Issue1473: Subclasses or ctypes.Structure without _fields_ should
inherit the list of field names, not reset it.
diff --git a/lib_pypy/_ctypes/structure.py b/lib_pypy/_ctypes/structure.py
--- a/lib_pypy/_ctypes/structure.py
+++ b/lib_pypy/_ctypes/structure.py
@@ -167,7 +167,6 @@
return
if '_fields_' not in self.__dict__:
self._fields_ = []
- self._names = []
_set_shape(self, [], self._is_union)
__setattr__ = struct_setattr
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py
b/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py
@@ -230,6 +230,17 @@
pt = POINT(y=2, x=1)
assert (pt.x, pt.y) == (1, 2)
+ def test_subclass_initializer(self):
+ class POINT(Structure):
+ _fields_ = [("x", c_int), ("y", c_int)]
+
+ class POSITION(POINT):
+ # A subclass without _fields_
+ pass
+ pos = POSITION(1, 2)
+ assert (pos.x, pos.y) == (1, 2)
+
+
def test_invalid_field_types(self):
class POINT(Structure):
pass
@@ -538,6 +549,7 @@
raises(AttributeError, setattr, X, "_fields_", [])
Y.__fields__ = []
+
class TestPatologicalCases(BaseCTypesTestChecker):
def test_structure_overloading_getattr(self):
class X(Structure):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit