Author MrSurly
Recipients MrSurly
Date 2021-01-30.04:38:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Placing a ctypes.Union inside of a ctypes.BigEndianStructure results in "TypeError: This type does not support other endian".  I believe this is a similar problem to issue #4376 (

Minimum repro test case:

import ctypes as ct

class U(ct.Union):
        ('a', ct.c_int),
        ('b', ct.c_int),

class S(ct.BigEndianStructure):
        ('x', ct.c_int),
        ('y', U),

I believe the fix is similar to that issue, though I admit I don't know enough about this code to be sure.

diff --git a/Lib/ctypes/ b/Lib/ctypes/
index 37444bd6a7..525c5e58c9 100644
--- a/Lib/ctypes/
+++ b/Lib/ctypes/
@@ -18,6 +18,9 @@ def _other_endian(typ):
     # if typ is structure
     if issubclass(typ, Structure):
         return typ
+    # if typ is union:
+    if issubclass(typ, Union):
+        return typ
     raise TypeError("This type does not support other endian: %s" % typ)
 class _swapped_meta(type(Structure)):
Date User Action Args
2021-01-30 04:38:58MrSurlysetrecipients: + MrSurly
2021-01-30 04:38:58MrSurlysetmessageid: <>
2021-01-30 04:38:58MrSurlylinkissue43073 messages
2021-01-30 04:38:58MrSurlycreate