linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vincent Fazio <vfazio@gmail.com>
To: linux-gpio@vger.kernel.org
Cc: vfazio@xes-inc.com, Vincent Fazio <vfazio@gmail.com>
Subject: [libgpiod][PATCH 9/9] bindings: python: line_request: warn on unknown lines when reconfiguring
Date: Thu,  9 Oct 2025 08:05:15 -0500	[thread overview]
Message-ID: <20251009130516.3729433-10-vfazio@gmail.com> (raw)
In-Reply-To: <20251009130516.3729433-1-vfazio@gmail.com>

Previously, attempting to reconfigure a line that was not included in
the original request provided no feedback to the caller that there was
invalid data in the request.

Now, emit a warning when an unknown offset or line name is encountered.

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
---
 bindings/python/gpiod/line_request.py       | 14 ++++++++--
 bindings/python/tests/tests_line_request.py | 29 ++++++++++++++-------
 2 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/bindings/python/gpiod/line_request.py b/bindings/python/gpiod/line_request.py
index 629df3c..deb48a7 100644
--- a/bindings/python/gpiod/line_request.py
+++ b/bindings/python/gpiod/line_request.py
@@ -3,6 +3,7 @@
 
 from __future__ import annotations
 
+import warnings
 from typing import TYPE_CHECKING, Optional, Union, cast
 
 from . import _ext
@@ -173,12 +174,21 @@ class LineRequest:
         for line, settings in config_iter(config):
             try:
                 offset = self._line_to_offset(line)
-                line_settings[offset] = settings
+                if offset in self.offsets:
+                    line_settings[offset] = settings
+                else:
+                    warnings.warn(
+                        f"Line offset '{offset}' was not included in original request.",
+                        stacklevel=2,
+                    )
             except ValueError:
                 # _line_to_offset will raise a ValueError when it encounters
                 # an unrecognized line name. Ignore these like we do offsets
                 # that were not in the original request.
-                pass
+                warnings.warn(
+                    f"Line name '{line}' was not included in original request.",
+                    stacklevel=2,
+                )
 
         for offset in self.offsets:
             settings = line_settings.get(offset) or LineSettings()
diff --git a/bindings/python/tests/tests_line_request.py b/bindings/python/tests/tests_line_request.py
index aa2cd83..8cb0f2c 100644
--- a/bindings/python/tests/tests_line_request.py
+++ b/bindings/python/tests/tests_line_request.py
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
 # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>
 
+import warnings
 from unittest import TestCase
 
 import gpiod
@@ -604,22 +605,30 @@ class ReconfigureRequestedLines(TestCase):
     def test_reconfigure_extra_offsets(self) -> None:
         info = self.chip.get_line_info(2)
         self.assertEqual(info.direction, Direction.OUTPUT)
-        self.req.reconfigure_lines(
-            {(0, 2, 3, 6, 5): gpiod.LineSettings(direction=Direction.INPUT)}
-        )
+        with warnings.catch_warnings(record=True) as w:
+            self.req.reconfigure_lines(
+                {(0, 2, 3, 6, 5): gpiod.LineSettings(direction=Direction.INPUT)}
+            )
+            assert len(w) == 1
+            assert issubclass(w[0].category, UserWarning)
+            assert "Line offset '5'" in str(w[0].message)
         info = self.chip.get_line_info(2)
         self.assertEqual(info.direction, Direction.INPUT)
 
     def test_reconfigure_extra_names(self) -> None:
         info = self.chip.get_line_info(2)
         self.assertEqual(info.direction, Direction.OUTPUT)
-        self.req.reconfigure_lines(
-            {
-                (0, 2, "foo", "baz", "buzz"): gpiod.LineSettings(
-                    direction=Direction.INPUT
-                )
-            }
-        )
+        with warnings.catch_warnings(record=True) as w:
+            self.req.reconfigure_lines(
+                {
+                    (0, 2, "foo", "baz", "buzz"): gpiod.LineSettings(
+                        direction=Direction.INPUT
+                    )
+                }
+            )
+            assert len(w) == 1
+            assert issubclass(w[0].category, UserWarning)
+            assert "Line name 'buzz'" in str(w[0].message)
         info = self.chip.get_line_info(2)
         self.assertEqual(info.direction, Direction.INPUT)
 
-- 
2.43.0


  parent reply	other threads:[~2025-10-09 13:05 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-09 13:05 [libgpiod][PATCH 0/9] bindings: python: improve line requests and reconfiguration Vincent Fazio
2025-10-09 13:05 ` [libgpiod][PATCH 1/9] bindings: python: make config iteration consistent Vincent Fazio
2025-10-09 13:05 ` [libgpiod][PATCH 2/9] bindings: python: remove unused attribute from LineRequest Vincent Fazio
2025-10-09 13:05 ` [libgpiod][PATCH 3/9] bindings: python: chip: track requested lines when enumerating Vincent Fazio
2025-10-09 13:05 ` [libgpiod][PATCH 4/9] bindings: python: chip: simplify duplicate checking Vincent Fazio
2025-10-09 13:05 ` [libgpiod][PATCH 5/9] bindings: python: chip: check mapped_output_values membership once Vincent Fazio
2025-10-09 13:05 ` [libgpiod][PATCH 6/9] bindings: python: line_request: ignore invalid line names in reconfigure_lines Vincent Fazio
2025-10-09 13:05 ` [libgpiod][PATCH 7/9] bindings: python: ext: add ability to query line name Vincent Fazio
2025-10-09 13:05 ` [libgpiod][PATCH 8/9] bindings: python: chip: map names for lines requested by offset Vincent Fazio
2025-10-09 13:05 ` Vincent Fazio [this message]
2025-10-13 15:31 ` [libgpiod][PATCH 0/9] bindings: python: improve line requests and reconfiguration Bartosz Golaszewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251009130516.3729433-10-vfazio@gmail.com \
    --to=vfazio@gmail.com \
    --cc=linux-gpio@vger.kernel.org \
    --cc=vfazio@xes-inc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).