classification
Title: Structure and native Structure (LittleEndianStructure on Windows) supports __slots__, but BigEndianStructure doesn't
Type: behavior Stage:
Components: ctypes Versions: Python 3.4, Python 3.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: hct
Priority: normal Keywords:

Created on 2012-09-28 03:19 by hct, last changed 2019-04-26 19:10 by BreamoreBoy.

Files
File name Uploaded Description Edit
slots_test.py hct, 2012-09-28 03:19 test script
Messages (2)
msg171402 - (view) Author: HCT (hct) Date: 2012-09-28 03:19
using official CPython 3.2.3 with a simple demonstration script (attached) to demonstrate inconsistency between ctypes structures

from ctypes import *

class cbs( BigEndianStructure ):
    __slots__ = tuple()
    def __init__( self, *args, **kw ):
        super().__init__( *args, **kw )
        self.a = 11

class cls( LittleEndianStructure ):
    __slots__ = tuple()
    def __init__( self, *args, **kw ):
        super().__init__( *args, **kw )
        self.a = 11

class cs( Structure ):
    __slots__ = tuple()
    def __init__( self, *args, **kw ):
        super().__init__( *args, **kw )
        self.a = 11

try :
    cbs1=cbs()
except AttributeError as e:
    print(e)

try :
    cls1=cls()
except AttributeError as e:
    print(e)

try :
    cs=cs()
except AttributeError as e:
    print(e)



yields

'cls' object has no attribute 'a'
'cs' object has no attribute 'a'



I expect cbs to throw error too, but itwent through the initalization and silently ignored the __slots__ defined in the class
msg222928 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-07-13 14:17
@hct I'm very sorry about the delay in getting back to you.  The reported bevaviour is the same with 3.4.1 and 3.5.0a0 on Windows 7.
History
Date User Action Args
2019-04-26 19:10:00BreamoreBoysetnosy: - BreamoreBoy
2014-07-13 14:17:27BreamoreBoysetnosy: + BreamoreBoy

messages: + msg222928
versions: + Python 3.4, Python 3.5, - Python 3.2
2012-09-28 03:19:04hctcreate