From patchwork Thu Mar 9 14:26:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 18375 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 3A1DFC32A5 for ; Thu, 9 Mar 2023 14:26:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C431762715; Thu, 9 Mar 2023 15:26:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1678371990; bh=5FwgOSzFtXbcHkPOsawNfIsu3wCs2lDtN23afzfYdJg=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=CWOpzUrgCBi43wsp2GI943e9o3jMptiOtT0E29TfYtPbw/gOJW6X5KoKmf/W/gRXN HHw9NFBeCyBEmJnws7QhRWlf0441U4Ko8qTiSBZ1YdnHZz/FelCb6VR28FLr9pWOqc W0tMvwDqowFbo+PCEu7bQ6CHqRzhdmIsWBpKKRtunb0UetB6fzQOueYewmtSqOZ+7L eVQzimXE0Pwr7JBDJMiwVq4Kz+HgTpmgjhBAlQZbyY8jsDzGbOn97i7den8hMmY1Uc /gzMKMGhPOpWn3dcuCXxAHc+OGeWoMJZ7LxgCPAjRsDQKf1m9EkJVylPaG3ajdP6II T0fcvpDZaKaHA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F1949626F5 for ; Thu, 9 Mar 2023 15:26:21 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="DH7UYVkU"; dkim-atps=neutral Received: from desky.lan (91-154-32-225.elisa-laajakaista.fi [91.154.32.225]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8C577589; Thu, 9 Mar 2023 15:26:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1678371981; bh=5FwgOSzFtXbcHkPOsawNfIsu3wCs2lDtN23afzfYdJg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DH7UYVkUD427sYhVd0n37rhXgXGVEe5n870PsdaUccwHfeAjwqrCqOtbe6mYr+vDq 3UsLscvgPf1XAlvRF541WoYBB9O+RCzBnDX0tgFvAMj/dfJ155kbb7A5tyGo16hLkR GHk7eQGciGJAI52B6NSBaPUlyEeWrM2j+hYv/x9o= To: libcamera-devel@lists.libcamera.org Date: Thu, 9 Mar 2023 16:26:00 +0200 Message-Id: <20230309142601.70556-15-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230309142601.70556-1-tomi.valkeinen@ideasonboard.com> References: <20230309142601.70556-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 14/15] py: Improve stub type generation for PyCameraEvent X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tomi Valkeinen via libcamera-devel From: Tomi Valkeinen Reply-To: Tomi Valkeinen Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" We store the camera, request and fb fields in PyCameraEvent as py::objects, so that we keep the refs and keep-alives. When we return py::objects to the Python side, they, obviously, show up as "objects" when the stub generation is looking at the fields. Fix this by manually casting the py::objects to the correct C++ counterparts, which causes pybind11 to assign the correct types for the properties, helpind stubgen to generate correct types. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart --- src/py/libcamera/py_main.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/py/libcamera/py_main.cpp b/src/py/libcamera/py_main.cpp index 1585b14a..cb7088b1 100644 --- a/src/py/libcamera/py_main.cpp +++ b/src/py/libcamera/py_main.cpp @@ -100,11 +100,19 @@ PYBIND11_MODULE(_libcamera, m) .value("RequestCompleted", CameraEventType::RequestCompleted) .value("BufferCompleted", CameraEventType::BufferCompleted); + /* + * For camera, request and fb fields, manually typecast to the C++ type, + * so that pybind11 assigns the actual type for the return value. This + * makes the stubs generated by pybind11-stubgen contain the correct type, + * instead of "object". + * + * Maybe there's a better way to do this... + */ pyEvent .def_readonly("type", &PyCameraEvent::type_) - .def_readonly("camera", &PyCameraEvent::camera_) - .def_readonly("request", &PyCameraEvent::request_) - .def_readonly("fb", &PyCameraEvent::fb_); + .def_property_readonly("camera", [](PyCameraEvent &self) { return self.camera_.cast(); }) + .def_property_readonly("request", [](PyCameraEvent &self) { return self.request_.cast(); }) + .def_property_readonly("fb", [](PyCameraEvent &self) { return self.fb_.cast(); }); pyCameraManager .def_static("singleton", []() {