[New-bugs-announce] [issue38860] GenericPyCData_new does not invoke new or init

Justin Capella report at bugs.python.org
Tue Nov 19 21:34:04 EST 2019


New submission from Justin Capella <justincapella at gmail.com>:

When subclassing the ctypes.Structure class, __new__ and __init__ are not invoked when using the inherited classmethod from_buffer_copy to create the object.

I think this is because tp_alloc is ultimately used by GenericPyCData_new when creating the object using the from_buffer_copy classmethod inherited from _CData.

https://github.com/python/cpython/blob/be143ec99674ba38c5811f34cdb85ef39c2dc8f8/Modules/_ctypes/_ctypes.c#L3202

Expected behavior: creation of Structure subclass object would invoke __new__ and possibly __init__.

----------
components: ctypes
files: ctypesnew.py
messages: 357022
nosy: b1tninja
priority: normal
severity: normal
status: open
title: GenericPyCData_new does not invoke new or init
type: behavior
versions: Python 2.7, Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 3.9
Added file: https://bugs.python.org/file48723/ctypesnew.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38860>
_______________________________________


More information about the New-bugs-announce mailing list