rindeal <dev.rindeal+bugs.python....@gmail.com> added the comment:
I have created a workaround, since it might take years to fix this in master. Hope it'll come in useful. For the example in https://bugs.python.org/issue43073#msg385970, but probably any combination of Unions and BigEndianStructures can be constructed this way. ``` class U_a(ct.BigEndianStructure): _pack_ = True _fields_ = [('a', ct.c_int)] class U_b(ct.BigEndianStructure): _pack_ = True _fields_ = [('b', ct.c_int)] class U(ct.Union): _pack_ = True _fields_ = [ ('_a', U_a), ('_b', U_b), ] _anonymous_ = ['_a', '_b'] class _S_be_fields_only(ct.Structure): _pack_ = True _fields_ = [ ('_x', ct.c_int), ('y', U), ] class _S_2be_fields_only(ct.BigEndianStructure): _pack_ = True _fields_ = [ ('x', ct.c_int), ('_y', ct.c_byte * ct.sizeof(U)), ] class _S_U(ct.Union): _pack_ = True _fields_ = [ ('_be_fields_only', _S_be_fields_only), ('_2be_fields_only', _S_2be_fields_only), ] _anonymous_ = [f[0] for f in _fields_] class S(ct.Structure): _pack_ = True _fields_ = [('_s_u', _S_U)] _anonymous_ = [_fields_[0][0]] issubclass(S, ct.Structure) == True s = S(x=0x11223344, y=U(a=0xaabbccdd)) s.y.a == s.y.b bytes(s).hex() == "11223344aabbccdd" ``` ---------- nosy: +rindeal _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue43073> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com