You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TypeError when using ctypes.BigEndianUnion nested in ctypes.BigEndianStructure on a little endian system (or vice versa) #105102
The classes ctypes.BigEndianUnion and ctypes.LittleEndianUnion was added in Python 3.11. In the case of the use of an Union in a Structure class that match the opposite system endianness, the Union class can't be used as shown below:
The following traceback is given by the interpretor:
TypeError Traceback (most recent call last)
Cell In[1], line 28
24 class MyUnion(c.BigEndianUnion):
25 _fields_ = [("my_struct", MyStruct), ("ab", c.c_short)]
---> 28 class MainStruct(c.BigEndianStructure):
29 _fields_ = [("my_union", MyUnion), ("foo", c.c_byte)]
File ~\AppData\Local\Programs\Python\Python311\Lib\ctypes\_endian.py:31, in _swapped_meta.__setattr__(self, attrname, value)
29 typ = desc[1]
30 rest = desc[2:]
---> 31 fields.append((name, _other_endian(typ)) + rest)
32 value = fields
33 super().__setattr__(attrname, value)
File ~\AppData\Local\Programs\Python\Python311\Lib\ctypes\_endian.py:21, in _other_endian(typ)
19 if issubclass(typ, Structure):
20 return typ
---> 21 raise TypeError("This type does not support other endian: %s" % typ)
TypeError: This type does not support other endian: <class '__main__.MyUnion'>
Your environment
CPython versions tested on: Interpreter compiled from the main branch in debug mode and also Python 3.11 (coming from the official release)
Activity
Merge branch 'main' into fix-pythongh-105102
gh-105102: Fix nested unions in structures when the system byteorder …
[3.12] pythongh-105102: Fix nested unions in structures when the syst…
[3.11] pythongh-105102: Fix nested unions in structures when the syst…
[3.11] gh-105102: Fix nested unions in structures when the system byt…
[3.12] gh-105102: Fix nested unions in structures when the system byt…
pythongh-105102: Fix nested unions in structures when the system byte…
pythongh-105102: Fix nested unions in structures when the system byte…
pythongh-105102: Fix nested unions in structures when the system byte…