python / cpython

The Python programming language
https://www.python.org
Other
63.08k stars 30.21k forks source link

Structure and native Structure (LittleEndianStructure on Windows) supports __slots__, but BigEndianStructure doesn't #60274

Open 0b4809ce-f77d-40b4-a79a-6012870dabba opened 12 years ago

0b4809ce-f77d-40b4-a79a-6012870dabba commented 12 years ago
BPO 16070
Files
  • slots_test.py: test script
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields: ```python assignee = None closed_at = None created_at = labels = ['ctypes', 'type-bug'] title = "Structure and native Structure (LittleEndianStructure on Windows) supports __slots__, but BigEndianStructure doesn't" updated_at = user = 'https://bugs.python.org/hct' ``` bugs.python.org fields: ```python activity = actor = 'BreamoreBoy' assignee = 'none' closed = False closed_date = None closer = None components = ['ctypes'] creation = creator = 'hct' dependencies = [] files = ['27323'] hgrepos = [] issue_num = 16070 keywords = [] message_count = 2.0 messages = ['171402', '222928'] nosy_count = 1.0 nosy_names = ['hct'] pr_nums = [] priority = 'normal' resolution = None stage = None status = 'open' superseder = None type = 'behavior' url = 'https://bugs.python.org/issue16070' versions = ['Python 3.4', 'Python 3.5'] ```

    0b4809ce-f77d-40b4-a79a-6012870dabba commented 12 years ago

    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

    83d2e70e-e599-4a04-b820-3814bbdb9bef commented 10 years ago

    @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.