From patchwork Sat Jun 3 07:56:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 18698 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 3D106C32AF for ; Sat, 3 Jun 2023 07:57:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0EC24628A1; Sat, 3 Jun 2023 09:57:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1685779043; bh=w/FC3Gju+vqRcQk+qqVpMJf2jHZlmQ8sepFEn0xU0IQ=; 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=XJGUpUUQtOomymBKio0j4qUuLMox8iowadxeeUXmz1VjBxDXcMTc3wzY9KOsU7bIQ O8SpEtWnSMt3UK+RydAKXEeV7BI8nNIMZm7HT/Hsw0jxHiUXdnSOYaZm81JIUyKaNY RZ6lTnSyoHBErdzgPl9SpMhgxdds2jaQU8v5wNPSriaMfwtxFR0W7nH9Y+WiGMAZl/ SjR2twJIiAPWvF+NATzZ0QQxkAAhqZe2vPm256DaXHXfYwd5ISAOUJPFTi/i3zl/tv Mekw1JostEwqXPvLbNLxQf5mgHdK3ranxEu5xadZ8aj9F14dLbrl+9aJL66xaB2xdS Ea7d18/8eX8wg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B9AFA6287E for ; Sat, 3 Jun 2023 09:57:16 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ZhPAlRli"; dkim-atps=neutral Received: from desky.lan (91-154-35-171.elisa-laajakaista.fi [91.154.35.171]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 49F6A1AFA; Sat, 3 Jun 2023 09:56:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1685779013; bh=w/FC3Gju+vqRcQk+qqVpMJf2jHZlmQ8sepFEn0xU0IQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZhPAlRli4e2/PSUoJjGnY935TyJ7umAo6gFJv0wEJCAvgGLLsqNDOgwEKqQ7pqpON wPiSV4JUDAQBW6aKozMcF7JvfIsA9qLGSeB1EqC86kBHOlgPoGYtxuST04m2ZeX3wj kF8jdksnU+yDylsa4QJg3yYILq/PkuefKmEzVjdk= To: libcamera-devel@lists.libcamera.org Date: Sat, 3 Jun 2023 10:56:15 +0300 Message-Id: <20230603075615.20663-14-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230603075615.20663-1-tomi.valkeinen@ideasonboard.com> References: <20230603075615.20663-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 13/13] 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, helping 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 bc40849a..85303d71 100644 --- a/src/py/libcamera/py_main.cpp +++ b/src/py/libcamera/py_main.cpp @@ -145,11 +145,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", []() {