[libgpiod][PATCH 4/9] bindings: python: simplify disallowing _ext.Request from being created

Vincent Fazio
2026-04-22T01:21:00Z

Previously, tp_new and tp_init functions were defined for Request with
the tp_init function raising a NotImplementedError to prevent the object
from being initialized (__init__, the stage after __new__).

Similar results can be achieved by removing the tp_new and tp_init
functions which raise a slightly different error:

TypeError: cannot create 'gpiod._ext.Request' instances

As this is an internal only detail, there should be impact to users.

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
---
bindings/python/gpiod/ext/request.c | 12 ------------
1 file changed, 12 deletions(-)

diff --git a/bindings/python/gpiod/ext/request.c b/bindings/python/gpiod/ext/request.c
index 1e1f65a..9940382 100644
--- a/bindings/python/gpiod/ext/request.c
+++ b/bindings/python/gpiod/ext/request.c
@@ -12,16 +12,6 @@ typedef struct {
struct gpiod_edge_event_buffer *buffer;
} request_object;

-static int request_init(PyObject *Py_UNUSED(ignored0),
- PyObject *Py_UNUSED(ignored1),
- PyObject *Py_UNUSED(ignored2))
-{
- PyErr_SetString(PyExc_NotImplementedError,
- "_ext.LineRequest cannot be instantiated");
-
- return -1;
-}
-
static void internal_request_release(request_object *self)
{
if (self->request){
@@ -390,8 +380,6 @@ PyTypeObject request_type = {
.tp_name = "gpiod._ext.Request",
.tp_basicsize = sizeof(request_object),
.tp_flags = Py_TPFLAGS_DEFAULT,
- .tp_new = PyType_GenericNew,
- .tp_init = (initproc)request_init,
.tp_finalize = (destructor)request_finalize,
.tp_dealloc = (destructor)Py_gpiod_dealloc,
.tp_getset = request_getset,
--
2.43.0