From patchwork Thu Nov 14 14:50:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 2011411 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=xes-inc.com header.i=@xes-inc.com header.a=rsa-sha256 header.s=mail header.b=OXncu32V; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:4601:e00::3; helo=am.mirrors.kernel.org; envelope-from=linux-gpio+bounces-13009-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [IPv6:2604:1380:4601:e00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Xq3592Wz1z1xyc for ; Fri, 15 Nov 2024 01:51:41 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 1A2CA1F24370 for ; Thu, 14 Nov 2024 14:51:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6D1EEBA53; Thu, 14 Nov 2024 14:51:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="OXncu32V" X-Original-To: linux-gpio@vger.kernel.org Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 38D2141746 for ; Thu, 14 Nov 2024 14:51:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595891; cv=none; b=foOfhRMvB7zs0KILDCHOnmMl5TyxaJpe+2QS5lP3DjYAAP4hNl7CaxwSYGkXADz/nLlriLGC2CACd6LDBz7u1386m89YoR6kxOYuUW7tQPNE5M6cBK2zj6ZiH4YAUoi966EfI6IajFQKxPGUob56zaTcCTXI3PBfOMMpLr5s+Kc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595891; c=relaxed/simple; bh=deKaW6iusWdqvEUsv4+1CTydFSZ0/TE4CAFl16/OLNM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GX6R17jjBFFGNU/k6qTg1Cn51e57ud+gZh9f7rohdfFua9gWgxUHqE/31l+xfKHaPDoQshaEipm3Oz7yehnK7dUaRul+nUc4lYuccPvR8UPSQE09BPQQ+G4Ptgkr37EH0/Tj6IiTw0iYeRmQGEHdAj4C+uHsJuXVDn0AVyLR6oI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=OXncu32V; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id 45A2D20404; Thu, 14 Nov 2024 08:51:22 -0600 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1731595882; bh=deKaW6iusWdqvEUsv4+1CTydFSZ0/TE4CAFl16/OLNM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OXncu32VpSF8zj5Hxo8RSIv7CwaqVo53PjpPPaMtYskJOzaLLz8levtXZVaMoBTR+ g81XHlCGsHrMGq2rdTAWQ1Oawhzxjb6uADfI/SIbsm+BKsHsLj3/ansHUxq+puWilU oYBW85UeBcUK+qQ0BrdfZsyzT+RLlewlOHlfbvI0= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH v2 01/23] bindings: python: clean up imports and exports Date: Thu, 14 Nov 2024 08:50:54 -0600 Message-Id: <20241114145116.2123714-2-vfazio@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114145116.2123714-1-vfazio@xes-inc.com> References: <20241114145116.2123714-1-vfazio@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Remove unused imports and sort the remainder following isort rules. Update submodules to use lists for `__all__` for ease of re-exporting public classes from within gpiod. Place imports used only for the purposes of type checking behind a TYPE_CHECKING guard. Signed-off-by: Vincent Fazio --- bindings/python/gpiod/__init__.py | 65 ++++++++++++++++++++++---- bindings/python/gpiod/chip.py | 23 +++++---- bindings/python/gpiod/chip_info.py | 2 +- bindings/python/gpiod/edge_event.py | 5 +- bindings/python/gpiod/info_event.py | 7 +-- bindings/python/gpiod/internal.py | 2 +- bindings/python/gpiod/line.py | 3 +- bindings/python/gpiod/line_info.py | 6 +-- bindings/python/gpiod/line_request.py | 18 ++++--- bindings/python/gpiod/line_settings.py | 7 +-- 10 files changed, 99 insertions(+), 39 deletions(-) diff --git a/bindings/python/gpiod/__init__.py b/bindings/python/gpiod/__init__.py index 9cbb8df..aaa0474 100644 --- a/bindings/python/gpiod/__init__.py +++ b/bindings/python/gpiod/__init__.py @@ -7,19 +7,66 @@ Python bindings for libgpiod. This module wraps the native C API of libgpiod in a set of python classes. """ -from . import _ext -from . import line -from .chip import Chip -from .chip_info import ChipInfo -from .edge_event import EdgeEvent -from .exception import ChipClosedError, RequestReleasedError -from .info_event import InfoEvent -from .line_request import LineRequest -from .line_settings import LineSettings +from . import ( + _ext, + chip, + chip_info, + edge_event, + exception, + info_event, + line, + line_info, + line_request, + line_settings, + version, +) +from .chip import * +from .chip_info import * +from .edge_event import * +from .exception import * +from .info_event import * +from .line_info import * +from .line_request import * +from .line_settings import * from .version import __version__ api_version = _ext.api_version +# public submodules +__all__ = [ + "chip", + "chip_info", + "edge_event", + "exception", + "info_event", + "line", + "line_info", + "line_request", + "line_settings", + "version", +] + +# re-export public submodule exports +# do not re-export line objects, this is not an oversight +__all__ += ( + chip.__all__ + + chip_info.__all__ + + edge_event.__all__ + + exception.__all__ + + info_event.__all__ + + line_info.__all__ + + line_request.__all__ + + line_settings.__all__ +) + +# module methods/attributes +__all__ += [ + "__version__", + "api_version", + "is_gpiochip_device", + "request_lines", +] + def is_gpiochip_device(path: str) -> bool: """ diff --git a/bindings/python/gpiod/chip.py b/bindings/python/gpiod/chip.py index 92a7314..29c30f5 100644 --- a/bindings/python/gpiod/chip.py +++ b/bindings/python/gpiod/chip.py @@ -1,22 +1,25 @@ # SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski +from collections import Counter +from errno import ENOENT +from typing import TYPE_CHECKING, Optional, Union + from . import _ext -from .chip_info import ChipInfo from .exception import ChipClosedError -from .info_event import InfoEvent from .internal import poll_fd from .line import Value -from .line_info import LineInfo -from .line_settings import LineSettings, _line_settings_to_ext from .line_request import LineRequest -from collections import Counter -from collections.abc import Iterable -from datetime import timedelta -from errno import ENOENT -from typing import Union, Optional +from .line_settings import LineSettings, _line_settings_to_ext + +if TYPE_CHECKING: + from datetime import timedelta + + from .chip_info import ChipInfo + from .info_event import InfoEvent + from .line_info import LineInfo -__all__ = "Chip" +__all__ = ["Chip"] class Chip: diff --git a/bindings/python/gpiod/chip_info.py b/bindings/python/gpiod/chip_info.py index 92b5e6f..884b910 100644 --- a/bindings/python/gpiod/chip_info.py +++ b/bindings/python/gpiod/chip_info.py @@ -4,7 +4,7 @@ from dataclasses import dataclass -__all__ = "ChipInfo" +__all__ = ["ChipInfo"] @dataclass(frozen=True, repr=False) diff --git a/bindings/python/gpiod/edge_event.py b/bindings/python/gpiod/edge_event.py index bf258c1..a8b2378 100644 --- a/bindings/python/gpiod/edge_event.py +++ b/bindings/python/gpiod/edge_event.py @@ -1,11 +1,12 @@ # SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski -from . import _ext from dataclasses import dataclass from enum import Enum -__all__ = "EdgeEvent" +from . import _ext + +__all__ = ["EdgeEvent"] @dataclass(frozen=True, init=False, repr=False) diff --git a/bindings/python/gpiod/info_event.py b/bindings/python/gpiod/info_event.py index 481eae6..7b544aa 100644 --- a/bindings/python/gpiod/info_event.py +++ b/bindings/python/gpiod/info_event.py @@ -1,12 +1,13 @@ # SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski -from . import _ext -from .line_info import LineInfo from dataclasses import dataclass from enum import Enum -__all__ = "InfoEvent" +from . import _ext +from .line_info import LineInfo + +__all__ = ["InfoEvent"] @dataclass(frozen=True, init=False, repr=False) diff --git a/bindings/python/gpiod/internal.py b/bindings/python/gpiod/internal.py index 2dddb65..d1e95e4 100644 --- a/bindings/python/gpiod/internal.py +++ b/bindings/python/gpiod/internal.py @@ -5,7 +5,7 @@ from datetime import timedelta from select import select from typing import Optional, Union -__all__ = [] +__all__ = ["poll_fd"] def poll_fd(fd: int, timeout: Optional[Union[timedelta, float]] = None) -> bool: diff --git a/bindings/python/gpiod/line.py b/bindings/python/gpiod/line.py index d088fb4..828385c 100644 --- a/bindings/python/gpiod/line.py +++ b/bindings/python/gpiod/line.py @@ -2,9 +2,10 @@ # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski -from . import _ext from enum import Enum +from . import _ext + __all__ = ["Value", "Direction", "Bias", "Drive", "Edge", "Clock"] diff --git a/bindings/python/gpiod/line_info.py b/bindings/python/gpiod/line_info.py index c196a6a..46e1653 100644 --- a/bindings/python/gpiod/line_info.py +++ b/bindings/python/gpiod/line_info.py @@ -1,12 +1,12 @@ # SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski -from . import _ext from dataclasses import dataclass from datetime import timedelta -from gpiod.line import Direction, Bias, Drive, Edge, Clock -__all__ = "LineInfo" +from .line import Bias, Clock, Direction, Drive, Edge + +__all__ = ["LineInfo"] @dataclass(frozen=True, init=False, repr=False) diff --git a/bindings/python/gpiod/line_request.py b/bindings/python/gpiod/line_request.py index 51e600a..292fa1b 100644 --- a/bindings/python/gpiod/line_request.py +++ b/bindings/python/gpiod/line_request.py @@ -1,17 +1,23 @@ # SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski +from typing import TYPE_CHECKING, Optional, Union + from . import _ext -from .edge_event import EdgeEvent + from .exception import RequestReleasedError from .internal import poll_fd -from .line import Value from .line_settings import LineSettings, _line_settings_to_ext -from collections.abc import Iterable -from datetime import timedelta -from typing import Optional, Union -__all__ = "LineRequest" +if TYPE_CHECKING: + from collections.abc import Iterable + from datetime import timedelta + + from .edge_event import EdgeEvent + from .line import Value + + +__all__ = ["LineRequest"] class LineRequest: diff --git a/bindings/python/gpiod/line_settings.py b/bindings/python/gpiod/line_settings.py index 5e32194..f2811b2 100644 --- a/bindings/python/gpiod/line_settings.py +++ b/bindings/python/gpiod/line_settings.py @@ -1,12 +1,13 @@ # SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski -from . import _ext from dataclasses import dataclass from datetime import timedelta -from gpiod.line import Direction, Bias, Drive, Edge, Clock, Value -__all__ = "LineSettings" +from . import _ext +from .line import Bias, Clock, Direction, Drive, Edge, Value + +__all__ = ["LineSettings"] @dataclass(repr=False) From patchwork Thu Nov 14 14:50:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 2011413 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=xes-inc.com header.i=@xes-inc.com header.a=rsa-sha256 header.s=mail header.b=AGr41wQL; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.80.249; helo=am.mirrors.kernel.org; envelope-from=linux-gpio+bounces-13011-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [147.75.80.249]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Xq35C4vN5z1xyc for ; Fri, 15 Nov 2024 01:51:43 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 0A7891F24649 for ; Thu, 14 Nov 2024 14:51:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9DC29770FE; Thu, 14 Nov 2024 14:51:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="AGr41wQL" X-Original-To: linux-gpio@vger.kernel.org Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 38D8043AD2 for ; Thu, 14 Nov 2024 14:51:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595892; cv=none; b=XuoNl+8+5zle2O8oDEjKkZFowWAsu96ILv2rkffwub1BTGbm7KjbVhx3OTf7UvPT2wYHz5OLLbTGQIcCdDcUHX5UBxoWiKbssU9fL6ESN6fZq19dLdAGuqiO/cJTQqgHDSYSrJFEZypsltKtWVQ5WSclhAuXJIw5JFYEJisZ7WU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595892; c=relaxed/simple; bh=sqhNYvgLB7YyrHjizzx0ecRfC/ySCTERpaJgq1E96/g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sZIvyNCgm3z7BpFu0SYviiteJjXXCQFgDukGebyfEeoWhbuJ5s+YmywGkv/2vFpCFSeyh0mfpJQA5rprrkfPy7+JmzF2GrHs8J6Mc4rzZI8jwIdiVj5yYh0Zx0X7+7w36zUMfGEyO7hyFXyfuFHVMo9dcaTwf7dBefL6pj0C2FM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=AGr41wQL; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id 5AD84207FB; Thu, 14 Nov 2024 08:51:22 -0600 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1731595882; bh=sqhNYvgLB7YyrHjizzx0ecRfC/ySCTERpaJgq1E96/g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AGr41wQLJjHHknBC6rdYtWMCWM41WI8JQ/A1vXB5T3hVQh5ciepCNtEzIFbP2h611 b02+UzbfJdWI5ImbZ9R63YP/7llJZntPmXMi5AJUHrNYkR6rhGGdNZOnScWWagL+Tt 4ufyJmQENuv1WANCCGbJylnhv2/lMDTy9HuqMQi4= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH v2 02/23] bindings: python: make internal a private submodule Date: Thu, 14 Nov 2024 08:50:55 -0600 Message-Id: <20241114145116.2123714-3-vfazio@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114145116.2123714-1-vfazio@xes-inc.com> References: <20241114145116.2123714-1-vfazio@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The internal submodule shouldn't be exposed as part of the public interface, so mark it private following PEP 8 convention [0]. [0]: https://peps.python.org/pep-0008/#public-and-internal-interfaces Signed-off-by: Vincent Fazio --- bindings/python/gpiod/{internal.py => _internal.py} | 0 bindings/python/gpiod/chip.py | 2 +- bindings/python/gpiod/line_request.py | 3 +-- 3 files changed, 2 insertions(+), 3 deletions(-) rename bindings/python/gpiod/{internal.py => _internal.py} (100%) diff --git a/bindings/python/gpiod/internal.py b/bindings/python/gpiod/_internal.py similarity index 100% rename from bindings/python/gpiod/internal.py rename to bindings/python/gpiod/_internal.py diff --git a/bindings/python/gpiod/chip.py b/bindings/python/gpiod/chip.py index 29c30f5..175fcb0 100644 --- a/bindings/python/gpiod/chip.py +++ b/bindings/python/gpiod/chip.py @@ -6,8 +6,8 @@ from errno import ENOENT from typing import TYPE_CHECKING, Optional, Union from . import _ext +from ._internal import poll_fd from .exception import ChipClosedError -from .internal import poll_fd from .line import Value from .line_request import LineRequest from .line_settings import LineSettings, _line_settings_to_ext diff --git a/bindings/python/gpiod/line_request.py b/bindings/python/gpiod/line_request.py index 292fa1b..a8e4a87 100644 --- a/bindings/python/gpiod/line_request.py +++ b/bindings/python/gpiod/line_request.py @@ -4,9 +4,8 @@ from typing import TYPE_CHECKING, Optional, Union from . import _ext - +from ._internal import poll_fd from .exception import RequestReleasedError -from .internal import poll_fd from .line_settings import LineSettings, _line_settings_to_ext if TYPE_CHECKING: From patchwork Thu Nov 14 14:50:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 2011412 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=xes-inc.com header.i=@xes-inc.com header.a=rsa-sha256 header.s=mail header.b=eaHAZiGh; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-gpio+bounces-13010-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Xq3596fYbz1yCV for ; Fri, 15 Nov 2024 01:51:41 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id AFF7828259C for ; Thu, 14 Nov 2024 14:51:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 98A3E7603A; Thu, 14 Nov 2024 14:51:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="eaHAZiGh" X-Original-To: linux-gpio@vger.kernel.org Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 38CA2179BD for ; Thu, 14 Nov 2024 14:51:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595892; cv=none; b=qWNesUyfy7/Fl9hLRvoTUphCjO4uJqOgIIqObdMKLl3DKJ65APRxI+nuT9Peb5/VBD/roG1rblqXQ7qjAzZyeNeAugqX4OHtmFxFViF8d7yyrCn1Y1u2ruErTmvVTUKp2kKNQhaF9vm4m5uDcGKN8y+plWOLYJIzS79TErKrb0o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595892; c=relaxed/simple; bh=Ld8QqaHjkMywk8ju92DvpgVII2LpMVMsKwNc59ZFEZw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=soBecxzf2P+ohuxt1b2wiwAF8rLpMPRVFd6AnvbyYdbsQstxvjBRKbWbUjP4lh8Lfa0XshP2cxGDySw7etrTHhnwWiWMNAHTmXnTv6l+khplgigzINGuC7GVVLo5DOf22Gq/SG4mlFUf/QHJ+Rd2NNv+u2Ya7DS4pjYcNkLw8Tk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=eaHAZiGh; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id 6F23A20A48; Thu, 14 Nov 2024 08:51:22 -0600 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1731595882; bh=Ld8QqaHjkMywk8ju92DvpgVII2LpMVMsKwNc59ZFEZw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eaHAZiGhWdr/VsZ6eXJ9K1Q0uSJE1gJUxuPFnY9sqODB//TEnIRmEavaq5m5S2RLS i8eJIhwcPh1102+MUYkYf69XOF4R1DFvl6c+fJ/XXINS2al2Vw0xq+7q1UCUwY2cbc b/BZDems7N9DtqLwKc6iEgx3upxb1tJOLr4vGOf4= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH v2 03/23] bindings: python: loosen type requirements in public API Date: Thu, 14 Nov 2024 08:50:56 -0600 Message-Id: <20241114145116.2123714-4-vfazio@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114145116.2123714-1-vfazio@xes-inc.com> References: <20241114145116.2123714-1-vfazio@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Previously, `Chip.request_lines` and `LineRequest.reconfigure_lines` were typed to accept a config argument that was either an int, a str, or a tuple[int | str]. This had two downsides, namely: * The tuple was typed as having only a single element and not a variable number of elements. The examples and test suite relied on a variable length tuple. * The tuple type itself was overly restictive. The function implementations had no requirement that the value be a tuple, only that it was iterable if it was not a str or an int. Now, these functions accept an Iterable[int | str] instead of tuples to offer greater flexibility to callers. This change does not break compatibility for existing users. Closes: https://github.com/brgl/libgpiod/issues/102 Signed-off-by: Vincent Fazio --- bindings/python/gpiod/chip.py | 5 ++++- bindings/python/gpiod/line_request.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/bindings/python/gpiod/chip.py b/bindings/python/gpiod/chip.py index 175fcb0..1db199e 100644 --- a/bindings/python/gpiod/chip.py +++ b/bindings/python/gpiod/chip.py @@ -13,6 +13,7 @@ from .line_request import LineRequest from .line_settings import LineSettings, _line_settings_to_ext if TYPE_CHECKING: + from collections.abc import Iterable from datetime import timedelta from .chip_info import ChipInfo @@ -225,7 +226,9 @@ class Chip: def request_lines( self, - config: dict[tuple[Union[int, str]], Optional[LineSettings]], + config: dict[ + Union[Iterable[Union[int, str]], int, str], Optional[LineSettings] + ], consumer: Optional[str] = None, event_buffer_size: Optional[int] = None, output_values: Optional[dict[Union[int, str], Value]] = None, diff --git a/bindings/python/gpiod/line_request.py b/bindings/python/gpiod/line_request.py index a8e4a87..c7b32f3 100644 --- a/bindings/python/gpiod/line_request.py +++ b/bindings/python/gpiod/line_request.py @@ -148,7 +148,10 @@ class LineRequest: self._req.set_values(mapped) def reconfigure_lines( - self, config: dict[tuple[Union[int, str]], LineSettings] + self, + config: dict[ + Union[Iterable[Union[int, str]], int, str], Optional[LineSettings] + ], ) -> None: """ Reconfigure requested lines. From patchwork Thu Nov 14 14:50:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 2011433 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=xes-inc.com header.i=@xes-inc.com header.a=rsa-sha256 header.s=mail header.b=mcmzmX8P; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=linux-gpio+bounces-13007-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [IPv6:2604:1380:40f1:3f00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Xq3C24GLtz1xxN for ; Fri, 15 Nov 2024 01:56:46 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id C1F00B2AA07 for ; Thu, 14 Nov 2024 14:51:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 46C9954720; Thu, 14 Nov 2024 14:51:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="mcmzmX8P" X-Original-To: linux-gpio@vger.kernel.org Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 38CD936AF5 for ; Thu, 14 Nov 2024 14:51:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595891; cv=none; b=HbL+wnK1GEiyuzx51bheMy+AHhJT3rUKvtq0X2E38zyISyZCf9PIQz/do/VbUTORW5O9EDN9y25UOWSrsicvLzlPihHB4ivl2ZWi1xwqbpAKts+cfoGqyRz/0HdV3CXe3rXykCxflkbDXZ6K3b2h2I4LUxUy/Axv8AujlYn9Gec= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595891; c=relaxed/simple; bh=wF9pSdtjVo3E9lN0jl/IwguMz4v2m/clhyrfwxzDv3I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Dc2LVqfoeIJVxFGm06lFqTnaRMULhi11WJI/4Yqg4pGUxp3eowHAnl2dr5uR2dLlHQE8rs8yCgc4g6KtKWBB5dpk+e5nqvPIVgbrznjuD03iQcVQCdfT4XcjGZ18yEDBrxeEblzll9/vmPjjNb+wuI1U5l/Mn5dOB34WqKJuIjE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=mcmzmX8P; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id 83BBF20A91; Thu, 14 Nov 2024 08:51:22 -0600 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1731595882; bh=wF9pSdtjVo3E9lN0jl/IwguMz4v2m/clhyrfwxzDv3I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mcmzmX8P3b/qty4stMoVKsypWG/WlYUjieiiJDdNCykUkwKEFiy40KC21gpfY2N2D T02itKNpSx21apeq9vobFfU3B+IZ+Jswpbp1cUXEbuHmTMh16fZcoJNy1ET0I6dzln PZdTmguiytll6zpeOGm8lFpRgL7rqA+qGePkN+yU= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH v2 04/23] bindings: python: explicitly type gpiod.request_lines Date: Thu, 14 Nov 2024 08:50:57 -0600 Message-Id: <20241114145116.2123714-5-vfazio@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114145116.2123714-1-vfazio@xes-inc.com> References: <20241114145116.2123714-1-vfazio@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Explicitly define the arguments for `gpiod.request_lines` so there is a clearer linkage with the underlying `Chip.request_lines` interface. Signed-off-by: Vincent Fazio --- bindings/python/gpiod/__init__.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/bindings/python/gpiod/__init__.py b/bindings/python/gpiod/__init__.py index aaa0474..817c755 100644 --- a/bindings/python/gpiod/__init__.py +++ b/bindings/python/gpiod/__init__.py @@ -7,6 +7,9 @@ Python bindings for libgpiod. This module wraps the native C API of libgpiod in a set of python classes. """ +from collections.abc import Iterable +from typing import Optional, Union + from . import ( _ext, chip, @@ -82,7 +85,13 @@ def is_gpiochip_device(path: str) -> bool: return _ext.is_gpiochip_device(path) -def request_lines(path: str, *args, **kwargs) -> LineRequest: +def request_lines( + path: str, + config: dict[Union[Iterable[Union[int, str]], int, str], Optional[LineSettings]], + consumer: Optional[str] = None, + event_buffer_size: Optional[int] = None, + output_values: Optional[dict[Union[int, str], line.Value]] = None, +) -> LineRequest: """ Open a GPIO chip pointed to by 'path', request lines according to the configuration arguments, close the chip and return the request object. @@ -98,4 +107,9 @@ def request_lines(path: str, *args, **kwargs) -> LineRequest: Returns a new LineRequest object. """ with Chip(path) as chip: - return chip.request_lines(*args, **kwargs) + return chip.request_lines( + config=config, + consumer=consumer, + event_buffer_size=event_buffer_size, + output_values=output_values, + ) From patchwork Thu Nov 14 14:50:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 2011416 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=xes-inc.com header.i=@xes-inc.com header.a=rsa-sha256 header.s=mail header.b=o7Lkw8Fp; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.80.249; helo=am.mirrors.kernel.org; envelope-from=linux-gpio+bounces-13014-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [147.75.80.249]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Xq35G2ggqz1yCY for ; Fri, 15 Nov 2024 01:51:46 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id ED1A71F245E3 for ; Thu, 14 Nov 2024 14:51:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B5A1582488; Thu, 14 Nov 2024 14:51:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="o7Lkw8Fp" X-Original-To: linux-gpio@vger.kernel.org Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C678536AF5 for ; Thu, 14 Nov 2024 14:51:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595893; cv=none; b=FZru+egeR/Gm5QFekubYOqVMJ6FWLpRXDWqDAEMl2FtCbX6k9SI45HmY6IoqKvRnO1PK/sKDRCcnprx5WQnO6q/Y48R2iQQqnNbXIOWJpJVf6eoyiHRo0YCzGqZrAA3qMlEULNsWjmhSTJmyc9PzeMeCnc5qosiMxfENHySaql8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595893; c=relaxed/simple; bh=xUk2IRbdq+lHQV9yq/xb4NnV3hZjtrZmx/NDMoTL+wo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OHK7kbq56g88kU00H7TuHPUk2SF3ND1exhUJK7m3KIqFblRFErARniuwY+iXlT5arPh3luNcUl38evANimOovqUA1IAFORv/r8zgcLjnjR1wkH0vgxNcH3gD5jFGN77i3IaUiCuos81KyapRONB0iprktu4+Bg80ita3vFm71vQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=o7Lkw8Fp; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id 981B120A9C; Thu, 14 Nov 2024 08:51:22 -0600 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1731595882; bh=xUk2IRbdq+lHQV9yq/xb4NnV3hZjtrZmx/NDMoTL+wo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o7Lkw8FpYBBGSB0v4AksQ0bzeG4f2i7Y3DHZGfyIniZ7EFs/Zp5qhlHpypXIbcCRy mK3J1GJg1+aL2YV2TLJ7Euf7rhGZeRZ/AjSvOgkqF2D/VQCulFkAE1NynbNv7kwD55 M3+nys9fa7Lcxivc1WsNx2dsLNc4H+ebtNt3gO3c= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH v2 05/23] bindings: python: add type stub for the _ext module Date: Thu, 14 Nov 2024 08:50:58 -0600 Message-Id: <20241114145116.2123714-6-vfazio@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114145116.2123714-1-vfazio@xes-inc.com> References: <20241114145116.2123714-1-vfazio@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add a type stub for the compiled external module so that types and methods used from the module are accurately type checked. Signed-off-by: Vincent Fazio --- bindings/python/gpiod/_ext.pyi | 93 ++++++++++++++++++++++++++++++++++ bindings/python/setup.py | 2 +- 2 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 bindings/python/gpiod/_ext.pyi diff --git a/bindings/python/gpiod/_ext.pyi b/bindings/python/gpiod/_ext.pyi new file mode 100644 index 0000000..1beb80d --- /dev/null +++ b/bindings/python/gpiod/_ext.pyi @@ -0,0 +1,93 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +# SPDX-FileCopyrightText: 2024 Vincent Fazio + +from typing import Optional + +from .chip_info import ChipInfo +from .edge_event import EdgeEvent +from .info_event import InfoEvent +from .line import Value +from .line_info import LineInfo + +class LineSettings: + def __init__( + self, + direction: int, + edge_detection: int, + bias: int, + drive: int, + active_low: bool, + debounce_period: int, + event_clock: int, + output_value: int, + ) -> None: ... + +class LineConfig: + def __init__(self) -> None: ... + def add_line_settings(self, offsets: list[int], settings: LineSettings) -> None: ... + def set_output_values(self, global_output_values: list[Value]) -> None: ... + +class Request: + def release(self) -> None: ... + def get_values(self, offsets: list[int], values: list[Value]) -> None: ... + def set_values(self, values: dict[int, Value]) -> None: ... + def reconfigure_lines(self, line_cfg: LineConfig) -> None: ... + def read_edge_events(self, max_events: Optional[int]) -> list[EdgeEvent]: ... + @property + def chip_name(self) -> str: ... + @property + def num_lines(self) -> int: ... + @property + def offsets(self) -> list[int]: ... + @property + def fd(self) -> int: ... + +class Chip: + def __init__(self, path: str) -> None: ... + def get_info(self) -> ChipInfo: ... + def line_offset_from_id(self, id: str) -> int: ... + def get_line_info(self, offset: int, watch: bool) -> LineInfo: ... + def request_lines( + self, + line_cfg: LineConfig, + consumer: Optional[str], + event_buffer_size: Optional[int], + ) -> Request: ... + def read_info_event(self) -> InfoEvent: ... + def close(self) -> None: ... + def unwatch_line_info(self, line: int) -> None: ... + @property + def path(self) -> str: ... + @property + def fd(self) -> int: ... + +def is_gpiochip_device(path: str) -> bool: ... + +api_version: str + +# enum constants +BIAS_AS_IS: int +BIAS_DISABLED: int +BIAS_PULL_DOWN: int +BIAS_PULL_UP: int +BIAS_UNKNOWN: int +CLOCK_HTE: int +CLOCK_MONOTONIC: int +CLOCK_REALTIME: int +DIRECTION_AS_IS: int +DIRECTION_INPUT: int +DIRECTION_OUTPUT: int +DRIVE_OPEN_DRAIN: int +DRIVE_OPEN_SOURCE: int +DRIVE_PUSH_PULL: int +EDGE_BOTH: int +EDGE_EVENT_TYPE_FALLING: int +EDGE_EVENT_TYPE_RISING: int +EDGE_FALLING: int +EDGE_NONE: int +EDGE_RISING: int +INFO_EVENT_TYPE_LINE_CONFIG_CHANGED: int +INFO_EVENT_TYPE_LINE_RELEASED: int +INFO_EVENT_TYPE_LINE_REQUESTED: int +VALUE_ACTIVE: int +VALUE_INACTIVE: int diff --git a/bindings/python/setup.py b/bindings/python/setup.py index 7ab783f..0d518af 100644 --- a/bindings/python/setup.py +++ b/bindings/python/setup.py @@ -228,7 +228,7 @@ setup( name="gpiod", url="https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git", packages=find_packages(exclude=["tests", "tests.*"]), - package_data={"gpiod": ["py.typed"]}, + package_data={"gpiod": ["py.typed", "_ext.pyi"]}, python_requires=">=3.9.0", ext_modules=[gpiod_ext], cmdclass={"build_ext": build_ext, "sdist": sdist}, From patchwork Thu Nov 14 14:50:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 2011418 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=xes-inc.com header.i=@xes-inc.com header.a=rsa-sha256 header.s=mail header.b=lzBHH952; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.80.249; helo=am.mirrors.kernel.org; envelope-from=linux-gpio+bounces-13015-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [147.75.80.249]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Xq35H3Bxlz1yCV for ; Fri, 15 Nov 2024 01:51:47 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id BE3DF1F2425F for ; Thu, 14 Nov 2024 14:51:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 45AF3126C03; Thu, 14 Nov 2024 14:51:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="lzBHH952" X-Original-To: linux-gpio@vger.kernel.org Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C67CD41746 for ; Thu, 14 Nov 2024 14:51:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595894; cv=none; b=f5LSjGBdleHv9X9BO/WJiLmOka2JEk3nFL6omTuVyko+i+mqkhapz+EC3zgSGcgk67YReXiawUMxjSMC1VpoqfpxsOIqUpMpcx3KG+kBN/sKWWqJy9hNtAnMDEJV4VJ4Y5B9dHWXxENohmFWSdMH5kQCQS3NceX63E+sVYdXtmE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595894; c=relaxed/simple; bh=bsyn4Ty9/YB3fzPPG34ksDifMc5CgcOfI4R7qtg0GtQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IcWxhUCIyk7VM5QJWWz3WTnM3lOHQi/SkGOQ7Rix5UGGlAbZz+7/ag4WzxISvoMyOhoSHdxW/mBgNSCIP9M5Y7QQxF77qDUmt5ZQC86WgwEK4EBYbjfuPrJsbQNNTvkH1nSf0BQDrzG5i6TxXXEZ0JkwQ0HFKEi5rm2h8uGv5G4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=lzBHH952; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id AD13F20AA0; Thu, 14 Nov 2024 08:51:22 -0600 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1731595882; bh=bsyn4Ty9/YB3fzPPG34ksDifMc5CgcOfI4R7qtg0GtQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lzBHH952xNjyNIrpOcw4BlAwwhUrlXDLp/yhHLCE77Qxr0qxL0wS9Lexp/YyXVsw0 QqiiQR5hkHPpGHmOIZyGUHEsBhXAKfbHXrjWMAs0vt47rAx7xIP7gDqMWM2nOeGcul spFu5+mRb61vDpzywAfdLZVETQWogFwxyl7/apEY= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH v2 06/23] bindings: python: add missing method type hints Date: Thu, 14 Nov 2024 08:50:59 -0600 Message-Id: <20241114145116.2123714-7-vfazio@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114145116.2123714-1-vfazio@xes-inc.com> References: <20241114145116.2123714-1-vfazio@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add type hints for all method arguments and return values. Signed-off-by: Vincent Fazio --- bindings/python/gpiod/chip.py | 12 ++++++++++-- bindings/python/gpiod/chip_info.py | 2 +- bindings/python/gpiod/edge_event.py | 2 +- bindings/python/gpiod/exception.py | 4 ++-- bindings/python/gpiod/info_event.py | 2 +- bindings/python/gpiod/line.py | 2 +- bindings/python/gpiod/line_info.py | 2 +- bindings/python/gpiod/line_request.py | 16 ++++++++++++---- bindings/python/gpiod/line_settings.py | 4 ++-- 9 files changed, 31 insertions(+), 15 deletions(-) diff --git a/bindings/python/gpiod/chip.py b/bindings/python/gpiod/chip.py index 1db199e..bf38c7f 100644 --- a/bindings/python/gpiod/chip.py +++ b/bindings/python/gpiod/chip.py @@ -1,6 +1,8 @@ # SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski +from __future__ import annotations + from collections import Counter from errno import ENOENT from typing import TYPE_CHECKING, Optional, Union @@ -15,6 +17,7 @@ from .line_settings import LineSettings, _line_settings_to_ext if TYPE_CHECKING: from collections.abc import Iterable from datetime import timedelta + from types import TracebackType from .chip_info import ChipInfo from .info_event import InfoEvent @@ -70,14 +73,19 @@ class Chip: """ return True if self._chip else False - def __enter__(self): + def __enter__(self) -> Chip: """ Controlled execution enter callback. """ self._check_closed() return self - def __exit__(self, exc_type, exc_value, traceback) -> None: + def __exit__( + self, + exc_type: Optional[type[BaseException]], + exc_value: Optional[BaseException], + traceback: Optional[TracebackType], + ) -> None: """ Controlled execution exit callback. """ diff --git a/bindings/python/gpiod/chip_info.py b/bindings/python/gpiod/chip_info.py index 884b910..eb585d6 100644 --- a/bindings/python/gpiod/chip_info.py +++ b/bindings/python/gpiod/chip_info.py @@ -17,7 +17,7 @@ class ChipInfo: label: str num_lines: int - def __str__(self): + def __str__(self) -> str: return ''.format( self.name, self.label, self.num_lines ) diff --git a/bindings/python/gpiod/edge_event.py b/bindings/python/gpiod/edge_event.py index a8b2378..0d401d8 100644 --- a/bindings/python/gpiod/edge_event.py +++ b/bindings/python/gpiod/edge_event.py @@ -39,7 +39,7 @@ class EdgeEvent: object.__setattr__(self, "global_seqno", global_seqno) object.__setattr__(self, "line_seqno", line_seqno) - def __str__(self): + def __str__(self) -> str: return "".format( self.event_type, self.timestamp_ns, diff --git a/bindings/python/gpiod/exception.py b/bindings/python/gpiod/exception.py index f9a83c2..54208e2 100644 --- a/bindings/python/gpiod/exception.py +++ b/bindings/python/gpiod/exception.py @@ -9,7 +9,7 @@ class ChipClosedError(Exception): Error raised when an already closed chip is used. """ - def __init__(self): + def __init__(self) -> None: super().__init__("I/O operation on closed chip") @@ -18,5 +18,5 @@ class RequestReleasedError(Exception): Error raised when a released request is used. """ - def __init__(self): + def __init__(self) -> None: super().__init__("GPIO lines have been released") diff --git a/bindings/python/gpiod/info_event.py b/bindings/python/gpiod/info_event.py index 7b544aa..d9e9564 100644 --- a/bindings/python/gpiod/info_event.py +++ b/bindings/python/gpiod/info_event.py @@ -30,7 +30,7 @@ class InfoEvent: object.__setattr__(self, "timestamp_ns", timestamp_ns) object.__setattr__(self, "line_info", line_info) - def __str__(self): + def __str__(self) -> str: return "".format( self.event_type, self.timestamp_ns, self.line_info ) diff --git a/bindings/python/gpiod/line.py b/bindings/python/gpiod/line.py index 828385c..33c7368 100644 --- a/bindings/python/gpiod/line.py +++ b/bindings/python/gpiod/line.py @@ -15,7 +15,7 @@ class Value(Enum): INACTIVE = _ext.VALUE_INACTIVE ACTIVE = _ext.VALUE_ACTIVE - def __bool__(self): + def __bool__(self) -> bool: return self == self.ACTIVE diff --git a/bindings/python/gpiod/line_info.py b/bindings/python/gpiod/line_info.py index 46e1653..5ea9568 100644 --- a/bindings/python/gpiod/line_info.py +++ b/bindings/python/gpiod/line_info.py @@ -58,7 +58,7 @@ class LineInfo: self, "debounce_period", timedelta(microseconds=debounce_period_us) ) - def __str__(self): + def __str__(self) -> str: return ''.format( self.offset, self.name, diff --git a/bindings/python/gpiod/line_request.py b/bindings/python/gpiod/line_request.py index c7b32f3..0846e6b 100644 --- a/bindings/python/gpiod/line_request.py +++ b/bindings/python/gpiod/line_request.py @@ -1,6 +1,8 @@ # SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski +from __future__ import annotations + from typing import TYPE_CHECKING, Optional, Union from . import _ext @@ -11,6 +13,7 @@ from .line_settings import LineSettings, _line_settings_to_ext if TYPE_CHECKING: from collections.abc import Iterable from datetime import timedelta + from types import TracebackType from .edge_event import EdgeEvent from .line import Value @@ -42,14 +45,19 @@ class LineRequest: """ return True if self._req else False - def __enter__(self): + def __enter__(self) -> LineRequest: """ Controlled execution enter callback. """ self._check_released() return self - def __exit__(self, exc_type, exc_value, traceback): + def __exit__( + self, + exc_type: Optional[type[BaseException]], + exc_value: Optional[BaseException], + traceback: Optional[TracebackType], + ) -> None: """ Controlled execution exit callback. """ @@ -81,7 +89,7 @@ class LineRequest: """ return self.get_values([line])[0] - def _check_line_name(self, line): + def _check_line_name(self, line: Union[int, str]) -> bool: if isinstance(line, str): if line not in self._name_map: raise ValueError("unknown line name: {}".format(line)) @@ -216,7 +224,7 @@ class LineRequest: return self._req.read_edge_events(max_events) - def __str__(self): + def __str__(self) -> str: """ Return a user-friendly, human-readable description of this request. """ diff --git a/bindings/python/gpiod/line_settings.py b/bindings/python/gpiod/line_settings.py index f2811b2..6c6518d 100644 --- a/bindings/python/gpiod/line_settings.py +++ b/bindings/python/gpiod/line_settings.py @@ -27,7 +27,7 @@ class LineSettings: # __repr__ generated by @dataclass uses repr for enum members resulting in # an unusable representation as those are of the form: - def __repr__(self): + def __repr__(self) -> str: return "gpiod.LineSettings(direction=gpiod.line.{}, edge_detection=gpiod.line.{}, bias=gpiod.line.{}, drive=gpiod.line.{}, active_low={}, debounce_period={}, event_clock=gpiod.line.{}, output_value=gpiod.line.{})".format( str(self.direction), str(self.edge_detection), @@ -39,7 +39,7 @@ class LineSettings: str(self.output_value), ) - def __str__(self): + def __str__(self) -> str: return "".format( self.direction, self.edge_detection, From patchwork Thu Nov 14 14:51:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 2011414 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=xes-inc.com header.i=@xes-inc.com header.a=rsa-sha256 header.s=mail header.b=f0wNDn+U; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.80.249; helo=am.mirrors.kernel.org; envelope-from=linux-gpio+bounces-13012-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [147.75.80.249]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Xq35F2H97z1xyc for ; Fri, 15 Nov 2024 01:51:45 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E78011F242E0 for ; Thu, 14 Nov 2024 14:51:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A68DE70814; Thu, 14 Nov 2024 14:51:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="f0wNDn+U" X-Original-To: linux-gpio@vger.kernel.org Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8F5E6F307 for ; Thu, 14 Nov 2024 14:51:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595893; cv=none; b=O45mv4KAU83iAEHldMj6ZgzhhRckHm9NXbesup/n9Qm5WnAOfafLYO95ttUdqr/BRnM00WT3o7b/YsJeCXdpsjZi1snusV1RasMpEMJDmaor02YekG5aZSw4hbrUk7tjCkTc0bz5+0ubORLnpBxakCmp+ughf7g8max4ZSbCxqM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595893; c=relaxed/simple; bh=HS1GUKoL282nBRqSaaDTxIfibMjITKqb/KQdxvjE1Dg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=j77TgRkzMUpolzqaZ+U4gy6LuKvLnvwDL0QqekMSdfHBmILT7i3HhGODTrN4RifYJ4crLdypTnwnMVLKDZNABhTfrC+1PkXhqw5gp1KeB1ud7sjWwFIDBNAca6pLQX/W/sMMRYOPSwNL473euHzOR0nt9IENWjggCx/hoEshUB0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=f0wNDn+U; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id C16B220AA5; Thu, 14 Nov 2024 08:51:22 -0600 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1731595882; bh=HS1GUKoL282nBRqSaaDTxIfibMjITKqb/KQdxvjE1Dg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f0wNDn+UYW70bZi2kh3DuGzvEcio37Ac7cJo6S9cMYTrtBjmW3yZM1r5HTQjX9enE lcyqPy9JiRQ+B5hlwKt//4NzfYLZEeUXoFczxACqgc2r79RxWBbSupnFVmCJz5LtX/ UsdxY7Fjgv9gBVkNI4omx/eQ73ltoCxuOwqUPa4g= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH v2 07/23] bindings: python: add type hint for the sec variable in poll_fd Date: Thu, 14 Nov 2024 08:51:00 -0600 Message-Id: <20241114145116.2123714-8-vfazio@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114145116.2123714-1-vfazio@xes-inc.com> References: <20241114145116.2123714-1-vfazio@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The sec variable can be either a float or None, so type it accordingly to avoid complaints from type checkers. Signed-off-by: Vincent Fazio --- bindings/python/gpiod/_internal.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bindings/python/gpiod/_internal.py b/bindings/python/gpiod/_internal.py index d1e95e4..c9b5d28 100644 --- a/bindings/python/gpiod/_internal.py +++ b/bindings/python/gpiod/_internal.py @@ -9,6 +9,7 @@ __all__ = ["poll_fd"] def poll_fd(fd: int, timeout: Optional[Union[timedelta, float]] = None) -> bool: + sec: Union[float, None] if isinstance(timeout, timedelta): sec = timeout.total_seconds() else: From patchwork Thu Nov 14 14:51:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 2011419 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=xes-inc.com header.i=@xes-inc.com header.a=rsa-sha256 header.s=mail header.b=w0aKWPES; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-gpio+bounces-13018-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Xq35J5Psjz1xyc for ; Fri, 15 Nov 2024 01:51:48 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 4F993281803 for ; Thu, 14 Nov 2024 14:51:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 28952136658; Thu, 14 Nov 2024 14:51:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="w0aKWPES" X-Original-To: linux-gpio@vger.kernel.org Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C68196F2F3 for ; Thu, 14 Nov 2024 14:51:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595894; cv=none; b=otj2/7/t97fjlyLsnXSbrg3cIyIWdY8NIO0jb+dVRKuXPmNGMiv1f7BCIOLyMlS+hZ7gOvjGG2J1TxOxfL5wb3F0AkabBEMCWuzpr+e21huzHaEEXz4puCpmQibHKGKNYM4gjQjVpjuOTEUpRnIHgRz0TSsQPk8oSG3f+VIjoZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595894; c=relaxed/simple; bh=h6aB99dT/vAmCz4535pHREsxBEfHYHJ+OD68VRVBLRs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KC56uLw0jgZBfRxEKUW3yXWFzGg7NW6sZ7VWjxlyRYrgZyvNYUYYViJ8KfKr1hm09riNLDWLwiGdCfgdAJi3jeEHrd6L7VjC5SfDrnJDUIyo9BCCtI/H6RLiFK98I7cmkFhvNnXcJoOAbjf25NNX5k1xWu5Lv4S5cRXkXFKbWiM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=w0aKWPES; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id D5ED520AAC; Thu, 14 Nov 2024 08:51:22 -0600 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1731595882; bh=h6aB99dT/vAmCz4535pHREsxBEfHYHJ+OD68VRVBLRs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=w0aKWPESzAuoPzJ0u7AZI4UOUlfPsb3FtZN5NaA3A2d3N0Zq4RRAPgJwK4NzqbiXr QJV/EVVF42OTCyigV0pqiL/m7LFVIJ86TIFXMrhWyFE0MDZCsj2jHr0qw7JM4IHSQb h3KCaJLdtECRlHzyPQU9FNNBawehljX/dL8MD6KY= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH v2 08/23] bindings: python: add type hints for Chip's internal members Date: Thu, 14 Nov 2024 08:51:01 -0600 Message-Id: <20241114145116.2123714-9-vfazio@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114145116.2123714-1-vfazio@xes-inc.com> References: <20241114145116.2123714-1-vfazio@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add type hints for Chip's internal members so type checkers can ensure the code properly constrains to these types and accounts for scenarios where the values are `None`. Signed-off-by: Vincent Fazio --- bindings/python/gpiod/chip.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/python/gpiod/chip.py b/bindings/python/gpiod/chip.py index bf38c7f..69ea777 100644 --- a/bindings/python/gpiod/chip.py +++ b/bindings/python/gpiod/chip.py @@ -61,8 +61,8 @@ class Chip: path: Path to the GPIO character device file. """ - self._chip = _ext.Chip(path) - self._info = None + self._chip: Union[_ext.Chip, None] = _ext.Chip(path) + self._info: Union[ChipInfo, None] = None def __bool__(self) -> bool: """ From patchwork Thu Nov 14 14:51:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 2011426 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=xes-inc.com header.i=@xes-inc.com header.a=rsa-sha256 header.s=mail header.b=jHezGXwj; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:4601:e00::3; helo=am.mirrors.kernel.org; envelope-from=linux-gpio+bounces-13028-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [IPv6:2604:1380:4601:e00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Xq35X0DCvz1xyc for ; Fri, 15 Nov 2024 01:52:00 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E19B21F24657 for ; Thu, 14 Nov 2024 14:51:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 63B9D13C9A3; Thu, 14 Nov 2024 14:51:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="jHezGXwj" X-Original-To: linux-gpio@vger.kernel.org Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F021344C81 for ; Thu, 14 Nov 2024 14:51:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595897; cv=none; b=mT4ddfcmkwX5+1CZIFVgbg6fDKo+CiETtLawX2L9h7HZBHINKc0J8xEXilsG/6Gg2rWi31hps4sykrqd4k1OyyBenjyDrkaEhXzoagtFlF0V6ZY8igxJZppyp/RxaIuHYwV/Prl/wXLAe3V65nbVWAUyLjq3HLDKbOPcSOzTG68= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595897; c=relaxed/simple; bh=KhkKPxF8lak37r03c84CKGcuxD0tq/clEjF9bWFFxL4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rsvHkd7vDCbz74bLOJrUH5dSFjjAIOoH3RXKRj0niag+DnCF4zB/s03efaM1BUU8A3x+tlVj2wFiSfy1wbdBVpUlrWiV8ei7kiYLs+6ndXqAOe281N3rhtvdJUmM8XAL+FA8pfolU2UhbOMuV+SjZxisAIWWufWHflirAjLFD54= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=jHezGXwj; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id EA81220AAE; Thu, 14 Nov 2024 08:51:22 -0600 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1731595882; bh=KhkKPxF8lak37r03c84CKGcuxD0tq/clEjF9bWFFxL4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jHezGXwjHuN8tBfCe901xxFoBiKwDAtJ8sYVzZSCKxbzANY+mZ4TqNTw6bJOJBeQB jdxMyHpQ8Eh3Nc3rfTqzxc/yyjqhFAqdh79pZuNaRJ8xoyqGSGsa8Z/8Oei3CwS5H+ QxmAcceqbOISFFIbsN3b/4h3sYBgB2Da1tj/adiA= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH v2 09/23] bindings: python: fix Chip union-attr type errors Date: Thu, 14 Nov 2024 08:51:02 -0600 Message-Id: <20241114145116.2123714-10-vfazio@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114145116.2123714-1-vfazio@xes-inc.com> References: <20241114145116.2123714-1-vfazio@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Since `Chip._chip` is typed to be `Optional` and because type checkers may not be able to infer that an object is not `None` from an earlier call (such as `_check_closed`) it is necessary to inform type checkers of the state of the object to silence union-attr [0] errors. Instead of littering the code with "# type: ignore" comments, use casts to inform type checkers that objects are not `None`. Using `assert` is another option, however this duplicates the logic in `_check_closed` so is redundant at best and, at worst, is not a safe replacement as `assert` can be elided in optimized Python environments and these checks need to be runtime enforced. [0]: https://mypy.readthedocs.io/en/stable/error_code_list.html#check-that-attribute-exists-in-each-union-item-union-attr Signed-off-by: Vincent Fazio --- bindings/python/gpiod/chip.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/bindings/python/gpiod/chip.py b/bindings/python/gpiod/chip.py index 69ea777..482b98b 100644 --- a/bindings/python/gpiod/chip.py +++ b/bindings/python/gpiod/chip.py @@ -5,7 +5,7 @@ from __future__ import annotations from collections import Counter from errno import ENOENT -from typing import TYPE_CHECKING, Optional, Union +from typing import TYPE_CHECKING, Optional, Union, cast from . import _ext from ._internal import poll_fd @@ -101,7 +101,7 @@ class Chip: longer be used after this method is called. """ self._check_closed() - self._chip.close() + cast(_ext.Chip, self._chip).close() self._chip = None def get_info(self) -> ChipInfo: @@ -114,7 +114,7 @@ class Chip: self._check_closed() if not self._info: - self._info = self._chip.get_info() + self._info = cast(_ext.Chip, self._chip).get_info() return self._info @@ -139,7 +139,7 @@ class Chip: if not isinstance(id, int): try: - return self._chip.line_offset_from_id(id) + return cast(_ext.Chip, self._chip).line_offset_from_id(id) except OSError as ex: if ex.errno == ENOENT: try: @@ -158,7 +158,9 @@ class Chip: def _get_line_info(self, line: Union[int, str], watch: bool) -> LineInfo: self._check_closed() - return self._chip.get_line_info(self.line_offset_from_id(line), watch) + return cast(_ext.Chip, self._chip).get_line_info( + self.line_offset_from_id(line), watch + ) def get_line_info(self, line: Union[int, str]) -> LineInfo: """ @@ -196,7 +198,9 @@ class Chip: Offset or name of the line to stop watching. """ self._check_closed() - return self._chip.unwatch_line_info(self.line_offset_from_id(line)) + return cast(_ext.Chip, self._chip).unwatch_line_info( + self.line_offset_from_id(line) + ) def wait_info_event( self, timeout: Optional[Union[timedelta, float]] = None @@ -230,7 +234,7 @@ class Chip: This function may block if there are no available events in the queue. """ self._check_closed() - return self._chip.read_info_event() + return cast(_ext.Chip, self._chip).read_info_event() def request_lines( self, @@ -326,7 +330,9 @@ class Chip: if len(global_output_values): line_cfg.set_output_values(global_output_values) - req_internal = self._chip.request_lines(line_cfg, consumer, event_buffer_size) + req_internal = cast(_ext.Chip, self._chip).request_lines( + line_cfg, consumer, event_buffer_size + ) request = LineRequest(req_internal) request._chip_name = req_internal.chip_name @@ -366,7 +372,7 @@ class Chip: Filesystem path used to open this chip. """ self._check_closed() - return self._chip.path + return cast(_ext.Chip, self._chip).path @property def fd(self) -> int: @@ -374,4 +380,4 @@ class Chip: File descriptor associated with this chip. """ self._check_closed() - return self._chip.fd + return cast(_ext.Chip, self._chip).fd From patchwork Thu Nov 14 14:51:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 2011415 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=xes-inc.com header.i=@xes-inc.com header.a=rsa-sha256 header.s=mail header.b=v0l5+WTa; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:4601:e00::3; helo=am.mirrors.kernel.org; envelope-from=linux-gpio+bounces-13013-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [IPv6:2604:1380:4601:e00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Xq35F55fYz1yCV for ; Fri, 15 Nov 2024 01:51:45 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 829FA1F2439A for ; Thu, 14 Nov 2024 14:51:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A6BA181AC8; Thu, 14 Nov 2024 14:51:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="v0l5+WTa" X-Original-To: linux-gpio@vger.kernel.org Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F18EA70826 for ; Thu, 14 Nov 2024 14:51:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595893; cv=none; b=hMrAQaIy3WoMo2QoxB4sjiqo+OsSBCIZ/T3juXqhqGUEzHtqGPOcJLBnut4BvWRiNM2yFv7brEbTD93G350z01ZdT81LMWiDDO+2H0m5DU9dNcFYkJCVG8KVKZajOoS6vpjh/+nX98/xjQoPb8qW6FdAWFh3J8QT+gD1h0/g07k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595893; c=relaxed/simple; bh=97NmNPQyAOS3Xg3liYt6Z6jEdjuIn3bYI5dqPu8UCuA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gACtHSU6Ke61C3ERpxUYdEDtLwj+vEo9l8yoBwoGPwQgzlvdQpMxoDgzLqvioqq4Go+XlYRDUtLL08j8Whdev/lFSGqFXxQjvAedClHe3/vlivQ75+sdPArsuGxyXNaAdM1InuHCFAkReK7bCxfYOQ7nV6HQvXy0AEgPX/Ah7No= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=v0l5+WTa; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id 0AD7C20AB1; Thu, 14 Nov 2024 08:51:23 -0600 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1731595883; bh=97NmNPQyAOS3Xg3liYt6Z6jEdjuIn3bYI5dqPu8UCuA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v0l5+WTaVeTgCJiak1VdZflfDVzZibQCdkdcntKQRJR8vRs0Aytvc5O7hpv2lNAKm Mb4oHV7KH2aNe3UVgjgPxTWH+BzQ3Wiimwju7hPxLJ5nUFD9Kh6BO490bl72/c7Ulp t/tKFm3iLrgQuJiVexHrSD1vqi4lpoKCEp6UW3mo= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH v2 10/23] bindings: python: add type hints for LineRequest's internal members Date: Thu, 14 Nov 2024 08:51:03 -0600 Message-Id: <20241114145116.2123714-11-vfazio@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114145116.2123714-1-vfazio@xes-inc.com> References: <20241114145116.2123714-1-vfazio@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add type hints for LineRequest's internal members so type checkers can ensure the code properly constrains to these types and accounts for scenarios where the values are `None`. Signed-off-by: Vincent Fazio --- bindings/python/gpiod/line_request.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bindings/python/gpiod/line_request.py b/bindings/python/gpiod/line_request.py index 0846e6b..f8bbf64 100644 --- a/bindings/python/gpiod/line_request.py +++ b/bindings/python/gpiod/line_request.py @@ -34,7 +34,12 @@ class LineRequest: LineRequest objects can only be instantiated by a Chip parent. This is not part of stable API. """ - self._req = req + self._req: Union[_ext.Request, None] = req + self._chip_name: str + self._offsets: list[int] + self._name_map: dict[str, int] + self._offset_map: dict[int, str] + self._lines: list[Union[int, str]] def __bool__(self) -> bool: """ From patchwork Thu Nov 14 14:51:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 2011421 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=xes-inc.com header.i=@xes-inc.com header.a=rsa-sha256 header.s=mail header.b=bHBvF/5X; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:4601:e00::3; helo=am.mirrors.kernel.org; envelope-from=linux-gpio+bounces-13020-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [IPv6:2604:1380:4601:e00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Xq35M69ddz1xyc for ; Fri, 15 Nov 2024 01:51:51 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id C19801F244AD for ; Thu, 14 Nov 2024 14:51:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5E88E6F2F3; Thu, 14 Nov 2024 14:51:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="bHBvF/5X" X-Original-To: linux-gpio@vger.kernel.org Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F0454D9FE for ; Thu, 14 Nov 2024 14:51:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595895; cv=none; b=dR0lwy3/VVBG4y8fclYyn3Nisu82uiMoxgk8u9fpfbKbu4uPq+RoFMTi3vWAWc34upeTb3321+vlxjHIQ73o+2YGYbc9a8NrcInoy3Y/91l9UtGfi3fEXY5JDCSVZy9kk/dIBCVV56plNnX67euDfCpgTZRr/EJIM4tB2m/75j4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595895; c=relaxed/simple; bh=xePOxLQmu+k04jd8EiUx7g+K1U4mxeZ1DY2jQpuYac4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Hg3kL+POg+aoFTO/hJQ3TA8PyS9elgnOJmq2kx1j5HuqHgoUMbd2Ifp3L70VB00yilq1ThOZ4KqrP/i9oeArRykrHNZysLUw9LfW0CSVpc46mUqnQEdOExc4VcNaVe7gN+JZxWVMO+3YS7jdC8rrX2ItTvc1W2HtJeKtxpZeIAs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=bHBvF/5X; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id 1F1ED20AB2; Thu, 14 Nov 2024 08:51:23 -0600 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1731595883; bh=xePOxLQmu+k04jd8EiUx7g+K1U4mxeZ1DY2jQpuYac4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bHBvF/5X7wKKUy5ZjsMz4nMYUjQ6bjUB9g0t3BSSg3iFfgxgpSNqtHyRMZBI4I5Eg p8YX1kzBn0Plm/pawjatZ2ssZsMWlATqodKAnVqyZcVqWgR53cWZ2WZzGSowpGgKwz O47qx8NHZcZ5W479k7ZUwHm9zSP8QA1u4XotfAgg= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH v2 11/23] bindings: python: fix LineRequest union-attr type errors Date: Thu, 14 Nov 2024 08:51:04 -0600 Message-Id: <20241114145116.2123714-12-vfazio@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114145116.2123714-1-vfazio@xes-inc.com> References: <20241114145116.2123714-1-vfazio@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Since `LineRequest._req` is typed to be `Optional` and because type checkers may not be able to infer that an object is not `None` from an earlier call (such as `_check_released`) it is necessary to inform type checkers of the state of the object to silence union-attr [0] errors. Instead of littering the code with "# type: ignore" comments, use casts to inform type checkers that objects are not `None`. Using `assert` is another option, however this duplicates the logic in `_check_released` so is redundant at best and, at worst, is not a safe replacement as `assert` can be elided in optimized Python environments and these checks need to be runtime enforced. [0]: https://mypy.readthedocs.io/en/stable/error_code_list.html#check-that-attribute-exists-in-each-union-item-union-attr Signed-off-by: Vincent Fazio --- bindings/python/gpiod/line_request.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bindings/python/gpiod/line_request.py b/bindings/python/gpiod/line_request.py index f8bbf64..81f2517 100644 --- a/bindings/python/gpiod/line_request.py +++ b/bindings/python/gpiod/line_request.py @@ -3,7 +3,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Optional, Union +from typing import TYPE_CHECKING, Optional, Union, cast from . import _ext from ._internal import poll_fd @@ -78,7 +78,7 @@ class LineRequest: not be used after a call to this method. """ self._check_released() - self._req.release() + cast(_ext.Request, self._req).release() self._req = None def get_value(self, line: Union[int, str]) -> Value: @@ -128,7 +128,7 @@ class LineRequest: buf = [None] * len(lines) - self._req.get_values(offsets, buf) + cast(_ext.Request, self._req).get_values(offsets, buf) return buf def set_value(self, line: Union[int, str], value: Value) -> None: @@ -158,7 +158,7 @@ class LineRequest: for line in values } - self._req.set_values(mapped) + cast(_ext.Request, self._req).set_values(mapped) def reconfigure_lines( self, @@ -193,7 +193,7 @@ class LineRequest: settings = line_settings.get(offset) or LineSettings() line_cfg.add_line_settings([offset], _line_settings_to_ext(settings)) - self._req.reconfigure_lines(line_cfg) + cast(_ext.Request, self._req).reconfigure_lines(line_cfg) def wait_edge_events( self, timeout: Optional[Union[timedelta, float]] = None @@ -227,7 +227,7 @@ class LineRequest: """ self._check_released() - return self._req.read_edge_events(max_events) + return cast(_ext.Request, self._req).read_edge_events(max_events) def __str__(self) -> str: """ @@ -279,4 +279,4 @@ class LineRequest: File descriptor associated with this request. """ self._check_released() - return self._req.fd + return cast(_ext.Request, self._req).fd From patchwork Thu Nov 14 14:51:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 2011417 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=xes-inc.com header.i=@xes-inc.com header.a=rsa-sha256 header.s=mail header.b=dKuDWkVE; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.80.249; helo=am.mirrors.kernel.org; envelope-from=linux-gpio+bounces-13016-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [147.75.80.249]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Xq35H2XDCz1xyc for ; Fri, 15 Nov 2024 01:51:47 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id BA4441F246D6 for ; Thu, 14 Nov 2024 14:51:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D433E136327; Thu, 14 Nov 2024 14:51:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="dKuDWkVE" X-Original-To: linux-gpio@vger.kernel.org Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1EFE643AD2 for ; Thu, 14 Nov 2024 14:51:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595894; cv=none; b=sX8uq38e5f/SCyloQGOJg/RUwmIuGMthacHx1EZZxuJPMOze4hjP1f4d9lUtZUGjCTFiXIfASfFWUjaNojM5yf7BSWOQwBbGrEpz1/+QiiaveEip7CJK4FwW5i+HMRAE7LBp3zy6SjC9suypbB9hpWIrtPspD7TH04PBhA5keAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595894; c=relaxed/simple; bh=ZAPje8Lv+/hR8Gn0fHhrkcvWtUex3wV0GRH+5dkkX1Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LEXuRWGQj5FzuiKsZcnDZkN7sjtqOG/1UTalCP/JXIwK2svPjGZdG8FAuwYWohZ1HGTjHapPv6kAyKobIRN4EfjIMJeGl6Gkhas1dZ4odK2gstVMZebCboJw3fFELeb1QcFWEL8u89JXHJitI6TxMLpRIDQqRg9E3/NBntZGLYI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=dKuDWkVE; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id 3389520AB4; Thu, 14 Nov 2024 08:51:23 -0600 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1731595883; bh=ZAPje8Lv+/hR8Gn0fHhrkcvWtUex3wV0GRH+5dkkX1Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dKuDWkVEJdN/+J4NX0l86qMtkvgrUoc7Yv/So9HLzGy6oMLZELjNilT0oCx/qI+0m XpvqYLNWY3nvPouejsDhL5caw4HsieqO3GZ+HRDM8lnviwYyoiuYmGU5keb7RMBtuX 4R0Dp3xOUoiqCoGh2V2T3pWNuEDi5iAStbA9C/NI= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH v2 12/23] bindings: python: convert lines to offsets in LineRequest Date: Thu, 14 Nov 2024 08:51:05 -0600 Message-Id: <20241114145116.2123714-13-vfazio@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114145116.2123714-1-vfazio@xes-inc.com> References: <20241114145116.2123714-1-vfazio@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Remove `_check_line_name` in favor of a new function, `_line_to_offset`, that converts a line reference to an offset. This new function helps narrow types and simplifies the iteration logic that is used to build objects to interface with `_ext.Request`. Signed-off-by: Vincent Fazio --- bindings/python/gpiod/line_request.py | 29 +++++++++++---------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/bindings/python/gpiod/line_request.py b/bindings/python/gpiod/line_request.py index 81f2517..3f181c9 100644 --- a/bindings/python/gpiod/line_request.py +++ b/bindings/python/gpiod/line_request.py @@ -94,14 +94,15 @@ class LineRequest: """ return self.get_values([line])[0] - def _check_line_name(self, line: Union[int, str]) -> bool: - if isinstance(line, str): - if line not in self._name_map: - raise ValueError("unknown line name: {}".format(line)) - - return True - - return False + def _line_to_offset(self, line: Union[int, str]) -> int: + if isinstance(line, int): + return line + else: + _line: Union[int, None] + if (_line := self._name_map.get(line)) is None: + raise ValueError(f"unknown line name: {line}") + else: + return _line def get_values( self, lines: Optional[Iterable[Union[int, str]]] = None @@ -121,10 +122,7 @@ class LineRequest: lines = lines or self._lines - offsets = [ - self._name_map[line] if self._check_line_name(line) else line - for line in lines - ] + offsets = [self._line_to_offset(line) for line in lines] buf = [None] * len(lines) @@ -153,10 +151,7 @@ class LineRequest: """ self._check_released() - mapped = { - self._name_map[line] if self._check_line_name(line) else line: values[line] - for line in values - } + mapped = {self._line_to_offset(line): value for line, value in values.items()} cast(_ext.Request, self._req).set_values(mapped) @@ -186,7 +181,7 @@ class LineRequest: lines = [lines] for line in lines: - offset = self._name_map[line] if self._check_line_name(line) else line + offset = self._line_to_offset(line) line_settings[offset] = settings for offset in self.offsets: From patchwork Thu Nov 14 14:51:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 2011430 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=xes-inc.com header.i=@xes-inc.com header.a=rsa-sha256 header.s=mail header.b=HSs26u5j; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=linux-gpio+bounces-13017-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [IPv6:2604:1380:40f1:3f00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Xq38g2w2Gz1xyc for ; Fri, 15 Nov 2024 01:54:43 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 792F3B2835F for ; Thu, 14 Nov 2024 14:51:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D1C6B1339A4; Thu, 14 Nov 2024 14:51:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="HSs26u5j" X-Original-To: linux-gpio@vger.kernel.org Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1EF8A179BD for ; Thu, 14 Nov 2024 14:51:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595894; cv=none; b=G8S7JJ5crPg9Iv0znEZVqaUw6yMKoxi87zL0X7orvHTxqtkdhD6OnoNzHcYYHJZiRvmfhBhOzPMrqkO4EkiAse+UOL+Nl7pUpDADpQ34jYmCRDBmAlRxaRfCL36qV6ALHIJrjFWj//PZjR2D/5mxZx4x+TNYn+WZjA47o8+Oye4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595894; c=relaxed/simple; bh=PoaQF24GHlIxevYL09mpbGzqdeEWvku20jXh44DvccE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qYb49dhhE115LlafYwadPXeCCnXsb1BOGI560iOzcc7i1IKGXptGM+6xIDGD64KOKcwfUqiV7qMengXneiEGBxmW3+EwmqU+/nofBj55cFme52wXk3l99iOmTP8pzs26SIWO4RQtdvLpOMy50KGaW1U+K2HK4uM+/P8vH5TIhKA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=HSs26u5j; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id 480E720AB5; Thu, 14 Nov 2024 08:51:23 -0600 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1731595883; bh=PoaQF24GHlIxevYL09mpbGzqdeEWvku20jXh44DvccE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HSs26u5jNF/wT17KLqUGwrm8JCGR6PP33SAKoeEFdMl+5Cbrfob0RZwBr8ilOpGtD KUA1vnQljdqWdZmB2W0ezrP1QqdJO4o4qTZUlEw86RZkZd7WUGr5Mus4OBsh8q9CVr AM/NtxBxN175HAIje0FLCtSjxGjF0hgBH6bhQOQU= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH v2 13/23] bindings: python: cast return value of LineRequest.get_values Date: Thu, 14 Nov 2024 08:51:06 -0600 Message-Id: <20241114145116.2123714-14-vfazio@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114145116.2123714-1-vfazio@xes-inc.com> References: <20241114145116.2123714-1-vfazio@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The `values` argument of `_ext.Request.get_values` uses a preallocated `list[None]` as a buffer that is populated with `Value`s by the external module that are then returned from the function. Use `cast` to inform the type checker it's a `list[Value]` despite how it's allocated. Also, as `lines` is typed as an `Iterable`, there is no guarantee it has a `__len__` method. Instead, use the size of the `offsets` array to allocate the buffer. Signed-off-by: Vincent Fazio --- bindings/python/gpiod/line_request.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/python/gpiod/line_request.py b/bindings/python/gpiod/line_request.py index 3f181c9..7327274 100644 --- a/bindings/python/gpiod/line_request.py +++ b/bindings/python/gpiod/line_request.py @@ -8,6 +8,7 @@ from typing import TYPE_CHECKING, Optional, Union, cast from . import _ext from ._internal import poll_fd from .exception import RequestReleasedError +from .line import Value from .line_settings import LineSettings, _line_settings_to_ext if TYPE_CHECKING: @@ -16,7 +17,6 @@ if TYPE_CHECKING: from types import TracebackType from .edge_event import EdgeEvent - from .line import Value __all__ = ["LineRequest"] @@ -124,7 +124,7 @@ class LineRequest: offsets = [self._line_to_offset(line) for line in lines] - buf = [None] * len(lines) + buf = cast(list[Value], [None] * len(offsets)) cast(_ext.Request, self._req).get_values(offsets, buf) return buf From patchwork Thu Nov 14 14:51:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 2011420 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=xes-inc.com header.i=@xes-inc.com header.a=rsa-sha256 header.s=mail header.b=EiVt6xR2; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=139.178.88.99; helo=sv.mirrors.kernel.org; envelope-from=linux-gpio+bounces-13019-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [139.178.88.99]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Xq35K0fKYz1yCV for ; Fri, 15 Nov 2024 01:51:48 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B3647282345 for ; Thu, 14 Nov 2024 14:51:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 38DF343AD2; Thu, 14 Nov 2024 14:51:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="EiVt6xR2" X-Original-To: linux-gpio@vger.kernel.org Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 558C45336E for ; Thu, 14 Nov 2024 14:51:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595895; cv=none; b=cy69hBvssxOTwQJOQWJQYIFP/wPKbJzvxrvhOEFZkducq55gGJdEWqkOtZ8QAdKjG8K4SKYQUPeTwY8cDYvm6Ze0mtcpQR85XQHvlNsOQoYiHQTmjG147z9tmr+ZXTBFjJXPEU+QvRwfUsbJqtdzFLL0d3JDld/P97SJEvgWfl0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595895; c=relaxed/simple; bh=cVk+e6AsuIimpq84ak7dHq55SU4PGwPcbCxpMGoE7lw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=M0jGU1lCkacljjVSKSgINO7ZYRWCaIoevDMxQ71/yfnkbzi6pyogN+Qp1OmkP9OJkf7tg3mWLQvpsF3QX+8S9VJqSyx51UxjDhxo2ofLt3bsX5+XdJuhaCJ0hZ+hOWsDug36XkXBtCgSB9USCUsA1iGGdrAYUsh+UJnhKOERzsQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=EiVt6xR2; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id 5CA8420AB6; Thu, 14 Nov 2024 08:51:23 -0600 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1731595883; bh=cVk+e6AsuIimpq84ak7dHq55SU4PGwPcbCxpMGoE7lw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EiVt6xR2/i/xJnxLkd7yNCA6aMfr8bxbgei2yBApVR/YIv49M+kzxgmx/YamIoAB4 boOsyJJx4/9NpUtYIKxhK2TQaltaB8coE/3/xVZmau5aPg2xOobGqeQUYlNdPNpHPd WoeT+tiPOnEC+7wygB4koGi++nDx8N5F5ce1Toqc= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH v2 14/23] bindings: python: selectively use f-strings Date: Thu, 14 Nov 2024 08:51:07 -0600 Message-Id: <20241114145116.2123714-15-vfazio@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114145116.2123714-1-vfazio@xes-inc.com> References: <20241114145116.2123714-1-vfazio@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Since their inclusion in Python 3.6, f-strings have become the preferred way to format strings with variable values as they are generally more readable as the value substitution is in place and doesn't have to be parsed from the list or arguments to `.format()`. Where it does not impact readability (when the line is <120 characters), swap usage of `.format()` to an f-string. For lines that are not converted, inform the linter to ignore attempts to upgrade those instances to f-strings [0] [0]: https://docs.astral.sh/ruff/rules/f-string/ Signed-off-by: Vincent Fazio --- bindings/python/gpiod/chip.py | 10 +++------- bindings/python/gpiod/chip_info.py | 4 +--- bindings/python/gpiod/edge_event.py | 2 +- bindings/python/gpiod/info_event.py | 4 +--- bindings/python/gpiod/line_info.py | 2 +- bindings/python/gpiod/line_request.py | 4 +--- bindings/python/gpiod/line_settings.py | 4 ++-- 7 files changed, 10 insertions(+), 20 deletions(-) diff --git a/bindings/python/gpiod/chip.py b/bindings/python/gpiod/chip.py index 482b98b..30201b5 100644 --- a/bindings/python/gpiod/chip.py +++ b/bindings/python/gpiod/chip.py @@ -282,9 +282,7 @@ class Chip: ).items(): if count != 1: raise ValueError( - "line must be configured exactly once - offset {} repeats".format( - offset - ) + f"line must be configured exactly once - offset {offset} repeats" ) # If we have global output values - map line names to offsets @@ -353,7 +351,7 @@ class Chip: if not self._chip: return "" - return 'gpiod.Chip("{}")'.format(self.path) + return f'gpiod.Chip("{self.path}")' def __str__(self) -> str: """ @@ -362,9 +360,7 @@ class Chip: if not self._chip: return "" - return ''.format( - self.path, self.fd, self.get_info() - ) + return f'' @property def path(self) -> str: diff --git a/bindings/python/gpiod/chip_info.py b/bindings/python/gpiod/chip_info.py index eb585d6..3306af2 100644 --- a/bindings/python/gpiod/chip_info.py +++ b/bindings/python/gpiod/chip_info.py @@ -18,6 +18,4 @@ class ChipInfo: num_lines: int def __str__(self) -> str: - return ''.format( - self.name, self.label, self.num_lines - ) + return f'' diff --git a/bindings/python/gpiod/edge_event.py b/bindings/python/gpiod/edge_event.py index 0d401d8..7f5cd4d 100644 --- a/bindings/python/gpiod/edge_event.py +++ b/bindings/python/gpiod/edge_event.py @@ -40,7 +40,7 @@ class EdgeEvent: object.__setattr__(self, "line_seqno", line_seqno) def __str__(self) -> str: - return "".format( + return "".format( # noqa: UP032 self.event_type, self.timestamp_ns, self.line_offset, diff --git a/bindings/python/gpiod/info_event.py b/bindings/python/gpiod/info_event.py index d9e9564..4a86697 100644 --- a/bindings/python/gpiod/info_event.py +++ b/bindings/python/gpiod/info_event.py @@ -31,6 +31,4 @@ class InfoEvent: object.__setattr__(self, "line_info", line_info) def __str__(self) -> str: - return "".format( - self.event_type, self.timestamp_ns, self.line_info - ) + return f"" diff --git a/bindings/python/gpiod/line_info.py b/bindings/python/gpiod/line_info.py index 5ea9568..1aca142 100644 --- a/bindings/python/gpiod/line_info.py +++ b/bindings/python/gpiod/line_info.py @@ -59,7 +59,7 @@ class LineInfo: ) def __str__(self) -> str: - return ''.format( + return ''.format( # noqa: UP032 self.offset, self.name, self.used, diff --git a/bindings/python/gpiod/line_request.py b/bindings/python/gpiod/line_request.py index 7327274..9471442 100644 --- a/bindings/python/gpiod/line_request.py +++ b/bindings/python/gpiod/line_request.py @@ -231,9 +231,7 @@ class LineRequest: if not self._req: return "" - return ''.format( - self.chip_name, self.num_lines, self.offsets, self.fd - ) + return f'' @property def chip_name(self) -> str: diff --git a/bindings/python/gpiod/line_settings.py b/bindings/python/gpiod/line_settings.py index 6c6518d..2aca71c 100644 --- a/bindings/python/gpiod/line_settings.py +++ b/bindings/python/gpiod/line_settings.py @@ -28,7 +28,7 @@ class LineSettings: # __repr__ generated by @dataclass uses repr for enum members resulting in # an unusable representation as those are of the form: def __repr__(self) -> str: - return "gpiod.LineSettings(direction=gpiod.line.{}, edge_detection=gpiod.line.{}, bias=gpiod.line.{}, drive=gpiod.line.{}, active_low={}, debounce_period={}, event_clock=gpiod.line.{}, output_value=gpiod.line.{})".format( + return "gpiod.LineSettings(direction=gpiod.line.{}, edge_detection=gpiod.line.{}, bias=gpiod.line.{}, drive=gpiod.line.{}, active_low={}, debounce_period={}, event_clock=gpiod.line.{}, output_value=gpiod.line.{})".format( # noqa: UP032 str(self.direction), str(self.edge_detection), str(self.bias), @@ -40,7 +40,7 @@ class LineSettings: ) def __str__(self) -> str: - return "".format( + return "".format( # noqa: UP032 self.direction, self.edge_detection, self.bias, From patchwork Thu Nov 14 14:51:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 2011422 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=xes-inc.com header.i=@xes-inc.com header.a=rsa-sha256 header.s=mail header.b=P4C8kTHL; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.80.249; helo=am.mirrors.kernel.org; envelope-from=linux-gpio+bounces-13021-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [147.75.80.249]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Xq35P4Zqbz1xyc for ; Fri, 15 Nov 2024 01:51:53 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 550C41F24355 for ; Thu, 14 Nov 2024 14:51:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E49FB13AD39; Thu, 14 Nov 2024 14:51:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="P4C8kTHL" X-Original-To: linux-gpio@vger.kernel.org Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F0E8126BEE for ; Thu, 14 Nov 2024 14:51:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595895; cv=none; b=AcoejGOOxM+sNuZwNCVzIZHImKxbk2rZHQ+Ba7UAMm9lsoFzcITtm1aZtprFL/zdwn+JkSfdfwz2FqOlD3yy+/s5zjJJKDVTUr2ze+XKY7gmIZZEMEvv1SxeIwkdSmgLEjlOGLWb0rG2bmQuh7xwJRdI8AFcAGQbUEKqgOVlMQI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595895; c=relaxed/simple; bh=dtQo05EoHgKE6Aqc8UbCYiRwjNavdVqKKbLEI0f3FoU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZIJ33qAx2xlkO8qPDgj8cs2K8F9Brk6MzxYwBkH/msd4xj1D7JW+Zwiy+40Z7K9wTzvqIz35Zkdux6RpP6d2jQThUgzAzWs4IeXdp72Ff636v+L9lBj1cbku4YGKALF0cJkukEdZJ2Z6TUcyv+NDUtO6ea20KnweoRBnV4J2vew= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=P4C8kTHL; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id 7128E20AB7; Thu, 14 Nov 2024 08:51:23 -0600 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1731595883; bh=dtQo05EoHgKE6Aqc8UbCYiRwjNavdVqKKbLEI0f3FoU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P4C8kTHL5MNBa99dOW9fMv2ZbOWtK39hQD1J6l0GLEbCfzbYwxDaxIRiPgYCjtvVX yamygAx4BzYoLAGWmbSpHb4S0Tv0G8E0er43Aa03GMm9+bD4CgbYs3bOZEAyQr6nLu 2e3KvTTaPZb7Et03YYxQI+ESg4JjIFWEVBKesZCI= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH v2 15/23] bindings: python: tests: fix duplicate test name Date: Thu, 14 Nov 2024 08:51:08 -0600 Message-Id: <20241114145116.2123714-16-vfazio@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114145116.2123714-1-vfazio@xes-inc.com> References: <20241114145116.2123714-1-vfazio@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Previously, the `test_rising_edge_event` test was defined twice. The second instance of the test actually tested the falling edge event and was shadowing the first test which tested the rising edge event. Now, the second instance is renamed to `test_falling_edge_event` to reflect what it is testing and to avoid the naming conflict. Signed-off-by: Vincent Fazio --- bindings/python/tests/tests_edge_event.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/python/tests/tests_edge_event.py b/bindings/python/tests/tests_edge_event.py index 17b2702..68ab17e 100644 --- a/bindings/python/tests/tests_edge_event.py +++ b/bindings/python/tests/tests_edge_event.py @@ -118,7 +118,7 @@ class WaitingForEdgeEvents(TestCase): self.assertFalse(req.wait_edge_events(timedelta(microseconds=10000))) - def test_rising_edge_event(self): + def test_falling_edge_event(self): with gpiod.request_lines( self.sim.dev_path, {6: gpiod.LineSettings(edge_detection=Edge.FALLING)} ) as req: From patchwork Thu Nov 14 14:51:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 2011427 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=xes-inc.com header.i=@xes-inc.com header.a=rsa-sha256 header.s=mail header.b=itZuNDWO; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-gpio+bounces-13030-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Xq35X3yTYz1yCV for ; Fri, 15 Nov 2024 01:52:00 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 5130B282468 for ; Thu, 14 Nov 2024 14:51:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 56B0654720; Thu, 14 Nov 2024 14:51:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="itZuNDWO" X-Original-To: linux-gpio@vger.kernel.org Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A99436AF5 for ; Thu, 14 Nov 2024 14:51:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595898; cv=none; b=GmuvUtlW3aIu0ipkg9/woyk5BsbOT8pIk1fEhZGo+Fe8VFPu13kzFnqmce97Xk5ZZ6lRo9qBPzt96J3DwChQhRpyUGwXS+2tl42vFevAVQkpsy71RBGbwTN6z1QW+iLpFGiFw6TMoNZwnDBYqFs4qIQdNLQAWpXBLFX35B/2zwo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595898; c=relaxed/simple; bh=vpgqjTRjvH2hDTv+KIRi22Hv4ChI0YVrwWYMdkJw4JQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KR2kVVULnsPivajmCRVb8oV7Zu5jBxkLkp2OeEONkKJdlIx+Gap9LpvXN7W+AL0xXBOl/GiMEU44mK8Ugi/ZdFEzxlGyj7r3RKNHa4e+mjVnJNitPH4vt4e95jZqxKdEYTXeEuco20PGW55G0u/IyT17FgZxCSC5MfwALK5WbDs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=itZuNDWO; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id 85D3020AB8; Thu, 14 Nov 2024 08:51:23 -0600 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1731595883; bh=vpgqjTRjvH2hDTv+KIRi22Hv4ChI0YVrwWYMdkJw4JQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=itZuNDWOhP8+SGxZnSNgagTcMjMyOt/9JdTMcDd1kMjFfPCSHNO3L0zYgj9LDqigw zR65HpacjswNZ0DaYBebtgsTC+Agd/9FlhocmS/Q8k8ACzj+NdGdyfYOodmD2FD7Iw FFccKe1fOB0WeKyQpPuIlKRWaru5Q1uvcbAGmjsE= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH v2 16/23] bindings: python: tests: clean up imports and exports Date: Thu, 14 Nov 2024 08:51:09 -0600 Message-Id: <20241114145116.2123714-17-vfazio@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114145116.2123714-1-vfazio@xes-inc.com> References: <20241114145116.2123714-1-vfazio@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Remove unused imports and sort the remainder following isort rules. Update the submodules to use `__all__` to advertise available imports. Remove an unnecessary blank line in the VersionString class to abide by the ruff formatter's rules (compatible with black's formatting). Signed-off-by: Vincent Fazio --- bindings/python/tests/__init__.py | 2 -- bindings/python/tests/__main__.py | 5 ++--- bindings/python/tests/gpiosim/__init__.py | 2 ++ bindings/python/tests/gpiosim/chip.py | 3 ++- bindings/python/tests/procname/__init__.py | 2 ++ bindings/python/tests/tests_chip.py | 5 +++-- bindings/python/tests/tests_chip_info.py | 3 ++- bindings/python/tests/tests_edge_event.py | 9 +++++---- bindings/python/tests/tests_info_event.py | 10 +++++----- bindings/python/tests/tests_line.py | 3 ++- bindings/python/tests/tests_line_info.py | 12 ++++++------ bindings/python/tests/tests_line_request.py | 6 +++--- bindings/python/tests/tests_line_settings.py | 7 +++---- bindings/python/tests/tests_module.py | 7 +++---- 14 files changed, 40 insertions(+), 36 deletions(-) diff --git a/bindings/python/tests/__init__.py b/bindings/python/tests/__init__.py index 02f4e8d..2374e81 100644 --- a/bindings/python/tests/__init__.py +++ b/bindings/python/tests/__init__.py @@ -2,8 +2,6 @@ # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski import os -import unittest - from distutils.version import LooseVersion required_kernel_version = LooseVersion("5.19.0") diff --git a/bindings/python/tests/__main__.py b/bindings/python/tests/__main__.py index ea4143f..8b4260d 100644 --- a/bindings/python/tests/__main__.py +++ b/bindings/python/tests/__main__.py @@ -4,17 +4,16 @@ import unittest +from . import procname from .tests_chip import * from .tests_chip_info import * from .tests_edge_event import * from .tests_info_event import * from .tests_line import * from .tests_line_info import * +from .tests_line_request import * from .tests_line_settings import * from .tests_module import * -from .tests_line_request import * - -from . import procname procname.set_process_name("python-gpiod") diff --git a/bindings/python/tests/gpiosim/__init__.py b/bindings/python/tests/gpiosim/__init__.py index f65e413..64a1551 100644 --- a/bindings/python/tests/gpiosim/__init__.py +++ b/bindings/python/tests/gpiosim/__init__.py @@ -2,3 +2,5 @@ # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski from .chip import Chip + +__all__ = ["Chip"] diff --git a/bindings/python/tests/gpiosim/chip.py b/bindings/python/tests/gpiosim/chip.py index 6af883e..691bfe1 100644 --- a/bindings/python/tests/gpiosim/chip.py +++ b/bindings/python/tests/gpiosim/chip.py @@ -1,10 +1,11 @@ # SPDX-License-Identifier: GPL-2.0-or-later # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski -from . import _ext from enum import Enum from typing import Optional +from . import _ext + class Chip: """ diff --git a/bindings/python/tests/procname/__init__.py b/bindings/python/tests/procname/__init__.py index af6abdd..436ff40 100644 --- a/bindings/python/tests/procname/__init__.py +++ b/bindings/python/tests/procname/__init__.py @@ -2,3 +2,5 @@ # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski from ._ext import set_process_name + +__all__ = ["set_process_name"] diff --git a/bindings/python/tests/tests_chip.py b/bindings/python/tests/tests_chip.py index bd4ae34..9110beb 100644 --- a/bindings/python/tests/tests_chip.py +++ b/bindings/python/tests/tests_chip.py @@ -2,12 +2,13 @@ # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski import errno -import gpiod import os +from unittest import TestCase + +import gpiod from . import gpiosim from .helpers import LinkGuard -from unittest import TestCase class ChipConstructor(TestCase): diff --git a/bindings/python/tests/tests_chip_info.py b/bindings/python/tests/tests_chip_info.py index d392ec3..9474f38 100644 --- a/bindings/python/tests/tests_chip_info.py +++ b/bindings/python/tests/tests_chip_info.py @@ -1,10 +1,11 @@ # SPDX-License-Identifier: GPL-2.0-or-later # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski +from unittest import TestCase + import gpiod from . import gpiosim -from unittest import TestCase class ChipInfoProperties(TestCase): diff --git a/bindings/python/tests/tests_edge_event.py b/bindings/python/tests/tests_edge_event.py index 68ab17e..7e7fada 100644 --- a/bindings/python/tests/tests_edge_event.py +++ b/bindings/python/tests/tests_edge_event.py @@ -1,16 +1,17 @@ # SPDX-License-Identifier: GPL-2.0-or-later # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski -import gpiod import time - -from . import gpiosim from datetime import timedelta from functools import partial -from gpiod.line import Direction, Edge from threading import Thread from unittest import TestCase +import gpiod +from gpiod.line import Direction, Edge + +from . import gpiosim + EventType = gpiod.EdgeEvent.Type Pull = gpiosim.Chip.Pull diff --git a/bindings/python/tests/tests_info_event.py b/bindings/python/tests/tests_info_event.py index a226e52..bbdbc0f 100644 --- a/bindings/python/tests/tests_info_event.py +++ b/bindings/python/tests/tests_info_event.py @@ -3,17 +3,17 @@ import datetime import errno -import gpiod import threading import time -import unittest - -from . import gpiosim from dataclasses import FrozenInstanceError from functools import partial -from gpiod.line import Direction from unittest import TestCase +import gpiod +from gpiod.line import Direction + +from . import gpiosim + EventType = gpiod.InfoEvent.Type diff --git a/bindings/python/tests/tests_line.py b/bindings/python/tests/tests_line.py index 70aa09b..2182567 100644 --- a/bindings/python/tests/tests_line.py +++ b/bindings/python/tests/tests_line.py @@ -1,9 +1,10 @@ # SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-FileCopyrightText: 2024 Kent Gibson -from gpiod.line import Value from unittest import TestCase +from gpiod.line import Value + class LineValue(TestCase): def test_cast_bool(self): diff --git a/bindings/python/tests/tests_line_info.py b/bindings/python/tests/tests_line_info.py index 2779e7a..79281a8 100644 --- a/bindings/python/tests/tests_line_info.py +++ b/bindings/python/tests/tests_line_info.py @@ -1,17 +1,17 @@ # SPDX-License-Identifier: GPL-2.0-or-later # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski -import errno +from unittest import TestCase + import gpiod -import unittest +from gpiod.line import Bias, Clock, Direction, Drive from . import gpiosim -from gpiod.line import Direction, Bias, Drive, Clock HogDir = gpiosim.Chip.Direction -class GetLineInfo(unittest.TestCase): +class GetLineInfo(TestCase): def setUp(self): self.sim = gpiosim.Chip( num_lines=4, @@ -49,7 +49,7 @@ class GetLineInfo(unittest.TestCase): self.chip.get_line_info() -class LinePropertiesCanBeRead(unittest.TestCase): +class LinePropertiesCanBeRead(TestCase): def test_basic_properties(self): sim = gpiosim.Chip( num_lines=8, @@ -86,7 +86,7 @@ class LinePropertiesCanBeRead(unittest.TestCase): self.assertEqual(info6.debounce_period.total_seconds(), 0.0) -class LineInfoStringRepresentation(unittest.TestCase): +class LineInfoStringRepresentation(TestCase): def test_line_info_str(self): sim = gpiosim.Chip( line_names={0: "foo"}, hogs={0: ("hogger", HogDir.OUTPUT_HIGH)} diff --git a/bindings/python/tests/tests_line_request.py b/bindings/python/tests/tests_line_request.py index 285c9f1..c3e86c5 100644 --- a/bindings/python/tests/tests_line_request.py +++ b/bindings/python/tests/tests_line_request.py @@ -1,12 +1,12 @@ # SPDX-License-Identifier: GPL-2.0-or-later # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski -import errno +from unittest import TestCase + import gpiod +from gpiod.line import Clock, Direction, Drive, Edge, Value from . import gpiosim -from gpiod.line import Clock, Direction, Drive, Edge, Value -from unittest import TestCase Pull = gpiosim.Chip.Pull SimVal = gpiosim.Chip.Value diff --git a/bindings/python/tests/tests_line_settings.py b/bindings/python/tests/tests_line_settings.py index 83be3d9..832ac8a 100644 --- a/bindings/python/tests/tests_line_settings.py +++ b/bindings/python/tests/tests_line_settings.py @@ -2,12 +2,11 @@ # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski import datetime -import gpiod - -from . import gpiosim -from gpiod.line import Direction, Edge, Bias, Drive, Value, Clock from unittest import TestCase +import gpiod +from gpiod.line import Bias, Clock, Direction, Drive, Edge, Value + class LineSettingsConstructor(TestCase): def test_default_values(self): diff --git a/bindings/python/tests/tests_module.py b/bindings/python/tests/tests_module.py index c6f07a6..f46729f 100644 --- a/bindings/python/tests/tests_module.py +++ b/bindings/python/tests/tests_module.py @@ -1,13 +1,13 @@ # SPDX-License-Identifier: GPL-2.0-or-later # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski -import gpiod import os -import unittest +from unittest import TestCase + +import gpiod from . import gpiosim from .helpers import LinkGuard -from unittest import TestCase class IsGPIOChip(TestCase): @@ -50,7 +50,6 @@ class IsGPIOChip(TestCase): class VersionString(TestCase): - VERSION_PATTERN = "^\\d+\\.\\d+(\\.\\d+|\\-devel|\\-rc\\d+)?$" def test_api_version_string(self): From patchwork Thu Nov 14 14:51:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 2011431 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=xes-inc.com header.i=@xes-inc.com header.a=rsa-sha256 header.s=mail header.b=Q5sT6LpH; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=linux-gpio+bounces-13023-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [IPv6:2604:1380:40f1:3f00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Xq39N69JPz1xxN for ; Fri, 15 Nov 2024 01:55:20 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id CAFFDB2D726 for ; Thu, 14 Nov 2024 14:51:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 49F0513B288; Thu, 14 Nov 2024 14:51:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="Q5sT6LpH" X-Original-To: linux-gpio@vger.kernel.org Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D202126BED for ; Thu, 14 Nov 2024 14:51:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595896; cv=none; b=gr7qhfbNf6k5pKJd7ms8fjqPTbWfprjwCRvr/UOt59YC1LpWyidzh1o1f0F8/jB+IWuJFEQt5VTRtJIxMWecu8Ke6Y32ZW7DccanRAKI2Fnfa2JJJ+F9VnWAGxVQhsd7Kut/YfXC9lhgEX/baKM/6B6IyxogpGdc/GJQbraTt5s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595896; c=relaxed/simple; bh=McWFR3uOMhE5eTI/8tBCKLAIlJJG+8U1ZkAEI8sdYZU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NsQ5OBHj+Z9yOYDG//MKbkKIVsGhFX5Ec+FXnAEZySrzFlL479XAXcX/lxPQbz66aIJtCWrPLYnnrCkn4luBYdJHqRr1zoWW/Tf8cOCrbs9Whic4XQKDlVrdcu5x6p4RWfl7FeNSLZ5lTij8fzwEz1yM7ujXjSdpKjuSQ7XLOpY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=Q5sT6LpH; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id 9B33720AB9; Thu, 14 Nov 2024 08:51:23 -0600 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1731595883; bh=McWFR3uOMhE5eTI/8tBCKLAIlJJG+8U1ZkAEI8sdYZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q5sT6LpHIPfLdYKYpvD5V9T6VYaxK2kDZtTc5Brs3mM4yrBXI03Hh+Fwuxvb0OzS5 u9LFMZzUECxcXZmZbjfDntHOjPWVKE++2ry39rMuqvRoXMRxpdwsbF1QBr/WMji1DE aM5fTqPvddfWzQ1YjiLUGSyjwfn0Ao02AVr+s8PE= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH v2 17/23] bindings: python: tests: make EventType private to prevent export Date: Thu, 14 Nov 2024 08:51:10 -0600 Message-Id: <20241114145116.2123714-18-vfazio@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114145116.2123714-1-vfazio@xes-inc.com> References: <20241114145116.2123714-1-vfazio@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Previously, both tests_edge_event and tests_info_event had a public module level EventType member. The __main__ module for unittests does a star import from both modules which led to an import conflict between the two. It is not necessary to import EventType to run unit tests. Now, EventType is private to avoid being imported via star syntax. Signed-off-by: Vincent Fazio --- bindings/python/tests/tests_edge_event.py | 14 +++++++------- bindings/python/tests/tests_info_event.py | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/bindings/python/tests/tests_edge_event.py b/bindings/python/tests/tests_edge_event.py index 7e7fada..c24d344 100644 --- a/bindings/python/tests/tests_edge_event.py +++ b/bindings/python/tests/tests_edge_event.py @@ -12,7 +12,7 @@ from gpiod.line import Direction, Edge from . import gpiosim -EventType = gpiod.EdgeEvent.Type +_EventType = gpiod.EdgeEvent.Type Pull = gpiosim.Chip.Pull @@ -87,7 +87,7 @@ class WaitingForEdgeEvents(TestCase): events = req.read_edge_events() self.assertEqual(len(events), 1) event = events[0] - self.assertEqual(event.event_type, EventType.RISING_EDGE) + self.assertEqual(event.event_type, _EventType.RISING_EDGE) self.assertEqual(event.line_offset, 2) ts_rising = event.timestamp_ns @@ -95,7 +95,7 @@ class WaitingForEdgeEvents(TestCase): events = req.read_edge_events() self.assertEqual(len(events), 1) event = events[0] - self.assertEqual(event.event_type, EventType.FALLING_EDGE) + self.assertEqual(event.event_type, _EventType.FALLING_EDGE) self.assertEqual(event.line_offset, 2) ts_falling = event.timestamp_ns @@ -114,7 +114,7 @@ class WaitingForEdgeEvents(TestCase): events = req.read_edge_events() self.assertEqual(len(events), 1) event = events[0] - self.assertEqual(event.event_type, EventType.RISING_EDGE) + self.assertEqual(event.event_type, _EventType.RISING_EDGE) self.assertEqual(event.line_offset, 6) self.assertFalse(req.wait_edge_events(timedelta(microseconds=10000))) @@ -132,7 +132,7 @@ class WaitingForEdgeEvents(TestCase): events = req.read_edge_events() self.assertEqual(len(events), 1) event = events[0] - self.assertEqual(event.event_type, EventType.FALLING_EDGE) + self.assertEqual(event.event_type, _EventType.FALLING_EDGE) self.assertEqual(event.line_offset, 6) self.assertFalse(req.wait_edge_events(timedelta(microseconds=10000))) @@ -150,7 +150,7 @@ class WaitingForEdgeEvents(TestCase): events = req.read_edge_events() self.assertEqual(len(events), 1) event = events[0] - self.assertEqual(event.event_type, EventType.RISING_EDGE) + self.assertEqual(event.event_type, _EventType.RISING_EDGE) self.assertEqual(event.line_offset, 2) self.assertEqual(event.global_seqno, 1) self.assertEqual(event.line_seqno, 1) @@ -159,7 +159,7 @@ class WaitingForEdgeEvents(TestCase): events = req.read_edge_events() self.assertEqual(len(events), 1) event = events[0] - self.assertEqual(event.event_type, EventType.RISING_EDGE) + self.assertEqual(event.event_type, _EventType.RISING_EDGE) self.assertEqual(event.line_offset, 4) self.assertEqual(event.global_seqno, 2) self.assertEqual(event.line_seqno, 1) diff --git a/bindings/python/tests/tests_info_event.py b/bindings/python/tests/tests_info_event.py index bbdbc0f..1976f4b 100644 --- a/bindings/python/tests/tests_info_event.py +++ b/bindings/python/tests/tests_info_event.py @@ -14,7 +14,7 @@ from gpiod.line import Direction from . import gpiosim -EventType = gpiod.InfoEvent.Type +_EventType = gpiod.InfoEvent.Type class InfoEventDataclassBehavior(TestCase): @@ -101,7 +101,7 @@ class WatchingInfoEventWorks(TestCase): self.assertTrue(self.chip.wait_info_event(datetime.timedelta(seconds=1))) event = self.chip.read_info_event() - self.assertEqual(event.event_type, EventType.LINE_REQUESTED) + self.assertEqual(event.event_type, _EventType.LINE_REQUESTED) self.assertEqual(event.line_info.offset, 7) self.assertEqual(event.line_info.direction, Direction.INPUT) ts_req = event.timestamp_ns @@ -109,14 +109,14 @@ class WatchingInfoEventWorks(TestCase): # Check that we can use a float directly instead of datetime.timedelta. self.assertTrue(self.chip.wait_info_event(1.0)) event = self.chip.read_info_event() - self.assertEqual(event.event_type, EventType.LINE_CONFIG_CHANGED) + self.assertEqual(event.event_type, _EventType.LINE_CONFIG_CHANGED) self.assertEqual(event.line_info.offset, 7) self.assertEqual(event.line_info.direction, Direction.OUTPUT) ts_rec = event.timestamp_ns self.assertTrue(self.chip.wait_info_event(datetime.timedelta(seconds=1))) event = self.chip.read_info_event() - self.assertEqual(event.event_type, EventType.LINE_RELEASED) + self.assertEqual(event.event_type, _EventType.LINE_RELEASED) self.assertEqual(event.line_info.offset, 7) self.assertEqual(event.line_info.direction, Direction.OUTPUT) ts_rel = event.timestamp_ns @@ -146,7 +146,7 @@ class UnwatchingLineInfo(TestCase): with self.chip.request_lines(config={0: None}) as request: self.assertTrue(self.chip.wait_info_event(datetime.timedelta(seconds=1))) event = self.chip.read_info_event() - self.assertEqual(event.event_type, EventType.LINE_REQUESTED) + self.assertEqual(event.event_type, _EventType.LINE_REQUESTED) self.chip.unwatch_line_info(0) self.assertFalse( From patchwork Thu Nov 14 14:51:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 2011423 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=xes-inc.com header.i=@xes-inc.com header.a=rsa-sha256 header.s=mail header.b=CtPMye0Z; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:4601:e00::3; helo=am.mirrors.kernel.org; envelope-from=linux-gpio+bounces-13022-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [IPv6:2604:1380:4601:e00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Xq35P5rzsz1yCV for ; Fri, 15 Nov 2024 01:51:53 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id B01751F24199 for ; Thu, 14 Nov 2024 14:51:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ED4A613AD29; Thu, 14 Nov 2024 14:51:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="CtPMye0Z" X-Original-To: linux-gpio@vger.kernel.org Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D1AD84E18 for ; Thu, 14 Nov 2024 14:51:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595895; cv=none; b=N9Sqjbj0vhlnxNXCl/SzoB427hN4mW7GTEzcLtYdsUuLET+7kYhzl43iKqk5A168me8z5wEPsLLCKcaCH6HZUxpok+1aY3mD1zpoxWjnBY5UGoRdm2X2gWEbMWz7mlwd6vgR74gmDa+yVRAMJLvPX9uK5I58x+DWRMUY4lGdZmQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595895; c=relaxed/simple; bh=r3TPDi30k3o1UDzICcKWj0WXToZFNPhUaaGaQgjpzis=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eDjWqgXOZ48/1QspvQoOoBLLJPBTKngJHh+/tyhIlEo8iBQOS82Mf0jBBkQVtOSyYfORuD+RGLcYC1axBmg7gpx07mWkikPLm0xP9EcAC6csxTP+a8Bq8kui7YslPPBRhDQ9idG9k3795Sp1qgcqSTOfIIHnwx5UOQQaTcQAuBY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=CtPMye0Z; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id AFD8E20ABA; Thu, 14 Nov 2024 08:51:23 -0600 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1731595883; bh=r3TPDi30k3o1UDzICcKWj0WXToZFNPhUaaGaQgjpzis=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CtPMye0Z7Pcnj1X8Asp/ot1LDJdKbgtK2iYMzjMqUDPMGjsMZkZjH+YxehyAAqpTW K2yeQQsEQEFxpSWTX5Ln5VEuGyVBdKMvL6yKOciM5zwhyb90E5Ogtm+JLyntqoDUk3 Lgo++omf1aHhzK33QibZbhkFppujUMrF1C6JXphY= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH v2 18/23] bindings: python: tests: add type stubs for external modules Date: Thu, 14 Nov 2024 08:51:11 -0600 Message-Id: <20241114145116.2123714-19-vfazio@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114145116.2123714-1-vfazio@xes-inc.com> References: <20241114145116.2123714-1-vfazio@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add type stubs for the compiled external modules so that types and methods used from the modules are accurately type checked. Signed-off-by: Vincent Fazio --- bindings/python/tests/gpiosim/_ext.pyi | 21 +++++++++++++++++++++ bindings/python/tests/procname/_ext.pyi | 1 + 2 files changed, 22 insertions(+) create mode 100644 bindings/python/tests/gpiosim/_ext.pyi create mode 100644 bindings/python/tests/procname/_ext.pyi diff --git a/bindings/python/tests/gpiosim/_ext.pyi b/bindings/python/tests/gpiosim/_ext.pyi new file mode 100644 index 0000000..69d4b63 --- /dev/null +++ b/bindings/python/tests/gpiosim/_ext.pyi @@ -0,0 +1,21 @@ +class Chip: + def __init__(self) -> None: ... + def set_label(self, label: str) -> None: ... + def set_num_lines(self, num_lines: int) -> None: ... + def set_line_name(self, offset: int, name: str) -> None: ... + def set_hog(self, offset: int, name: str, direction: int) -> None: ... + def enable(self) -> None: ... + def get_value(set, offset: int) -> int: ... + def set_pull(set, offset: int, pull: int) -> None: ... + @property + def dev_path(self) -> str: ... + @property + def name(self) -> str: ... + +PULL_DOWN: int +PULL_UP: int +VALUE_INACTIVE: int +VALUE_ACTIVE: int +DIRECTION_INPUT: int +DIRECTION_OUTPUT_HIGH: int +DIRECTION_OUTPUT_LOW: int diff --git a/bindings/python/tests/procname/_ext.pyi b/bindings/python/tests/procname/_ext.pyi new file mode 100644 index 0000000..fdcd8ac --- /dev/null +++ b/bindings/python/tests/procname/_ext.pyi @@ -0,0 +1 @@ +def set_process_name(name: str) -> None: ... From patchwork Thu Nov 14 14:51:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 2011428 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=xes-inc.com header.i=@xes-inc.com header.a=rsa-sha256 header.s=mail header.b=wjm6zCXj; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.80.249; helo=am.mirrors.kernel.org; envelope-from=linux-gpio+bounces-13029-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [147.75.80.249]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Xq35Y4Hc8z1xyc for ; Fri, 15 Nov 2024 01:52:01 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 09B261F245B5 for ; Thu, 14 Nov 2024 14:51:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AAD3213CFA8; Thu, 14 Nov 2024 14:51:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="wjm6zCXj" X-Original-To: linux-gpio@vger.kernel.org Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 44E5E126BF1 for ; Thu, 14 Nov 2024 14:51:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595897; cv=none; b=CHwRCQ2aX7ZdLTkQwV25w47d1feHrwrBPzsrd1T8mogq+4XIZZv+cf9IYG4rYvQj5huVPVY8Uw/OWBX9o2Pe5weUI6S0dgCcW6qWRw0X+WedSPe2tsHAOWVyzXxGzf6mGL8kntF6+ZOx4H++v14LGicitI6LSwiQHP+xCOC+qxc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595897; c=relaxed/simple; bh=7HA9sQuSQo3p0uarotgms2137a1fkpcp4fR2Kq5iGiE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=f7wUuxq4C+U5HPpM/aR3q0i57Pil5QLnLXdX7xBIZ13lupESDdPoS/IFl61n5GECUohe6bIorK7jlgncx2NcqWF1xFSBP5xgrHbU9aBx6MY9kHfZQ3HY6ZtINpQ+o8Ze13tMM4pDPArCmPflxttXvtb/clgvaxjFMELaqoUAo5E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=wjm6zCXj; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id C4C9020ABB; Thu, 14 Nov 2024 08:51:23 -0600 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1731595883; bh=7HA9sQuSQo3p0uarotgms2137a1fkpcp4fR2Kq5iGiE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wjm6zCXj0IXNixrbuJ+UJYIIvg1Bf5A0mmNES6KW0dkycaGmis9dgyZz0JJggayIu 60Lxv54o7T/xIzNpUUNK89aAN+L4Q0F/fpk9SZA2EWF5ZgkPGEysgVx99UsJ89H3Od k7hIR0lyoPMi8/Ppy8mWxo3LHX26d5QQsSTqJOdM= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH v2 19/23] bindings: python: tests: add missing method type hints Date: Thu, 14 Nov 2024 08:51:12 -0600 Message-Id: <20241114145116.2123714-20-vfazio@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114145116.2123714-1-vfazio@xes-inc.com> References: <20241114145116.2123714-1-vfazio@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add type hints for all method arguments and return values. Signed-off-by: Vincent Fazio --- bindings/python/tests/helpers.py | 17 +- bindings/python/tests/tests_chip.py | 68 +++---- bindings/python/tests/tests_chip_info.py | 14 +- bindings/python/tests/tests_edge_event.py | 32 ++-- bindings/python/tests/tests_info_event.py | 38 ++-- bindings/python/tests/tests_line.py | 2 +- bindings/python/tests/tests_line_info.py | 22 +-- bindings/python/tests/tests_line_request.py | 184 +++++++++---------- bindings/python/tests/tests_line_settings.py | 12 +- bindings/python/tests/tests_module.py | 20 +- 10 files changed, 211 insertions(+), 198 deletions(-) diff --git a/bindings/python/tests/helpers.py b/bindings/python/tests/helpers.py index f9a15e8..2126901 100644 --- a/bindings/python/tests/helpers.py +++ b/bindings/python/tests/helpers.py @@ -1,16 +1,27 @@ # SPDX-License-Identifier: GPL-2.0-or-later # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski +from __future__ import annotations + import os +from typing import TYPE_CHECKING, Optional + +if TYPE_CHECKING: + from types import TracebackType class LinkGuard: - def __init__(self, src, dst): + def __init__(self, src: str, dst: str) -> None: self.src = src self.dst = dst - def __enter__(self): + def __enter__(self) -> None: os.symlink(self.src, self.dst) - def __exit__(self, type, val, tb): + def __exit__( + self, + type: Optional[type[BaseException]], + val: Optional[BaseException], + tb: Optional[TracebackType], + ) -> None: os.unlink(self.dst) diff --git a/bindings/python/tests/tests_chip.py b/bindings/python/tests/tests_chip.py index 9110beb..9c8f875 100644 --- a/bindings/python/tests/tests_chip.py +++ b/bindings/python/tests/tests_chip.py @@ -12,19 +12,19 @@ from .helpers import LinkGuard class ChipConstructor(TestCase): - def test_open_existing_chip(self): + def test_open_existing_chip(self) -> None: sim = gpiosim.Chip() with gpiod.Chip(sim.dev_path): pass - def test_open_existing_chip_with_keyword(self): + def test_open_existing_chip_with_keyword(self) -> None: sim = gpiosim.Chip() with gpiod.Chip(path=sim.dev_path): pass - def test_open_chip_by_link(self): + def test_open_chip_by_link(self) -> None: link = "/tmp/gpiod-py-test-link.{}".format(os.getpid()) sim = gpiosim.Chip() @@ -32,35 +32,35 @@ class ChipConstructor(TestCase): with gpiod.Chip(link): pass - def test_open_nonexistent_chip(self): + def test_open_nonexistent_chip(self) -> None: with self.assertRaises(OSError) as ex: gpiod.Chip("/dev/nonexistent") self.assertEqual(ex.exception.errno, errno.ENOENT) - def test_open_not_a_character_device(self): + def test_open_not_a_character_device(self) -> None: with self.assertRaises(OSError) as ex: gpiod.Chip("/tmp") self.assertEqual(ex.exception.errno, errno.ENOTTY) - def test_open_not_a_gpio_device(self): + def test_open_not_a_gpio_device(self) -> None: with self.assertRaises(OSError) as ex: gpiod.Chip("/dev/null") self.assertEqual(ex.exception.errno, errno.ENODEV) - def test_missing_path(self): + def test_missing_path(self) -> None: with self.assertRaises(TypeError): gpiod.Chip() - def test_invalid_type_for_path(self): + def test_invalid_type_for_path(self) -> None: with self.assertRaises(TypeError): gpiod.Chip(4) class ChipBooleanConversion(TestCase): - def test_chip_bool(self): + def test_chip_bool(self) -> None: sim = gpiosim.Chip() chip = gpiod.Chip(sim.dev_path) self.assertTrue(chip) @@ -69,21 +69,21 @@ class ChipBooleanConversion(TestCase): class ChipProperties(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip() self.chip = gpiod.Chip(self.sim.dev_path) - def tearDown(self): + def tearDown(self) -> None: self.chip.close() self.sim = None - def test_get_chip_path(self): + def test_get_chip_path(self) -> None: self.assertEqual(self.sim.dev_path, self.chip.path) - def test_get_fd(self): + def test_get_fd(self) -> None: self.assertGreaterEqual(self.chip.fd, 0) - def test_properties_are_immutable(self): + def test_properties_are_immutable(self) -> None: with self.assertRaises(AttributeError): self.chip.path = "foobar" @@ -92,7 +92,7 @@ class ChipProperties(TestCase): class ChipDevPathFromLink(TestCase): - def test_dev_path_open_by_link(self): + def test_dev_path_open_by_link(self) -> None: sim = gpiosim.Chip() link = "/tmp/gpiod-py-test-link.{}".format(os.getpid()) @@ -102,7 +102,7 @@ class ChipDevPathFromLink(TestCase): class ChipMapLine(TestCase): - def test_lookup_by_name_good(self): + def test_lookup_by_name_good(self) -> None: sim = gpiosim.Chip( num_lines=8, line_names={1: "foo", 2: "bar", 4: "baz", 5: "xyz"} ) @@ -110,7 +110,7 @@ class ChipMapLine(TestCase): with gpiod.Chip(sim.dev_path) as chip: self.assertEqual(chip.line_offset_from_id("baz"), 4) - def test_lookup_by_name_good_keyword_argument(self): + def test_lookup_by_name_good_keyword_argument(self) -> None: sim = gpiosim.Chip( num_lines=8, line_names={1: "foo", 2: "bar", 4: "baz", 5: "xyz"} ) @@ -118,7 +118,7 @@ class ChipMapLine(TestCase): with gpiod.Chip(sim.dev_path) as chip: self.assertEqual(chip.line_offset_from_id(id="baz"), 4) - def test_lookup_bad_name(self): + def test_lookup_bad_name(self) -> None: sim = gpiosim.Chip( num_lines=8, line_names={1: "foo", 2: "bar", 4: "baz", 5: "xyz"} ) @@ -127,21 +127,21 @@ class ChipMapLine(TestCase): with self.assertRaises(FileNotFoundError): chip.line_offset_from_id("nonexistent") - def test_lookup_bad_offset(self): + def test_lookup_bad_offset(self) -> None: sim = gpiosim.Chip() with gpiod.Chip(sim.dev_path) as chip: with self.assertRaises(ValueError): chip.line_offset_from_id(4) - def test_lookup_bad_offset_as_string(self): + def test_lookup_bad_offset_as_string(self) -> None: sim = gpiosim.Chip() with gpiod.Chip(sim.dev_path) as chip: with self.assertRaises(ValueError): chip.line_offset_from_id("4") - def test_duplicate_names(self): + def test_duplicate_names(self) -> None: sim = gpiosim.Chip( num_lines=8, line_names={1: "foo", 2: "bar", 4: "baz", 5: "bar"} ) @@ -149,14 +149,14 @@ class ChipMapLine(TestCase): with gpiod.Chip(sim.dev_path) as chip: self.assertEqual(chip.line_offset_from_id("bar"), 2) - def test_integer_offsets(self): + def test_integer_offsets(self) -> None: sim = gpiosim.Chip(num_lines=8, line_names={1: "foo", 2: "bar", 6: "baz"}) with gpiod.Chip(sim.dev_path) as chip: self.assertEqual(chip.line_offset_from_id(4), 4) self.assertEqual(chip.line_offset_from_id(1), 1) - def test_offsets_as_string(self): + def test_offsets_as_string(self) -> None: sim = gpiosim.Chip(num_lines=8, line_names={1: "foo", 2: "bar", 7: "6"}) with gpiod.Chip(sim.dev_path) as chip: @@ -165,7 +165,7 @@ class ChipMapLine(TestCase): class ClosedChipCannotBeUsed(TestCase): - def test_close_chip_and_try_to_use_it(self): + def test_close_chip_and_try_to_use_it(self) -> None: sim = gpiosim.Chip(label="foobar") chip = gpiod.Chip(sim.dev_path) @@ -174,7 +174,7 @@ class ClosedChipCannotBeUsed(TestCase): with self.assertRaises(gpiod.ChipClosedError): chip.path - def test_close_chip_and_try_controlled_execution(self): + def test_close_chip_and_try_controlled_execution(self) -> None: sim = gpiosim.Chip() chip = gpiod.Chip(sim.dev_path) @@ -184,7 +184,7 @@ class ClosedChipCannotBeUsed(TestCase): with chip: chip.fd - def test_close_chip_twice(self): + def test_close_chip_twice(self) -> None: sim = gpiosim.Chip(label="foobar") chip = gpiod.Chip(sim.dev_path) chip.close() @@ -194,21 +194,21 @@ class ClosedChipCannotBeUsed(TestCase): class StringRepresentation(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=4, label="foobar") self.chip = gpiod.Chip(self.sim.dev_path) - def tearDown(self): + def tearDown(self) -> None: self.chip.close() self.sim = None - def test_repr(self): + def test_repr(self) -> None: self.assertEqual(repr(self.chip), 'gpiod.Chip("{}")'.format(self.sim.dev_path)) cmp = eval(repr(self.chip)) self.assertEqual(self.chip.path, cmp.path) - def test_str(self): + def test_str(self) -> None: info = self.chip.get_info() self.assertEqual( str(self.chip), @@ -219,17 +219,17 @@ class StringRepresentation(TestCase): class StringRepresentationClosed(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=4, label="foobar") self.chip = gpiod.Chip(self.sim.dev_path) - def tearDown(self): + def tearDown(self) -> None: self.sim = None - def test_repr_closed(self): + def test_repr_closed(self) -> None: self.chip.close() self.assertEqual(repr(self.chip), "") - def test_str_closed(self): + def test_str_closed(self) -> None: self.chip.close() self.assertEqual(str(self.chip), "") diff --git a/bindings/python/tests/tests_chip_info.py b/bindings/python/tests/tests_chip_info.py index 9474f38..acb0da9 100644 --- a/bindings/python/tests/tests_chip_info.py +++ b/bindings/python/tests/tests_chip_info.py @@ -9,27 +9,27 @@ from . import gpiosim class ChipInfoProperties(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(label="foobar", num_lines=16) self.chip = gpiod.Chip(self.sim.dev_path) self.info = self.chip.get_info() - def tearDown(self): + def tearDown(self) -> None: self.info = None self.chip.close() self.chip = None self.sim = None - def test_chip_info_name(self): + def test_chip_info_name(self) -> None: self.assertEqual(self.info.name, self.sim.name) - def test_chip_info_label(self): + def test_chip_info_label(self) -> None: self.assertEqual(self.info.label, "foobar") - def test_chip_info_num_lines(self): + def test_chip_info_num_lines(self) -> None: self.assertEqual(self.info.num_lines, 16) - def test_chip_info_properties_are_immutable(self): + def test_chip_info_properties_are_immutable(self) -> None: with self.assertRaises(AttributeError): self.info.name = "foobar" @@ -41,7 +41,7 @@ class ChipInfoProperties(TestCase): class ChipInfoStringRepresentation(TestCase): - def test_chip_info_str(self): + def test_chip_info_str(self) -> None: sim = gpiosim.Chip(label="foobar", num_lines=16) with gpiod.Chip(sim.dev_path) as chip: diff --git a/bindings/python/tests/tests_edge_event.py b/bindings/python/tests/tests_edge_event.py index c24d344..f80d6a5 100644 --- a/bindings/python/tests/tests_edge_event.py +++ b/bindings/python/tests/tests_edge_event.py @@ -17,7 +17,7 @@ Pull = gpiosim.Chip.Pull class EdgeEventWaitTimeout(TestCase): - def test_event_wait_timeout(self): + def test_event_wait_timeout(self) -> None: sim = gpiosim.Chip() with gpiod.request_lines( @@ -26,7 +26,7 @@ class EdgeEventWaitTimeout(TestCase): ) as req: self.assertEqual(req.wait_edge_events(timedelta(microseconds=10000)), False) - def test_event_wait_timeout_float(self): + def test_event_wait_timeout_float(self) -> None: sim = gpiosim.Chip() with gpiod.request_lines( @@ -37,7 +37,7 @@ class EdgeEventWaitTimeout(TestCase): class EdgeEventInvalidConfig(TestCase): - def test_output_mode_and_edge_detection(self): + def test_output_mode_and_edge_detection(self) -> None: sim = gpiosim.Chip() with self.assertRaises(ValueError): @@ -52,29 +52,31 @@ class EdgeEventInvalidConfig(TestCase): class WaitingForEdgeEvents(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=8) self.thread = None - def tearDown(self): + def tearDown(self) -> None: if self.thread: self.thread.join() del self.thread self.sim = None - def trigger_falling_and_rising_edge(self, offset): + def trigger_falling_and_rising_edge(self, offset: int) -> None: time.sleep(0.05) self.sim.set_pull(offset, Pull.UP) time.sleep(0.05) self.sim.set_pull(offset, Pull.DOWN) - def trigger_rising_edge_events_on_two_offsets(self, offset0, offset1): + def trigger_rising_edge_events_on_two_offsets( + self, offset0: int, offset1: int + ) -> None: time.sleep(0.05) self.sim.set_pull(offset0, Pull.UP) time.sleep(0.05) self.sim.set_pull(offset1, Pull.UP) - def test_both_edge_events(self): + def test_both_edge_events(self) -> None: with gpiod.request_lines( self.sim.dev_path, {2: gpiod.LineSettings(edge_detection=Edge.BOTH)} ) as req: @@ -101,7 +103,7 @@ class WaitingForEdgeEvents(TestCase): self.assertGreater(ts_falling, ts_rising) - def test_rising_edge_event(self): + def test_rising_edge_event(self) -> None: with gpiod.request_lines( self.sim.dev_path, {6: gpiod.LineSettings(edge_detection=Edge.RISING)} ) as req: @@ -119,7 +121,7 @@ class WaitingForEdgeEvents(TestCase): self.assertFalse(req.wait_edge_events(timedelta(microseconds=10000))) - def test_falling_edge_event(self): + def test_falling_edge_event(self) -> None: with gpiod.request_lines( self.sim.dev_path, {6: gpiod.LineSettings(edge_detection=Edge.FALLING)} ) as req: @@ -137,7 +139,7 @@ class WaitingForEdgeEvents(TestCase): self.assertFalse(req.wait_edge_events(timedelta(microseconds=10000))) - def test_sequence_numbers(self): + def test_sequence_numbers(self) -> None: with gpiod.request_lines( self.sim.dev_path, {(2, 4): gpiod.LineSettings(edge_detection=Edge.BOTH)} ) as req: @@ -166,7 +168,7 @@ class WaitingForEdgeEvents(TestCase): class ReadingMultipleEdgeEvents(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=8) self.request = gpiod.request_lines( self.sim.dev_path, {1: gpiod.LineSettings(edge_detection=Edge.BOTH)} @@ -180,12 +182,12 @@ class ReadingMultipleEdgeEvents(TestCase): self.sim.set_pull(1, Pull.UP) time.sleep(0.05) - def tearDown(self): + def tearDown(self) -> None: self.request.release() del self.request del self.sim - def test_read_multiple_events(self): + def test_read_multiple_events(self) -> None: self.assertTrue(self.request.wait_edge_events(timedelta(seconds=1))) events = self.request.read_edge_events() self.assertEqual(len(events), 3) @@ -199,7 +201,7 @@ class ReadingMultipleEdgeEvents(TestCase): class EdgeEventStringRepresentation(TestCase): - def test_edge_event_str(self): + def test_edge_event_str(self) -> None: sim = gpiosim.Chip() with gpiod.request_lines( diff --git a/bindings/python/tests/tests_info_event.py b/bindings/python/tests/tests_info_event.py index 1976f4b..7e12b8e 100644 --- a/bindings/python/tests/tests_info_event.py +++ b/bindings/python/tests/tests_info_event.py @@ -18,7 +18,7 @@ _EventType = gpiod.InfoEvent.Type class InfoEventDataclassBehavior(TestCase): - def test_info_event_props_are_frozen(self): + def test_info_event_props_are_frozen(self) -> None: sim = gpiosim.Chip() with gpiod.Chip(sim.dev_path) as chip: @@ -37,7 +37,7 @@ class InfoEventDataclassBehavior(TestCase): event.line_info = 4 -def request_reconfigure_release_line(chip_path, offset): +def request_reconfigure_release_line(chip_path: str, offset: int) -> None: time.sleep(0.1) with gpiod.request_lines(chip_path, config={offset: None}) as request: time.sleep(0.1) @@ -48,12 +48,12 @@ def request_reconfigure_release_line(chip_path, offset): class WatchingInfoEventWorks(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=8, line_names={4: "foobar"}) self.chip = gpiod.Chip(self.sim.dev_path) self.thread = None - def tearDown(self): + def tearDown(self) -> None: if self.thread: self.thread.join() self.thread = None @@ -62,35 +62,35 @@ class WatchingInfoEventWorks(TestCase): self.chip = None self.sim = None - def test_watch_line_info_returns_line_info(self): + def test_watch_line_info_returns_line_info(self) -> None: info = self.chip.watch_line_info(7) self.assertEqual(info.offset, 7) - def test_watch_line_info_keyword_argument(self): + def test_watch_line_info_keyword_argument(self) -> None: info = self.chip.watch_line_info(line=7) - def test_watch_line_info_offset_out_of_range(self): + def test_watch_line_info_offset_out_of_range(self) -> None: with self.assertRaises(ValueError): self.chip.watch_line_info(8) - def test_watch_line_info_no_arguments(self): + def test_watch_line_info_no_arguments(self) -> None: with self.assertRaises(TypeError): self.chip.watch_line_info() - def test_watch_line_info_by_line_name(self): + def test_watch_line_info_by_line_name(self) -> None: self.chip.watch_line_info("foobar") - def test_watch_line_info_invalid_argument_type(self): + def test_watch_line_info_invalid_argument_type(self) -> None: with self.assertRaises(TypeError): self.chip.watch_line_info(None) - def test_wait_for_event_timeout(self): + def test_wait_for_event_timeout(self) -> None: info = self.chip.watch_line_info(7) self.assertFalse( self.chip.wait_info_event(datetime.timedelta(microseconds=10000)) ) - def test_request_reconfigure_release_events(self): + def test_request_reconfigure_release_events(self) -> None: info = self.chip.watch_line_info(7) self.assertEqual(info.direction, Direction.INPUT) @@ -132,16 +132,16 @@ class WatchingInfoEventWorks(TestCase): class UnwatchingLineInfo(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=8, line_names={4: "foobar"}) self.chip = gpiod.Chip(self.sim.dev_path) - def tearDown(self): + def tearDown(self) -> None: self.chip.close() self.chip = None self.sim = None - def test_unwatch_line_info(self): + def test_unwatch_line_info(self) -> None: self.chip.watch_line_info(0) with self.chip.request_lines(config={0: None}) as request: self.assertTrue(self.chip.wait_info_event(datetime.timedelta(seconds=1))) @@ -153,17 +153,17 @@ class UnwatchingLineInfo(TestCase): self.chip.wait_info_event(datetime.timedelta(microseconds=10000)) ) - def test_unwatch_not_watched_line(self): + def test_unwatch_not_watched_line(self) -> None: with self.assertRaises(OSError) as ex: self.chip.unwatch_line_info(2) self.assertEqual(ex.exception.errno, errno.EBUSY) - def test_unwatch_line_info_no_argument(self): + def test_unwatch_line_info_no_argument(self) -> None: with self.assertRaises(TypeError): self.chip.unwatch_line_info() - def test_unwatch_line_info_by_line_name(self): + def test_unwatch_line_info_by_line_name(self) -> None: self.chip.watch_line_info(4) with self.chip.request_lines(config={4: None}) as request: self.assertIsNotNone(self.chip.read_info_event()) @@ -175,7 +175,7 @@ class UnwatchingLineInfo(TestCase): class InfoEventStringRepresentation(TestCase): - def test_info_event_str(self): + def test_info_event_str(self) -> None: sim = gpiosim.Chip() with gpiod.Chip(sim.dev_path) as chip: diff --git a/bindings/python/tests/tests_line.py b/bindings/python/tests/tests_line.py index 2182567..c96f6de 100644 --- a/bindings/python/tests/tests_line.py +++ b/bindings/python/tests/tests_line.py @@ -7,6 +7,6 @@ from gpiod.line import Value class LineValue(TestCase): - def test_cast_bool(self): + def test_cast_bool(self) -> None: self.assertTrue(bool(Value.ACTIVE)) self.assertFalse(bool(Value.INACTIVE)) diff --git a/bindings/python/tests/tests_line_info.py b/bindings/python/tests/tests_line_info.py index 79281a8..9828349 100644 --- a/bindings/python/tests/tests_line_info.py +++ b/bindings/python/tests/tests_line_info.py @@ -12,7 +12,7 @@ HogDir = gpiosim.Chip.Direction class GetLineInfo(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip( num_lines=4, line_names={0: "foobar"}, @@ -20,37 +20,37 @@ class GetLineInfo(TestCase): self.chip = gpiod.Chip(self.sim.dev_path) - def tearDown(self): + def tearDown(self) -> None: self.chip.close() self.chip = None self.sim = None - def test_get_line_info_by_offset(self): + def test_get_line_info_by_offset(self) -> None: self.chip.get_line_info(0) - def test_get_line_info_by_offset_keyword(self): + def test_get_line_info_by_offset_keyword(self) -> None: self.chip.get_line_info(line=0) - def test_get_line_info_by_name(self): + def test_get_line_info_by_name(self) -> None: self.chip.get_line_info("foobar") - def test_get_line_info_by_name_keyword(self): + def test_get_line_info_by_name_keyword(self) -> None: self.chip.get_line_info(line="foobar") - def test_get_line_info_by_offset_string(self): + def test_get_line_info_by_offset_string(self) -> None: self.chip.get_line_info("2") - def test_offset_out_of_range(self): + def test_offset_out_of_range(self) -> None: with self.assertRaises(ValueError) as ex: self.chip.get_line_info(4) - def test_no_offset(self): + def test_no_offset(self) -> None: with self.assertRaises(TypeError): self.chip.get_line_info() class LinePropertiesCanBeRead(TestCase): - def test_basic_properties(self): + def test_basic_properties(self) -> None: sim = gpiosim.Chip( num_lines=8, line_names={1: "foo", 2: "bar", 4: "baz", 5: "xyz"}, @@ -87,7 +87,7 @@ class LinePropertiesCanBeRead(TestCase): class LineInfoStringRepresentation(TestCase): - def test_line_info_str(self): + def test_line_info_str(self) -> None: sim = gpiosim.Chip( line_names={0: "foo"}, hogs={0: ("hogger", HogDir.OUTPUT_HIGH)} ) diff --git a/bindings/python/tests/tests_line_request.py b/bindings/python/tests/tests_line_request.py index c3e86c5..76edb1d 100644 --- a/bindings/python/tests/tests_line_request.py +++ b/bindings/python/tests/tests_line_request.py @@ -13,78 +13,78 @@ SimVal = gpiosim.Chip.Value class ChipLineRequestsBehaveCorrectlyWithInvalidArguments(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=8) self.chip = gpiod.Chip(self.sim.dev_path) - def tearDown(self): + def tearDown(self) -> None: self.chip.close() del self.chip del self.sim - def test_passing_invalid_types_as_configs(self): + def test_passing_invalid_types_as_configs(self) -> None: with self.assertRaises(AttributeError): self.chip.request_lines("foobar") with self.assertRaises(AttributeError): self.chip.request_lines(None, "foobar") - def test_offset_out_of_range(self): + def test_offset_out_of_range(self) -> None: with self.assertRaises(ValueError): self.chip.request_lines(config={(1, 0, 4, 8): None}) - def test_line_name_not_found(self): + def test_line_name_not_found(self) -> None: with self.assertRaises(FileNotFoundError): self.chip.request_lines(config={"foo": None}) - def test_request_no_arguments(self): + def test_request_no_arguments(self) -> None: with self.assertRaises(TypeError): self.chip.request_lines() class ModuleLineRequestsBehaveCorrectlyWithInvalidArguments(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=8) - def tearDown(self): + def tearDown(self) -> None: del self.sim - def test_passing_invalid_types_as_configs(self): + def test_passing_invalid_types_as_configs(self) -> None: with self.assertRaises(AttributeError): gpiod.request_lines(self.sim.dev_path, "foobar") with self.assertRaises(AttributeError): gpiod.request_lines(self.sim.dev_path, None, "foobar") - def test_offset_out_of_range(self): + def test_offset_out_of_range(self) -> None: with self.assertRaises(ValueError): gpiod.request_lines(self.sim.dev_path, config={(1, 0, 4, 8): None}) - def test_line_name_not_found(self): + def test_line_name_not_found(self) -> None: with self.assertRaises(FileNotFoundError): gpiod.request_lines(self.sim.dev_path, config={"foo": None}) - def test_request_no_arguments(self): + def test_request_no_arguments(self) -> None: with self.assertRaises(TypeError): gpiod.request_lines() class ChipLineRequestWorks(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=8, line_names={5: "foo", 7: "bar"}) self.chip = gpiod.Chip(self.sim.dev_path) - def tearDown(self): + def tearDown(self) -> None: self.chip.close() del self.chip del self.sim - def test_request_with_positional_arguments(self): + def test_request_with_positional_arguments(self) -> None: with self.chip.request_lines({(0, 5, 3, 1): None}, "foobar", 32) as req: self.assertEqual(req.offsets, [0, 5, 3, 1]) self.assertEqual(self.chip.get_line_info(0).consumer, "foobar") - def test_request_with_keyword_arguments(self): + def test_request_with_keyword_arguments(self) -> None: with self.chip.request_lines( config={(0, 5, 6): None}, consumer="foobar", @@ -93,31 +93,31 @@ class ChipLineRequestWorks(TestCase): self.assertEqual(req.offsets, [0, 5, 6]) self.assertEqual(self.chip.get_line_info(0).consumer, "foobar") - def test_request_single_offset_as_int(self): + def test_request_single_offset_as_int(self) -> None: with self.chip.request_lines(config={4: None}) as req: self.assertEqual(req.offsets, [4]) - def test_request_single_offset_as_tuple(self): + def test_request_single_offset_as_tuple(self) -> None: with self.chip.request_lines(config={(4): None}) as req: self.assertEqual(req.offsets, [4]) - def test_request_by_name(self): + def test_request_by_name(self) -> None: with self.chip.request_lines(config={(1, 2, "foo", "bar"): None}) as req: self.assertEqual(req.offsets, [1, 2, 5, 7]) - def test_request_single_line_by_name(self): + def test_request_single_line_by_name(self) -> None: with self.chip.request_lines(config={"foo": None}) as req: self.assertEqual(req.offsets, [5]) class ModuleLineRequestWorks(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=8, line_names={5: "foo", 7: "bar"}) - def tearDown(self): + def tearDown(self) -> None: del self.sim - def test_request_with_positional_arguments(self): + def test_request_with_positional_arguments(self) -> None: with gpiod.request_lines( self.sim.dev_path, {(0, 5, 3, 1): None}, "foobar", 32 ) as req: @@ -125,7 +125,7 @@ class ModuleLineRequestWorks(TestCase): with gpiod.Chip(self.sim.dev_path) as chip: self.assertEqual(chip.get_line_info(5).consumer, "foobar") - def test_request_with_keyword_arguments(self): + def test_request_with_keyword_arguments(self) -> None: with gpiod.request_lines( path=self.sim.dev_path, config={(0, 5, 6): None}, @@ -136,15 +136,15 @@ class ModuleLineRequestWorks(TestCase): with gpiod.Chip(self.sim.dev_path) as chip: self.assertEqual(chip.get_line_info(5).consumer, "foobar") - def test_request_single_offset_as_int(self): + def test_request_single_offset_as_int(self) -> None: with gpiod.request_lines(path=self.sim.dev_path, config={4: None}) as req: self.assertEqual(req.offsets, [4]) - def test_request_single_offset_as_tuple(self): + def test_request_single_offset_as_tuple(self) -> None: with gpiod.request_lines(path=self.sim.dev_path, config={(4): None}) as req: self.assertEqual(req.offsets, [4]) - def test_request_by_name(self): + def test_request_by_name(self) -> None: with gpiod.request_lines( self.sim.dev_path, {(1, 2, "foo", "bar"): None} ) as req: @@ -152,29 +152,29 @@ class ModuleLineRequestWorks(TestCase): class LineRequestGettingValues(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=8) self.req = gpiod.request_lines( self.sim.dev_path, {(0, 1, 2, 3): gpiod.LineSettings(direction=Direction.INPUT)}, ) - def tearDown(self): + def tearDown(self) -> None: self.req.release() del self.req del self.sim - def test_get_single_value(self): + def test_get_single_value(self) -> None: self.sim.set_pull(1, Pull.UP) self.assertEqual(self.req.get_values([1]), [Value.ACTIVE]) - def test_get_single_value_helper(self): + def test_get_single_value_helper(self) -> None: self.sim.set_pull(1, Pull.UP) self.assertEqual(self.req.get_value(1), Value.ACTIVE) - def test_get_values_for_subset_of_lines(self): + def test_get_values_for_subset_of_lines(self) -> None: self.sim.set_pull(0, Pull.UP) self.sim.set_pull(1, Pull.DOWN) self.sim.set_pull(3, Pull.UP) @@ -183,7 +183,7 @@ class LineRequestGettingValues(TestCase): self.req.get_values([0, 1, 3]), [Value.ACTIVE, Value.INACTIVE, Value.ACTIVE] ) - def test_get_all_values(self): + def test_get_all_values(self) -> None: self.sim.set_pull(0, Pull.DOWN) self.sim.set_pull(1, Pull.UP) self.sim.set_pull(2, Pull.UP) @@ -194,29 +194,29 @@ class LineRequestGettingValues(TestCase): [Value.INACTIVE, Value.ACTIVE, Value.ACTIVE, Value.ACTIVE], ) - def test_get_values_invalid_offset(self): + def test_get_values_invalid_offset(self) -> None: with self.assertRaises(ValueError): self.req.get_values([9]) - def test_get_values_invalid_argument_type(self): + def test_get_values_invalid_argument_type(self) -> None: with self.assertRaises(TypeError): self.req.get_values(True) class LineRequestGettingValuesByName(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=4, line_names={2: "foo", 3: "bar", 1: "baz"}) self.req = gpiod.request_lines( self.sim.dev_path, {(0, "baz", "bar", "foo"): gpiod.LineSettings(direction=Direction.INPUT)}, ) - def tearDown(self): + def tearDown(self) -> None: self.req.release() del self.req del self.sim - def test_get_values_by_name(self): + def test_get_values_by_name(self) -> None: self.sim.set_pull(1, Pull.UP) self.sim.set_pull(2, Pull.DOWN) self.sim.set_pull(3, Pull.UP) @@ -226,58 +226,58 @@ class LineRequestGettingValuesByName(TestCase): [Value.INACTIVE, Value.ACTIVE, Value.ACTIVE], ) - def test_get_values_by_bad_name(self): + def test_get_values_by_bad_name(self) -> None: with self.assertRaises(ValueError): self.req.get_values(["xyz"]) class LineRequestSettingValues(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=8) self.req = gpiod.request_lines( self.sim.dev_path, {(0, 1, 2, 3): gpiod.LineSettings(direction=Direction.OUTPUT)}, ) - def tearDown(self): + def tearDown(self) -> None: self.req.release() del self.req del self.sim - def test_set_single_value(self): + def test_set_single_value(self) -> None: self.req.set_values({1: Value.ACTIVE}) self.assertEqual(self.sim.get_value(1), SimVal.ACTIVE) - def test_set_single_value_helper(self): + def test_set_single_value_helper(self) -> None: self.req.set_value(1, Value.ACTIVE) self.assertEqual(self.sim.get_value(1), SimVal.ACTIVE) - def test_set_values_for_subset_of_lines(self): + def test_set_values_for_subset_of_lines(self) -> None: self.req.set_values({0: Value.ACTIVE, 1: Value.INACTIVE, 3: Value.ACTIVE}) self.assertEqual(self.sim.get_value(0), SimVal.ACTIVE) self.assertEqual(self.sim.get_value(1), SimVal.INACTIVE) self.assertEqual(self.sim.get_value(3), SimVal.ACTIVE) - def test_set_values_invalid_offset(self): + def test_set_values_invalid_offset(self) -> None: with self.assertRaises(ValueError): self.req.set_values({9: Value.ACTIVE}) class LineRequestSettingValuesByName(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=4, line_names={2: "foo", 3: "bar", 1: "baz"}) self.req = gpiod.request_lines( self.sim.dev_path, {(0, "baz", "bar", "foo"): gpiod.LineSettings(direction=Direction.OUTPUT)}, ) - def tearDown(self): + def tearDown(self) -> None: self.req.release() del self.req del self.sim - def test_set_values_by_name(self): + def test_set_values_by_name(self) -> None: self.req.set_values( {"foo": Value.INACTIVE, "bar": Value.ACTIVE, 1: Value.ACTIVE} ) @@ -286,13 +286,13 @@ class LineRequestSettingValuesByName(TestCase): self.assertEqual(self.sim.get_value(1), SimVal.ACTIVE) self.assertEqual(self.sim.get_value(3), SimVal.ACTIVE) - def test_set_values_by_bad_name(self): + def test_set_values_by_bad_name(self) -> None: with self.assertRaises(ValueError): self.req.set_values({"xyz": Value.ACTIVE}) class LineRequestComplexConfig(TestCase): - def test_complex_config(self): + def test_complex_config(self) -> None: sim = gpiosim.Chip(num_lines=8) with gpiod.Chip(sim.dev_path) as chip: @@ -314,7 +314,7 @@ class LineRequestComplexConfig(TestCase): class LineRequestMixedConfigByName(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip( num_lines=4, line_names={2: "foo", 3: "bar", 1: "baz", 0: "xyz"} ) @@ -326,18 +326,18 @@ class LineRequestMixedConfigByName(TestCase): }, ) - def tearDown(self): + def tearDown(self) -> None: self.req.release() del self.req del self.sim - def test_set_values_by_name(self): + def test_set_values_by_name(self) -> None: self.req.set_values({"bar": Value.ACTIVE, "baz": Value.INACTIVE}) self.assertEqual(self.sim.get_value(1), SimVal.INACTIVE) self.assertEqual(self.sim.get_value(3), SimVal.ACTIVE) - def test_get_values_by_name(self): + def test_get_values_by_name(self) -> None: self.sim.set_pull(0, Pull.UP) self.sim.set_pull(2, Pull.DOWN) @@ -348,40 +348,40 @@ class LineRequestMixedConfigByName(TestCase): class RepeatingLinesInRequestConfig(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=4, line_names={0: "foo", 2: "bar"}) self.chip = gpiod.Chip(self.sim.dev_path) - def tearDown(self): + def tearDown(self) -> None: self.chip.close() del self.chip del self.sim - def test_offsets_repeating_within_the_same_tuple(self): + def test_offsets_repeating_within_the_same_tuple(self) -> None: with self.assertRaises(ValueError): self.chip.request_lines({(0, 1, 2, 1): None}) - def test_offsets_repeating_in_different_tuples(self): + def test_offsets_repeating_in_different_tuples(self) -> None: with self.assertRaises(ValueError): self.chip.request_lines({(0, 1, 2): None, (3, 4, 0): None}) - def test_offset_and_name_conflict_in_the_same_tuple(self): + def test_offset_and_name_conflict_in_the_same_tuple(self) -> None: with self.assertRaises(ValueError): self.chip.request_lines({(2, "bar"): None}) - def test_offset_and_name_conflict_in_different_tuples(self): + def test_offset_and_name_conflict_in_different_tuples(self) -> None: with self.assertRaises(ValueError): self.chip.request_lines({(0, 1, 2): None, (4, 5, "bar"): None}) class LineRequestPropertiesWork(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=16, line_names={0: "foo", 2: "bar", 5: "baz"}) - def tearDown(self): + def tearDown(self) -> None: del self.sim - def test_property_fd(self): + def test_property_fd(self) -> None: with gpiod.request_lines( self.sim.dev_path, config={ @@ -392,19 +392,19 @@ class LineRequestPropertiesWork(TestCase): ) as req: self.assertGreaterEqual(req.fd, 0) - def test_property_num_lines(self): + def test_property_num_lines(self) -> None: with gpiod.request_lines( self.sim.dev_path, config={(0, 2, 3, 5, 6, 8, 12): None} ) as req: self.assertEqual(req.num_lines, 7) - def test_property_offsets(self): + def test_property_offsets(self) -> None: with gpiod.request_lines( self.sim.dev_path, config={(1, 6, 12, 4): None} ) as req: self.assertEqual(req.offsets, [1, 6, 12, 4]) - def test_property_lines(self): + def test_property_lines(self) -> None: with gpiod.request_lines( self.sim.dev_path, config={("foo", 1, "bar", 4, "baz"): None} ) as req: @@ -412,43 +412,43 @@ class LineRequestPropertiesWork(TestCase): class LineRequestConsumerString(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=4) self.chip = gpiod.Chip(self.sim.dev_path) - def tearDown(self): + def tearDown(self) -> None: self.chip.close() del self.chip del self.sim - def test_custom_consumer(self): + def test_custom_consumer(self) -> None: with self.chip.request_lines( consumer="foobar", config={(2, 3): None} ) as request: info = self.chip.get_line_info(2) self.assertEqual(info.consumer, "foobar") - def test_empty_consumer(self): + def test_empty_consumer(self) -> None: with self.chip.request_lines(consumer="", config={(2, 3): None}) as request: info = self.chip.get_line_info(2) self.assertEqual(info.consumer, "?") - def test_default_consumer(self): + def test_default_consumer(self) -> None: with self.chip.request_lines(config={(2, 3): None}) as request: info = self.chip.get_line_info(2) self.assertEqual(info.consumer, "?") class LineRequestSetOutputValues(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip( num_lines=4, line_names={0: "foo", 1: "bar", 2: "baz", 3: "xyz"} ) - def tearDown(self): + def tearDown(self) -> None: del self.sim - def test_request_with_globally_set_output_values(self): + def test_request_with_globally_set_output_values(self) -> None: with gpiod.request_lines( self.sim.dev_path, config={(0, 1, 2, 3): gpiod.LineSettings(direction=Direction.OUTPUT)}, @@ -464,7 +464,7 @@ class LineRequestSetOutputValues(TestCase): self.assertEqual(self.sim.get_value(2), SimVal.ACTIVE) self.assertEqual(self.sim.get_value(3), SimVal.INACTIVE) - def test_request_with_globally_set_output_values_with_mapping(self): + def test_request_with_globally_set_output_values_with_mapping(self) -> None: with gpiod.request_lines( self.sim.dev_path, config={(0, 1, 2, 3): gpiod.LineSettings(direction=Direction.OUTPUT)}, @@ -475,7 +475,7 @@ class LineRequestSetOutputValues(TestCase): self.assertEqual(self.sim.get_value(2), SimVal.ACTIVE) self.assertEqual(self.sim.get_value(3), SimVal.INACTIVE) - def test_request_with_globally_set_output_values_bad_mapping(self): + def test_request_with_globally_set_output_values_bad_mapping(self) -> None: with self.assertRaises(FileNotFoundError): with gpiod.request_lines( self.sim.dev_path, @@ -484,7 +484,7 @@ class LineRequestSetOutputValues(TestCase): ) as request: pass - def test_request_with_globally_set_output_values_bad_offset(self): + def test_request_with_globally_set_output_values_bad_offset(self) -> None: with self.assertRaises(ValueError): with gpiod.request_lines( self.sim.dev_path, @@ -495,7 +495,7 @@ class LineRequestSetOutputValues(TestCase): class ReconfigureRequestedLines(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=8, line_names={3: "foo", 4: "bar", 6: "baz"}) self.chip = gpiod.Chip(self.sim.dev_path) self.req = self.chip.request_lines( @@ -506,14 +506,14 @@ class ReconfigureRequestedLines(TestCase): } ) - def tearDown(self): + def tearDown(self) -> None: self.chip.close() del self.chip self.req.release() del self.req del self.sim - def test_reconfigure_by_offsets(self): + def test_reconfigure_by_offsets(self) -> None: info = self.chip.get_line_info(2) self.assertEqual(info.direction, Direction.OUTPUT) self.req.reconfigure_lines( @@ -522,7 +522,7 @@ class ReconfigureRequestedLines(TestCase): info = self.chip.get_line_info(2) self.assertEqual(info.direction, Direction.INPUT) - def test_reconfigure_by_names(self): + def test_reconfigure_by_names(self) -> None: info = self.chip.get_line_info(2) self.assertEqual(info.direction, Direction.OUTPUT) self.req.reconfigure_lines( @@ -531,7 +531,7 @@ class ReconfigureRequestedLines(TestCase): info = self.chip.get_line_info(2) self.assertEqual(info.direction, Direction.INPUT) - def test_reconfigure_by_misordered_offsets(self): + def test_reconfigure_by_misordered_offsets(self) -> None: info = self.chip.get_line_info(2) self.assertEqual(info.direction, Direction.OUTPUT) self.req.reconfigure_lines( @@ -540,7 +540,7 @@ class ReconfigureRequestedLines(TestCase): info = self.chip.get_line_info(2) self.assertEqual(info.direction, Direction.INPUT) - def test_reconfigure_by_misordered_names(self): + def test_reconfigure_by_misordered_names(self) -> None: info = self.chip.get_line_info(2) self.assertEqual(info.direction, Direction.OUTPUT) self.req.reconfigure_lines( @@ -549,7 +549,7 @@ class ReconfigureRequestedLines(TestCase): info = self.chip.get_line_info(2) self.assertEqual(info.direction, Direction.INPUT) - def test_reconfigure_with_default(self): + def test_reconfigure_with_default(self) -> None: info = self.chip.get_line_info(2) self.assertEqual(info.direction, Direction.OUTPUT) self.assertTrue(info.active_low) @@ -568,7 +568,7 @@ class ReconfigureRequestedLines(TestCase): self.assertTrue(info.active_low) self.assertEqual(info.drive, Drive.OPEN_DRAIN) - def test_reconfigure_missing_offsets(self): + def test_reconfigure_missing_offsets(self) -> None: info = self.chip.get_line_info(2) self.assertEqual(info.direction, Direction.OUTPUT) self.assertTrue(info.active_low) @@ -583,7 +583,7 @@ class ReconfigureRequestedLines(TestCase): self.assertTrue(info.active_low) self.assertEqual(info.drive, Drive.OPEN_DRAIN) - def test_reconfigure_extra_offsets(self): + def test_reconfigure_extra_offsets(self) -> None: info = self.chip.get_line_info(2) self.assertEqual(info.direction, Direction.OUTPUT) self.req.reconfigure_lines( @@ -594,7 +594,7 @@ class ReconfigureRequestedLines(TestCase): class ReleasedLineRequestCannotBeUsed(TestCase): - def test_using_released_line_request(self): + def test_using_released_line_request(self) -> None: sim = gpiosim.Chip() with gpiod.Chip(sim.dev_path) as chip: @@ -606,7 +606,7 @@ class ReleasedLineRequestCannotBeUsed(TestCase): class LineRequestSurvivesParentChip(TestCase): - def test_line_request_survives_parent_chip(self): + def test_line_request_survives_parent_chip(self) -> None: sim = gpiosim.Chip() chip = gpiod.Chip(sim.dev_path) @@ -624,13 +624,13 @@ class LineRequestSurvivesParentChip(TestCase): class LineRequestStringRepresentation(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=8) - def tearDown(self): + def tearDown(self) -> None: del self.sim - def test_str(self): + def test_str(self) -> None: with gpiod.Chip(self.sim.dev_path) as chip: with chip.request_lines(config={(2, 6, 4, 1): None}) as req: self.assertEqual( @@ -640,7 +640,7 @@ class LineRequestStringRepresentation(TestCase): ), ) - def test_str_released(self): + def test_str_released(self) -> None: req = gpiod.request_lines(self.sim.dev_path, config={(2, 6, 4, 1): None}) req.release() self.assertEqual(str(req), "") diff --git a/bindings/python/tests/tests_line_settings.py b/bindings/python/tests/tests_line_settings.py index 832ac8a..66e01df 100644 --- a/bindings/python/tests/tests_line_settings.py +++ b/bindings/python/tests/tests_line_settings.py @@ -9,7 +9,7 @@ from gpiod.line import Bias, Clock, Direction, Drive, Edge, Value class LineSettingsConstructor(TestCase): - def test_default_values(self): + def test_default_values(self) -> None: settings = gpiod.LineSettings() self.assertEqual(settings.direction, Direction.AS_IS) @@ -21,7 +21,7 @@ class LineSettingsConstructor(TestCase): self.assertEqual(settings.event_clock, Clock.MONOTONIC) self.assertEqual(settings.output_value, Value.INACTIVE) - def test_keyword_arguments(self): + def test_keyword_arguments(self) -> None: settings = gpiod.LineSettings( direction=Direction.INPUT, edge_detection=Edge.BOTH, @@ -40,7 +40,7 @@ class LineSettingsConstructor(TestCase): class LineSettingsAttributes(TestCase): - def test_line_settings_attributes_are_mutable(self): + def test_line_settings_attributes_are_mutable(self) -> None: settings = gpiod.LineSettings() settings.direction = Direction.INPUT @@ -60,12 +60,12 @@ class LineSettingsAttributes(TestCase): class LineSettingsStringRepresentation(TestCase): - def setUp(self): + def setUp(self) -> None: self.settings = gpiod.LineSettings( direction=Direction.OUTPUT, drive=Drive.OPEN_SOURCE, active_low=True ) - def test_repr(self): + def test_repr(self) -> None: self.assertEqual( repr(self.settings), "gpiod.LineSettings(direction=gpiod.line.Direction.OUTPUT, edge_detection=gpiod.line.Edge.NONE, bias=gpiod.line.Bias.AS_IS, drive=gpiod.line.Drive.OPEN_SOURCE, active_low=True, debounce_period=datetime.timedelta(0), event_clock=gpiod.line.Clock.MONOTONIC, output_value=gpiod.line.Value.INACTIVE)", @@ -74,7 +74,7 @@ class LineSettingsStringRepresentation(TestCase): cmp = eval(repr(self.settings)) self.assertEqual(self.settings, cmp) - def test_str(self): + def test_str(self) -> None: self.assertEqual( str(self.settings), "", diff --git a/bindings/python/tests/tests_module.py b/bindings/python/tests/tests_module.py index f46729f..2718624 100644 --- a/bindings/python/tests/tests_module.py +++ b/bindings/python/tests/tests_module.py @@ -11,38 +11,38 @@ from .helpers import LinkGuard class IsGPIOChip(TestCase): - def test_is_gpiochip_bad(self): + def test_is_gpiochip_bad(self) -> None: self.assertFalse(gpiod.is_gpiochip_device("/dev/null")) self.assertFalse(gpiod.is_gpiochip_device("/dev/nonexistent")) - def test_is_gpiochip_invalid_argument(self): + def test_is_gpiochip_invalid_argument(self) -> None: with self.assertRaises(TypeError): gpiod.is_gpiochip_device(4) - def test_is_gpiochip_superfluous_argument(self): + def test_is_gpiochip_superfluous_argument(self) -> None: with self.assertRaises(TypeError): gpiod.is_gpiochip_device("/dev/null", 4) - def test_is_gpiochip_missing_argument(self): + def test_is_gpiochip_missing_argument(self) -> None: with self.assertRaises(TypeError): gpiod.is_gpiochip_device() - def test_is_gpiochip_good(self): + def test_is_gpiochip_good(self) -> None: sim = gpiosim.Chip() self.assertTrue(gpiod.is_gpiochip_device(sim.dev_path)) - def test_is_gpiochip_good_keyword_argument(self): + def test_is_gpiochip_good_keyword_argument(self) -> None: sim = gpiosim.Chip() self.assertTrue(gpiod.is_gpiochip_device(path=sim.dev_path)) - def test_is_gpiochip_link_good(self): + def test_is_gpiochip_link_good(self) -> None: link = "/tmp/gpiod-py-test-link.{}".format(os.getpid()) sim = gpiosim.Chip() with LinkGuard(sim.dev_path, link): self.assertTrue(gpiod.is_gpiochip_device(link)) - def test_is_gpiochip_link_bad(self): + def test_is_gpiochip_link_bad(self) -> None: link = "/tmp/gpiod-py-test-link.{}".format(os.getpid()) with LinkGuard("/dev/null", link): @@ -52,8 +52,8 @@ class IsGPIOChip(TestCase): class VersionString(TestCase): VERSION_PATTERN = "^\\d+\\.\\d+(\\.\\d+|\\-devel|\\-rc\\d+)?$" - def test_api_version_string(self): + def test_api_version_string(self) -> None: self.assertRegex(gpiod.api_version, VersionString.VERSION_PATTERN) - def test_module_version(self): + def test_module_version(self) -> None: self.assertRegex(gpiod.__version__, VersionString.VERSION_PATTERN) From patchwork Thu Nov 14 14:51:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 2011425 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=xes-inc.com header.i=@xes-inc.com header.a=rsa-sha256 header.s=mail header.b=cu9gY9F3; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-gpio+bounces-13027-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Xq35T5b8Xz1yCV for ; Fri, 15 Nov 2024 01:51:57 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 5CEDA2823B2 for ; Thu, 14 Nov 2024 14:51:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5113413CA8D; Thu, 14 Nov 2024 14:51:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="cu9gY9F3" X-Original-To: linux-gpio@vger.kernel.org Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23D426F307 for ; Thu, 14 Nov 2024 14:51:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595897; cv=none; b=RWAeuxA+bLx5YPWdbLOM+BS/h9TfxdNPY9K0XJusjbSjRdwAr0b+FLtoauOrl0Ir0GqOrFCggqmkt9AHWqtBqrmySkB4l6J+36WtppK0tUAddJfIdC+AN5IgC9kmLI3wEY/JuJgIyO2L7fP0InQCm7Ctq4Vqd82Ex2li3AmPCqg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595897; c=relaxed/simple; bh=GqsbHIiZILytSGfI3bEakJVjHTB/n+zOG9o/ML+KvC8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=u8Rjin3FSVpJ1oCDBmxgzUA/T4l5QoC9nqObR/8YtHo396huGPUdZFWloFMmDBQgql5ZwoHUOHHEA9j3fBoVUasEJkouX4CP/HRRZ4bPGYKSyIQsUEJSX0YpTmWFlOsFbf+e6OutMhPZAhqRjn6aTRp0NpnsTxgD/oEnl0h4Pyw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=cu9gY9F3; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id DBF6220ABD; Thu, 14 Nov 2024 08:51:23 -0600 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1731595883; bh=GqsbHIiZILytSGfI3bEakJVjHTB/n+zOG9o/ML+KvC8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cu9gY9F3GDz+VXHmlQHKswhxHPzXw3pvbJOR2+RuUQ8WOXja0RMPxFPCScBMpuD1x lBJUE6h4v5Pz2lJkaH4VtQPUr3RcEzgJnROV4AyKYSvE71o3GgsBxSnMJLrc/hqn3x +1lYCtJQFUqDyVAaL7twGK2F1Ufg9KP0GQK6/mWs= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH v2 20/23] bindings: python: tests: add type hints to internal members Date: Thu, 14 Nov 2024 08:51:13 -0600 Message-Id: <20241114145116.2123714-21-vfazio@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114145116.2123714-1-vfazio@xes-inc.com> References: <20241114145116.2123714-1-vfazio@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add type hints for internal members of the test cases so type checkers can ensure the code properly constrains to these types and accounts for scenarios where the values are `None`. In most cases, the type checker is allowed to assume the inferred type upon assignment. An example is any test case that creates a `Chip` as part of its `setUp` method. Many of these tests subsequently set the reference to `None` in `tearDown` to free up resources to be collected by the GC. If the member was "properly" typed to be `Optional`, all references in the unit tests would need to be guarded by an assert or a cast or ignored by the type checker. This is noisy and doesn't add value since for the life of the test it should always be a valid reference. Instead, allow `tearDown` to violate the inferred type and inform the type checker to ignore the assignment via directive. If the tests are ever changed to set the member to something other than the inferred type outside of `tearDown`, explicit type hints and proper checks should be added. Signed-off-by: Vincent Fazio --- bindings/python/tests/tests_chip.py | 6 +++--- bindings/python/tests/tests_chip_info.py | 6 +++--- bindings/python/tests/tests_edge_event.py | 5 +++-- bindings/python/tests/tests_info_event.py | 11 ++++++----- bindings/python/tests/tests_line_info.py | 4 ++-- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/bindings/python/tests/tests_chip.py b/bindings/python/tests/tests_chip.py index 9c8f875..218f238 100644 --- a/bindings/python/tests/tests_chip.py +++ b/bindings/python/tests/tests_chip.py @@ -75,7 +75,7 @@ class ChipProperties(TestCase): def tearDown(self) -> None: self.chip.close() - self.sim = None + self.sim = None # type: ignore[assignment] def test_get_chip_path(self) -> None: self.assertEqual(self.sim.dev_path, self.chip.path) @@ -200,7 +200,7 @@ class StringRepresentation(TestCase): def tearDown(self) -> None: self.chip.close() - self.sim = None + self.sim = None # type: ignore[assignment] def test_repr(self) -> None: self.assertEqual(repr(self.chip), 'gpiod.Chip("{}")'.format(self.sim.dev_path)) @@ -224,7 +224,7 @@ class StringRepresentationClosed(TestCase): self.chip = gpiod.Chip(self.sim.dev_path) def tearDown(self) -> None: - self.sim = None + self.sim = None # type: ignore[assignment] def test_repr_closed(self) -> None: self.chip.close() diff --git a/bindings/python/tests/tests_chip_info.py b/bindings/python/tests/tests_chip_info.py index acb0da9..aabfbee 100644 --- a/bindings/python/tests/tests_chip_info.py +++ b/bindings/python/tests/tests_chip_info.py @@ -15,10 +15,10 @@ class ChipInfoProperties(TestCase): self.info = self.chip.get_info() def tearDown(self) -> None: - self.info = None + self.info = None # type: ignore[assignment] self.chip.close() - self.chip = None - self.sim = None + self.chip = None # type: ignore[assignment] + self.sim = None # type: ignore[assignment] def test_chip_info_name(self) -> None: self.assertEqual(self.info.name, self.sim.name) diff --git a/bindings/python/tests/tests_edge_event.py b/bindings/python/tests/tests_edge_event.py index f80d6a5..d7766ec 100644 --- a/bindings/python/tests/tests_edge_event.py +++ b/bindings/python/tests/tests_edge_event.py @@ -5,6 +5,7 @@ import time from datetime import timedelta from functools import partial from threading import Thread +from typing import Optional from unittest import TestCase import gpiod @@ -54,13 +55,13 @@ class EdgeEventInvalidConfig(TestCase): class WaitingForEdgeEvents(TestCase): def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=8) - self.thread = None + self.thread: Optional[Thread] = None def tearDown(self) -> None: if self.thread: self.thread.join() del self.thread - self.sim = None + self.sim = None # type: ignore[assignment] def trigger_falling_and_rising_edge(self, offset: int) -> None: time.sleep(0.05) diff --git a/bindings/python/tests/tests_info_event.py b/bindings/python/tests/tests_info_event.py index 7e12b8e..1005647 100644 --- a/bindings/python/tests/tests_info_event.py +++ b/bindings/python/tests/tests_info_event.py @@ -7,6 +7,7 @@ import threading import time from dataclasses import FrozenInstanceError from functools import partial +from typing import Optional from unittest import TestCase import gpiod @@ -51,7 +52,7 @@ class WatchingInfoEventWorks(TestCase): def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=8, line_names={4: "foobar"}) self.chip = gpiod.Chip(self.sim.dev_path) - self.thread = None + self.thread: Optional[threading.Thread] = None def tearDown(self) -> None: if self.thread: @@ -59,8 +60,8 @@ class WatchingInfoEventWorks(TestCase): self.thread = None self.chip.close() - self.chip = None - self.sim = None + self.chip = None # type: ignore[assignment] + self.sim = None # type: ignore[assignment] def test_watch_line_info_returns_line_info(self) -> None: info = self.chip.watch_line_info(7) @@ -138,8 +139,8 @@ class UnwatchingLineInfo(TestCase): def tearDown(self) -> None: self.chip.close() - self.chip = None - self.sim = None + self.chip = None # type: ignore[assignment] + self.sim = None # type: ignore[assignment] def test_unwatch_line_info(self) -> None: self.chip.watch_line_info(0) diff --git a/bindings/python/tests/tests_line_info.py b/bindings/python/tests/tests_line_info.py index 9828349..7bc244d 100644 --- a/bindings/python/tests/tests_line_info.py +++ b/bindings/python/tests/tests_line_info.py @@ -22,8 +22,8 @@ class GetLineInfo(TestCase): def tearDown(self) -> None: self.chip.close() - self.chip = None - self.sim = None + self.chip = None # type: ignore[assignment] + self.sim = None # type: ignore[assignment] def test_get_line_info_by_offset(self) -> None: self.chip.get_line_info(0) From patchwork Thu Nov 14 14:51:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 2011429 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=xes-inc.com header.i=@xes-inc.com header.a=rsa-sha256 header.s=mail header.b=P44RjYjS; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=linux-gpio+bounces-13025-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [IPv6:2604:1380:40f1:3f00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Xq36D6wvnz1xyc for ; Fri, 15 Nov 2024 01:52:36 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id E1A17B2DB35 for ; Thu, 14 Nov 2024 14:51:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DD13013C8F9; Thu, 14 Nov 2024 14:51:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="P44RjYjS" X-Original-To: linux-gpio@vger.kernel.org Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1796133987 for ; Thu, 14 Nov 2024 14:51:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595896; cv=none; b=MPEfU6qCKiFR9n5RBoD45SjFpauVn8aiaZ4e/vEYgrU5UyzrlNGatvBfBb3vicaqcggY7DEANCHmcOSEh2Z4+m/V8FMcuARViqIiP0LSnwvotGZo8ei3/k+SExs9SgR/ByuCNEdR/2VgKGdnCuyFe+0I5CeYEsyJ7N7rPXYf2Es= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595896; c=relaxed/simple; bh=+yW1lNtX3BKFoo/xRbe7YuEAUj8k0bc3UC9pBxL2csI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HCGcE0wLxARaPayJ1y3eQfS7Zm4EmvwaqyytXDlkP8vZlojIdMucPfOm2aoIi8XZ1+LGosuk0rVWuva3s4j7lKOpT9jeKa3STVX6tDMiwG7/2PyXcxt9Vutp9LnY9k3j61tnZOGhdtTd6g/9kK8trNB44V9McnqOt58/XndnunY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=P44RjYjS; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id F079120ABE; Thu, 14 Nov 2024 08:51:23 -0600 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1731595884; bh=+yW1lNtX3BKFoo/xRbe7YuEAUj8k0bc3UC9pBxL2csI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P44RjYjSstzHBDZJ1t5+Aa00N30YL/RiAQ7ARSP+TleSw5uXyMqUttns7cXkIkczz f/weJP8JcfiZY1RBFGZujKf3yuX6ECVbTXeMj3Psk4yjWIgLGNW2m8cw5I3dkjF6ed bP66j9fn5hVTIhrYgYyhdnwlHg8WWkHWUTANpcAw= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH v2 21/23] bindings: python: tests: ignore purposeful type errors Date: Thu, 14 Nov 2024 08:51:14 -0600 Message-Id: <20241114145116.2123714-22-vfazio@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114145116.2123714-1-vfazio@xes-inc.com> References: <20241114145116.2123714-1-vfazio@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some of the unit tests intentionally call methods or assign properties with invalid values to ensure they fail in an expected way. Type checkers complain for these instances so inform them via directive that these lines should be ignore for specific errors. Additionally, some lines that access properties without assigning the value look like they perform no action to linters. To appease the linter, read the value into a throw-away variable. Signed-off-by: Vincent Fazio --- bindings/python/tests/tests_chip.py | 12 ++++++------ bindings/python/tests/tests_chip_info.py | 6 +++--- bindings/python/tests/tests_info_event.py | 12 ++++++------ bindings/python/tests/tests_line_info.py | 2 +- bindings/python/tests/tests_line_request.py | 16 ++++++++-------- bindings/python/tests/tests_module.py | 6 +++--- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/bindings/python/tests/tests_chip.py b/bindings/python/tests/tests_chip.py index 218f238..9b31e30 100644 --- a/bindings/python/tests/tests_chip.py +++ b/bindings/python/tests/tests_chip.py @@ -52,11 +52,11 @@ class ChipConstructor(TestCase): def test_missing_path(self) -> None: with self.assertRaises(TypeError): - gpiod.Chip() + gpiod.Chip() # type: ignore[call-arg] def test_invalid_type_for_path(self) -> None: with self.assertRaises(TypeError): - gpiod.Chip(4) + gpiod.Chip(4) # type: ignore[arg-type] class ChipBooleanConversion(TestCase): @@ -85,10 +85,10 @@ class ChipProperties(TestCase): def test_properties_are_immutable(self) -> None: with self.assertRaises(AttributeError): - self.chip.path = "foobar" + self.chip.path = "foobar" # type: ignore[misc] with self.assertRaises(AttributeError): - self.chip.fd = 4 + self.chip.fd = 4 # type: ignore[misc] class ChipDevPathFromLink(TestCase): @@ -172,7 +172,7 @@ class ClosedChipCannotBeUsed(TestCase): chip.close() with self.assertRaises(gpiod.ChipClosedError): - chip.path + _ = chip.path def test_close_chip_and_try_controlled_execution(self) -> None: sim = gpiosim.Chip() @@ -182,7 +182,7 @@ class ClosedChipCannotBeUsed(TestCase): with self.assertRaises(gpiod.ChipClosedError): with chip: - chip.fd + _ = chip.fd def test_close_chip_twice(self) -> None: sim = gpiosim.Chip(label="foobar") diff --git a/bindings/python/tests/tests_chip_info.py b/bindings/python/tests/tests_chip_info.py index aabfbee..fdceda9 100644 --- a/bindings/python/tests/tests_chip_info.py +++ b/bindings/python/tests/tests_chip_info.py @@ -31,13 +31,13 @@ class ChipInfoProperties(TestCase): def test_chip_info_properties_are_immutable(self) -> None: with self.assertRaises(AttributeError): - self.info.name = "foobar" + self.info.name = "foobar" # type: ignore[misc] with self.assertRaises(AttributeError): - self.info.num_lines = 4 + self.info.num_lines = 4 # type: ignore[misc] with self.assertRaises(AttributeError): - self.info.label = "foobar" + self.info.label = "foobar" # type: ignore[misc] class ChipInfoStringRepresentation(TestCase): diff --git a/bindings/python/tests/tests_info_event.py b/bindings/python/tests/tests_info_event.py index 1005647..e726a54 100644 --- a/bindings/python/tests/tests_info_event.py +++ b/bindings/python/tests/tests_info_event.py @@ -29,13 +29,13 @@ class InfoEventDataclassBehavior(TestCase): event = chip.read_info_event() with self.assertRaises(FrozenInstanceError): - event.event_type = 4 + event.event_type = 4 # type: ignore[misc, assignment] with self.assertRaises(FrozenInstanceError): - event.timestamp_ns = 4 + event.timestamp_ns = 4 # type: ignore[misc] with self.assertRaises(FrozenInstanceError): - event.line_info = 4 + event.line_info = 4 # type: ignore[misc, assignment] def request_reconfigure_release_line(chip_path: str, offset: int) -> None: @@ -76,14 +76,14 @@ class WatchingInfoEventWorks(TestCase): def test_watch_line_info_no_arguments(self) -> None: with self.assertRaises(TypeError): - self.chip.watch_line_info() + self.chip.watch_line_info() # type: ignore[call-arg] def test_watch_line_info_by_line_name(self) -> None: self.chip.watch_line_info("foobar") def test_watch_line_info_invalid_argument_type(self) -> None: with self.assertRaises(TypeError): - self.chip.watch_line_info(None) + self.chip.watch_line_info(None) # type: ignore[arg-type] def test_wait_for_event_timeout(self) -> None: info = self.chip.watch_line_info(7) @@ -162,7 +162,7 @@ class UnwatchingLineInfo(TestCase): def test_unwatch_line_info_no_argument(self) -> None: with self.assertRaises(TypeError): - self.chip.unwatch_line_info() + self.chip.unwatch_line_info() # type: ignore[call-arg] def test_unwatch_line_info_by_line_name(self) -> None: self.chip.watch_line_info(4) diff --git a/bindings/python/tests/tests_line_info.py b/bindings/python/tests/tests_line_info.py index 7bc244d..5eb6cd5 100644 --- a/bindings/python/tests/tests_line_info.py +++ b/bindings/python/tests/tests_line_info.py @@ -46,7 +46,7 @@ class GetLineInfo(TestCase): def test_no_offset(self) -> None: with self.assertRaises(TypeError): - self.chip.get_line_info() + self.chip.get_line_info() # type: ignore[call-arg] class LinePropertiesCanBeRead(TestCase): diff --git a/bindings/python/tests/tests_line_request.py b/bindings/python/tests/tests_line_request.py index 76edb1d..bae8815 100644 --- a/bindings/python/tests/tests_line_request.py +++ b/bindings/python/tests/tests_line_request.py @@ -24,10 +24,10 @@ class ChipLineRequestsBehaveCorrectlyWithInvalidArguments(TestCase): def test_passing_invalid_types_as_configs(self) -> None: with self.assertRaises(AttributeError): - self.chip.request_lines("foobar") + self.chip.request_lines("foobar") # type: ignore[arg-type] with self.assertRaises(AttributeError): - self.chip.request_lines(None, "foobar") + self.chip.request_lines(None, "foobar") # type: ignore[arg-type] def test_offset_out_of_range(self) -> None: with self.assertRaises(ValueError): @@ -39,7 +39,7 @@ class ChipLineRequestsBehaveCorrectlyWithInvalidArguments(TestCase): def test_request_no_arguments(self) -> None: with self.assertRaises(TypeError): - self.chip.request_lines() + self.chip.request_lines() # type: ignore[call-arg] class ModuleLineRequestsBehaveCorrectlyWithInvalidArguments(TestCase): @@ -51,10 +51,10 @@ class ModuleLineRequestsBehaveCorrectlyWithInvalidArguments(TestCase): def test_passing_invalid_types_as_configs(self) -> None: with self.assertRaises(AttributeError): - gpiod.request_lines(self.sim.dev_path, "foobar") + gpiod.request_lines(self.sim.dev_path, "foobar") # type: ignore[arg-type] with self.assertRaises(AttributeError): - gpiod.request_lines(self.sim.dev_path, None, "foobar") + gpiod.request_lines(self.sim.dev_path, None, "foobar") # type: ignore[arg-type] def test_offset_out_of_range(self) -> None: with self.assertRaises(ValueError): @@ -66,7 +66,7 @@ class ModuleLineRequestsBehaveCorrectlyWithInvalidArguments(TestCase): def test_request_no_arguments(self) -> None: with self.assertRaises(TypeError): - gpiod.request_lines() + gpiod.request_lines() # type: ignore[call-arg] class ChipLineRequestWorks(TestCase): @@ -200,7 +200,7 @@ class LineRequestGettingValues(TestCase): def test_get_values_invalid_argument_type(self) -> None: with self.assertRaises(TypeError): - self.req.get_values(True) + self.req.get_values(True) # type: ignore[arg-type] class LineRequestGettingValuesByName(TestCase): @@ -602,7 +602,7 @@ class ReleasedLineRequestCannotBeUsed(TestCase): req.release() with self.assertRaises(gpiod.RequestReleasedError): - req.fd + _ = req.fd class LineRequestSurvivesParentChip(TestCase): diff --git a/bindings/python/tests/tests_module.py b/bindings/python/tests/tests_module.py index 2718624..efd49db 100644 --- a/bindings/python/tests/tests_module.py +++ b/bindings/python/tests/tests_module.py @@ -17,15 +17,15 @@ class IsGPIOChip(TestCase): def test_is_gpiochip_invalid_argument(self) -> None: with self.assertRaises(TypeError): - gpiod.is_gpiochip_device(4) + gpiod.is_gpiochip_device(4) # type: ignore[arg-type] def test_is_gpiochip_superfluous_argument(self) -> None: with self.assertRaises(TypeError): - gpiod.is_gpiochip_device("/dev/null", 4) + gpiod.is_gpiochip_device("/dev/null", 4) # type: ignore[call-arg] def test_is_gpiochip_missing_argument(self) -> None: with self.assertRaises(TypeError): - gpiod.is_gpiochip_device() + gpiod.is_gpiochip_device() # type: ignore[call-arg] def test_is_gpiochip_good(self) -> None: sim = gpiosim.Chip() From patchwork Thu Nov 14 14:51:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 2011424 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=xes-inc.com header.i=@xes-inc.com header.a=rsa-sha256 header.s=mail header.b=Of9jKf7a; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.80.249; helo=am.mirrors.kernel.org; envelope-from=linux-gpio+bounces-13024-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [147.75.80.249]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Xq35S5cxMz1xyc for ; Fri, 15 Nov 2024 01:51:56 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 5E93A1F246D6 for ; Thu, 14 Nov 2024 14:51:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CAA4613C3CD; Thu, 14 Nov 2024 14:51:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="Of9jKf7a" X-Original-To: linux-gpio@vger.kernel.org Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1B1212FF70 for ; Thu, 14 Nov 2024 14:51:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595896; cv=none; b=TjsSyFBhvxaMXTTJfiwjpXRFSmPaoXG7QxlNr+60RBlb4F3mAZNo6hcTgphlqcp/34RoxKhoAWPc3tkYLN6XeqVXBt8ePtDnovdImNxgiZ5KqfOwVq9Ai7Ug9dDnO8pLn3331OK97A+2AUT2T3CPlIkqrSOBnc+NTZLlRcemsCQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595896; c=relaxed/simple; bh=PZ2PXOyR3EdAWFgjqGbH0qHNu/MYDSd0UrdD1rj8pac=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CQKG4k6ZZ88Z+ZYAUokdCG+TetqMpiJ0jyDPebXpFqPd65Apyv0B9ew6Kwyk+6HDmmqXPGSomLGXW9jABLhFk9uvL4Am626SUz5hSZKlhBrRL/yB5ACkZ88UXfgEAcPL8D04XbpVMzKW/w0zqvTSi8sZ6EnGIK80KbBk2DTC9Aw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=Of9jKf7a; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id 119E520ABF; Thu, 14 Nov 2024 08:51:24 -0600 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1731595884; bh=PZ2PXOyR3EdAWFgjqGbH0qHNu/MYDSd0UrdD1rj8pac=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Of9jKf7a5AGJrEJwqQCUU6TBa5L/FBdgFgOK+y/Lg8NtVDXrY4QCQH2XAxWHeG03a gQgvnhobTxFL9npAYbPgWNiEoZwHdY0nzs3YslPoIz34mb5nne5xyYb/VnkGA8z1fG EmxgeiiYBfHhwBajrvYQM3RTFdS3sWvBzzXOa2D0= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH v2 22/23] bindings: python: tests: selectively use f-strings Date: Thu, 14 Nov 2024 08:51:15 -0600 Message-Id: <20241114145116.2123714-23-vfazio@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114145116.2123714-1-vfazio@xes-inc.com> References: <20241114145116.2123714-1-vfazio@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Since their inclusion in Python 3.6, f-strings have become the preferred way to format strings with variable values as they are generally more readable as the value substitution is in place and doesn't have to be parsed from the list or arguments to `.format()`. Where it does not impact readability (when the line is <120 characters), swap usage of `.format()` to an f-string. For lines that are not converted, inform the linter to ignore attempts to upgrade those instances to f-strings [0] [0]: https://docs.astral.sh/ruff/rules/f-string/ Signed-off-by: Vincent Fazio --- bindings/python/tests/__init__.py | 4 +--- bindings/python/tests/tests_chip.py | 8 ++++---- bindings/python/tests/tests_chip_info.py | 2 +- bindings/python/tests/tests_line_request.py | 4 +--- bindings/python/tests/tests_module.py | 4 ++-- 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/bindings/python/tests/__init__.py b/bindings/python/tests/__init__.py index 2374e81..a0f22ae 100644 --- a/bindings/python/tests/__init__.py +++ b/bindings/python/tests/__init__.py @@ -9,7 +9,5 @@ current_version = LooseVersion(os.uname().release.split("-")[0]) if current_version < required_kernel_version: raise NotImplementedError( - "linux kernel version must be at least {} - got {}".format( - required_kernel_version, current_version - ) + f"linux kernel version must be at least {required_kernel_version} - got {current_version}" ) diff --git a/bindings/python/tests/tests_chip.py b/bindings/python/tests/tests_chip.py index 9b31e30..d5a64b3 100644 --- a/bindings/python/tests/tests_chip.py +++ b/bindings/python/tests/tests_chip.py @@ -25,7 +25,7 @@ class ChipConstructor(TestCase): pass def test_open_chip_by_link(self) -> None: - link = "/tmp/gpiod-py-test-link.{}".format(os.getpid()) + link = f"/tmp/gpiod-py-test-link.{os.getpid()}" sim = gpiosim.Chip() with LinkGuard(sim.dev_path, link): @@ -94,7 +94,7 @@ class ChipProperties(TestCase): class ChipDevPathFromLink(TestCase): def test_dev_path_open_by_link(self) -> None: sim = gpiosim.Chip() - link = "/tmp/gpiod-py-test-link.{}".format(os.getpid()) + link = f"/tmp/gpiod-py-test-link.{os.getpid()}" with LinkGuard(sim.dev_path, link): with gpiod.Chip(link) as chip: @@ -203,7 +203,7 @@ class StringRepresentation(TestCase): self.sim = None # type: ignore[assignment] def test_repr(self) -> None: - self.assertEqual(repr(self.chip), 'gpiod.Chip("{}")'.format(self.sim.dev_path)) + self.assertEqual(repr(self.chip), f'gpiod.Chip("{self.sim.dev_path}")') cmp = eval(repr(self.chip)) self.assertEqual(self.chip.path, cmp.path) @@ -212,7 +212,7 @@ class StringRepresentation(TestCase): info = self.chip.get_info() self.assertEqual( str(self.chip), - '>'.format( + '>'.format( # noqa: UP032 self.sim.dev_path, self.chip.fd, info.name ), ) diff --git a/bindings/python/tests/tests_chip_info.py b/bindings/python/tests/tests_chip_info.py index fdceda9..dbb7fd0 100644 --- a/bindings/python/tests/tests_chip_info.py +++ b/bindings/python/tests/tests_chip_info.py @@ -49,5 +49,5 @@ class ChipInfoStringRepresentation(TestCase): self.assertEqual( str(info), - ''.format(sim.name), + f'', ) diff --git a/bindings/python/tests/tests_line_request.py b/bindings/python/tests/tests_line_request.py index bae8815..afee644 100644 --- a/bindings/python/tests/tests_line_request.py +++ b/bindings/python/tests/tests_line_request.py @@ -635,9 +635,7 @@ class LineRequestStringRepresentation(TestCase): with chip.request_lines(config={(2, 6, 4, 1): None}) as req: self.assertEqual( str(req), - ''.format( - self.sim.name, req.fd - ), + f'', ) def test_str_released(self) -> None: diff --git a/bindings/python/tests/tests_module.py b/bindings/python/tests/tests_module.py index efd49db..7120c63 100644 --- a/bindings/python/tests/tests_module.py +++ b/bindings/python/tests/tests_module.py @@ -36,14 +36,14 @@ class IsGPIOChip(TestCase): self.assertTrue(gpiod.is_gpiochip_device(path=sim.dev_path)) def test_is_gpiochip_link_good(self) -> None: - link = "/tmp/gpiod-py-test-link.{}".format(os.getpid()) + link = f"/tmp/gpiod-py-test-link.{os.getpid()}" sim = gpiosim.Chip() with LinkGuard(sim.dev_path, link): self.assertTrue(gpiod.is_gpiochip_device(link)) def test_is_gpiochip_link_bad(self) -> None: - link = "/tmp/gpiod-py-test-link.{}".format(os.getpid()) + link = f"/tmp/gpiod-py-test-link.{os.getpid()}" with LinkGuard("/dev/null", link): self.assertFalse(gpiod.is_gpiochip_device(link)) From patchwork Thu Nov 14 14:51:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 2011434 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=xes-inc.com header.i=@xes-inc.com header.a=rsa-sha256 header.s=mail header.b=tHgznKxK; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=linux-gpio+bounces-13026-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [IPv6:2604:1380:40f1:3f00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Xq3Ck6CH8z1xxN for ; Fri, 15 Nov 2024 01:57:22 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 053EEB2DD14 for ; Thu, 14 Nov 2024 14:51:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1E92F7DA66; Thu, 14 Nov 2024 14:51:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="tHgznKxK" X-Original-To: linux-gpio@vger.kernel.org Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C1705336E for ; Thu, 14 Nov 2024 14:51:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595896; cv=none; b=LLCNTf7OJpH/lLldtGCqtjFqsP9YoFA2mIXyGifYtEYVWhqJZDIGvAK4hw7QBi5YbjRGyd5vDOvdn2bXB4wBLUj2QnH2bP2ObsC3Ygb8bCrhLi2eq8U/lL7wDoh9S5lrXHWA8K/H+g1OdBs0rqjYn0MIk0j/1WTrWTlThQs+Qs8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731595896; c=relaxed/simple; bh=3buoQxfsBeu/2LtnS6PhbYb3vk35HwEBDXbocvanbXE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BDhkUCk9jnXbDOfrNSjXhewJ1FEt45LV/9nujOSPiKXW8aS7ROq+nCeUiKbJy/PFAnjx4lCYV6lqZuc0RWVPPunIjL/0gg4d5HfU4G7pvoezJGxBJP0MMsvNwk1bS5x3LbI6V2iEgoydU29w+QWGoppn1mjZX6BThrdfkbqRlGY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=tHgznKxK; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id 2628E20AC0; Thu, 14 Nov 2024 08:51:24 -0600 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1731595884; bh=3buoQxfsBeu/2LtnS6PhbYb3vk35HwEBDXbocvanbXE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tHgznKxKKpTMJUtLE+JhLw2lb55Aa+SurYKeRHG2cZxdtf4JQQ3OH3MwyMBZ2jhZi I/Orz30JG4Cd7rcniZ9qnIKMpUFQABKFzbYist8ZRTj5D+/0iYTWJUeU3oW/M0Mjir hvA3XkCY9qPKPh2Cc3NFwfxSkzjQHCWLom4fUbr8= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH v2 23/23] bindings: python: configure and document dev dependencies Date: Thu, 14 Nov 2024 08:51:16 -0600 Message-Id: <20241114145116.2123714-24-vfazio@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114145116.2123714-1-vfazio@xes-inc.com> References: <20241114145116.2123714-1-vfazio@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Mypy [0] is a popular static type checker that validates attribute and variable use and ensures function arguments adhere to type annotations. Ruff [1] is a popular Rust-based Python linter and code formatter. It has support for a large set of linting rules [2] and largely complies with the Black format [3]. Add documentation to README.md for how to run the tools. [0]: https://mypy.readthedocs.io/en/stable/ [1]: https://docs.astral.sh/ruff/ [2]: https://docs.astral.sh/ruff/rules/ [3]: https://docs.astral.sh/ruff/formatter/#black-compatibility Signed-off-by: Vincent Fazio --- bindings/python/README.md | 17 ++++++++++++++++ bindings/python/pyproject.toml | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/bindings/python/README.md b/bindings/python/README.md index cb5cee6..89c824c 100644 --- a/bindings/python/README.md +++ b/bindings/python/README.md @@ -112,3 +112,20 @@ make python-tests-run from the `libgpiod/bindings/python` directory as root (necessary to be able to create the **gpio-sims** used for testing). + +## Linting/Formatting + +When making changes, ensure type checks and linting still pass: + +``` +python3 -m venv venv +. venv/bin/activate +pip install mypy ruff +mypy; ruff format; ruff check +``` + +Ideally the gpiod library will continue to pass strict checks: + +``` +mypy --strict +``` \ No newline at end of file diff --git a/bindings/python/pyproject.toml b/bindings/python/pyproject.toml index f6bf43c..d6f5f9b 100644 --- a/bindings/python/pyproject.toml +++ b/bindings/python/pyproject.toml @@ -3,3 +3,39 @@ [build-system] requires = ["setuptools", "wheel", "packaging"] + +[tool.mypy] +python_version = "3.9" +files = [ + "gpiod/", + "tests/", +] + +[[tool.mypy.overrides]] +module = "gpiod.line.*" +strict_equality = false # Ignore Enum comparison-overlap: https://github.com/python/mypy/issues/17317 + +[tool.ruff] +target-version = "py39" +include = [ + "gpiod/**/*.py", + "gpiod/**/*.pyi", + "tests/**/*.py", + "tests/**/*.pyi", +] + +[tool.ruff.lint] +select = ["B", "E", "F", "I", "TCH", "UP"] +ignore=[ + # Ignore chained exception warnings for now: https://docs.astral.sh/ruff/rules/raise-without-from-inside-except/ + "B904", + # Never enforce line length violations. Let the formatter handle it: https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules + "E501", + # Ignore new Union (|) syntax until we require 3.10+ + "UP007", +] + +[tool.ruff.lint.per-file-ignores] +"gpiod/__init__.py" = ["F403", "F405"] # ignore warnings about star imports +"tests/__main__.py" = ["F403"] +"tests/**.py" = ["F841"] # ignore warnings about unused variables \ No newline at end of file