New submission from Vijay <rvij...@gmail.com>:
I am trying to "monkey patch" a class derived from Python ctypes "Union", but I am unable to do so - getting weird errors and sometimes seg-faults. The same thing works quite well when deriving from ctypes "Structure". I have narrowed this to down to the simplest possible test case which I am posting below. I am using Python 3.6.4. I am wondering if I am doing something wrong (or is there a problem with the ctypes "Union" implementation?). The example python code is attached with this issue. Please see the output below (for the attached code in Python 3.6.4). Using Structure: ---------------- Print Type #1: [ 10, 20 ] Original : <function MyStruct.__str__ at 0x7fdf89d02e18> Patched : <function display at 0x7fdf8b0ebe18> Patched (dict) : <function display at 0x7fdf8b0ebe18> Print Type #2: ( 10, 20 ) Using Union: ------------ Print Type #1: [ 20, 20 ] Original : <function MyUnion.__str__ at 0x7fdf89d02f28> Patched : <function MyUnion.__str__ at 0x7fdf89d02f28> Patched (dict) : <function display at 0x7fdf8b0ebe18> Traceback (most recent call last): File "ctypes_bug.py", line 54, in <module> print(a) TypeError: 'managedbuffer' object is not callable Clearly, I am able to "patch" __str__ when the corresponding Python object was derived from "Structure", but I am unable to "patch" __str__ when the corresponding Python object was derived from "Union". Interestingly, MyUnion.__dict__[__str__] and MyUnion.__str__ shows different results - which is weird as well. Is there something I am doing wrong here, or is there an issue with ctypes.Union? I highly appreciate any help or insight! ---------- components: ctypes files: ctypes_bug.py messages: 330817 nosy: rvijayc priority: normal severity: normal status: open title: Monkey Patching class derived from ctypes.Union doesn't work type: behavior versions: Python 3.6 Added file: https://bugs.python.org/file47961/ctypes_bug.py _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue35366> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com