diff options
author | 2013-05-04 11:25:01 +0200 | |
---|---|---|
committer | 2013-05-04 11:25:01 +0200 | |
commit | 8ed1a812cfb44d29602264b503c8073575bba753 (patch) | |
tree | 5434f4683f4c43b8f51681dfe618902abaf4ccca | |
parent | merge (diff) | |
download | pypy-8ed1a812cfb44d29602264b503c8073575bba753.tar.gz pypy-8ed1a812cfb44d29602264b503c8073575bba753.tar.bz2 pypy-8ed1a812cfb44d29602264b503c8073575bba753.zip |
Issue1473: Subclasses or ctypes.Structure without _fields_ should inherit the list of field names, not reset it.
-rw-r--r-- | lib_pypy/_ctypes/structure.py | 1 | ||||
-rw-r--r-- | pypy/module/test_lib_pypy/ctypes_tests/test_structures.py | 12 |
2 files changed, 12 insertions, 1 deletions
diff --git a/lib_pypy/_ctypes/structure.py b/lib_pypy/_ctypes/structure.py index 169553ed87..441cd166cd 100644 --- a/lib_pypy/_ctypes/structure.py +++ b/lib_pypy/_ctypes/structure.py @@ -167,7 +167,6 @@ class StructOrUnionMeta(_CDataMeta): 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 index c6b6abc782..e61986baac 100644 --- 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 @@ class TestStructure(BaseCTypesTestChecker): 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 @@ class TestRecursiveStructure(BaseCTypesTestChecker): raises(AttributeError, setattr, X, "_fields_", []) Y.__fields__ = [] + class TestPatologicalCases(BaseCTypesTestChecker): def test_structure_overloading_getattr(self): class X(Structure): |