gpiod 2.4.2__tar.gz → 2.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. gpiod-2.5.0/CHANGELOG.md +47 -0
  2. {gpiod-2.4.2 → gpiod-2.5.0}/MANIFEST.in +1 -0
  3. {gpiod-2.4.2/gpiod.egg-info → gpiod-2.5.0}/PKG-INFO +15 -6
  4. {gpiod-2.4.2 → gpiod-2.5.0}/README.md +12 -4
  5. {gpiod-2.4.2 → gpiod-2.5.0}/build_tests.py +3 -20
  6. {gpiod-2.4.2 → gpiod-2.5.0}/gpiod/__init__.py +4 -5
  7. {gpiod-2.4.2 → gpiod-2.5.0}/gpiod/_ext.pyi +4 -6
  8. {gpiod-2.4.2 → gpiod-2.5.0}/gpiod/_internal.py +5 -5
  9. {gpiod-2.4.2 → gpiod-2.5.0}/gpiod/chip.py +22 -23
  10. {gpiod-2.4.2 → gpiod-2.5.0}/gpiod/chip_info.py +3 -1
  11. {gpiod-2.4.2 → gpiod-2.5.0}/gpiod/edge_event.py +2 -0
  12. {gpiod-2.4.2 → gpiod-2.5.0}/gpiod/ext/chip.c +17 -14
  13. {gpiod-2.4.2 → gpiod-2.5.0}/gpiod/ext/common.c +4 -1
  14. {gpiod-2.4.2 → gpiod-2.5.0}/gpiod/ext/internal.h +8 -2
  15. {gpiod-2.4.2 → gpiod-2.5.0}/gpiod/ext/line-config.c +4 -0
  16. {gpiod-2.4.2 → gpiod-2.5.0}/gpiod/ext/module.c +38 -37
  17. {gpiod-2.4.2 → gpiod-2.5.0}/gpiod/ext/request.c +12 -19
  18. {gpiod-2.4.2 → gpiod-2.5.0}/gpiod/info_event.py +2 -0
  19. {gpiod-2.4.2 → gpiod-2.5.0}/gpiod/line_info.py +3 -1
  20. {gpiod-2.4.2 → gpiod-2.5.0}/gpiod/line_request.py +21 -24
  21. {gpiod-2.4.2 → gpiod-2.5.0}/gpiod/line_settings.py +2 -0
  22. {gpiod-2.4.2 → gpiod-2.5.0}/gpiod/version.py +1 -1
  23. {gpiod-2.4.2 → gpiod-2.5.0/gpiod.egg-info}/PKG-INFO +15 -6
  24. {gpiod-2.4.2 → gpiod-2.5.0}/gpiod.egg-info/SOURCES.txt +2 -0
  25. {gpiod-2.4.2 → gpiod-2.5.0}/lib/chip-info.c +2 -0
  26. {gpiod-2.4.2 → gpiod-2.5.0}/lib/edge-event.c +5 -0
  27. {gpiod-2.4.2 → gpiod-2.5.0}/lib/line-config.c +42 -3
  28. {gpiod-2.4.2 → gpiod-2.5.0}/lib/line-info.c +2 -0
  29. {gpiod-2.4.2 → gpiod-2.5.0}/lib/line-request.c +1 -1
  30. {gpiod-2.4.2 → gpiod-2.5.0}/lib/misc.c +1 -1
  31. {gpiod-2.4.2 → gpiod-2.5.0}/lib/request-config.c +1 -1
  32. gpiod-2.5.0/libgpiod-version.txt +1 -0
  33. {gpiod-2.4.2 → gpiod-2.5.0}/pyproject.toml +11 -24
  34. {gpiod-2.4.2 → gpiod-2.5.0}/setup.py +28 -20
  35. {gpiod-2.4.2 → gpiod-2.5.0}/tests/__main__.py +1 -0
  36. {gpiod-2.4.2 → gpiod-2.5.0}/tests/gpiosim/chip.py +4 -5
  37. {gpiod-2.4.2 → gpiod-2.5.0}/tests/gpiosim/ext.c +99 -58
  38. {gpiod-2.4.2 → gpiod-2.5.0}/tests/helpers.py +9 -4
  39. {gpiod-2.4.2 → gpiod-2.5.0}/tests/system/ext.c +9 -1
  40. {gpiod-2.4.2 → gpiod-2.5.0}/tests/tests_chip.py +0 -8
  41. {gpiod-2.4.2 → gpiod-2.5.0}/tests/tests_edge_event.py +2 -3
  42. {gpiod-2.4.2 → gpiod-2.5.0}/tests/tests_info_event.py +1 -2
  43. gpiod-2.5.0/tests/tests_threading.py +745 -0
  44. gpiod-2.4.2/libgpiod-version.txt +0 -1
  45. {gpiod-2.4.2 → gpiod-2.5.0}/LICENSE +0 -0
  46. {gpiod-2.4.2 → gpiod-2.5.0}/gpiod/exception.py +0 -0
  47. {gpiod-2.4.2 → gpiod-2.5.0}/gpiod/ext/line-settings.c +0 -0
  48. {gpiod-2.4.2 → gpiod-2.5.0}/gpiod/line.py +0 -0
  49. {gpiod-2.4.2 → gpiod-2.5.0}/gpiod/py.typed +0 -0
  50. {gpiod-2.4.2 → gpiod-2.5.0}/gpiod.egg-info/dependency_links.txt +0 -0
  51. {gpiod-2.4.2 → gpiod-2.5.0}/gpiod.egg-info/top_level.txt +0 -0
  52. {gpiod-2.4.2 → gpiod-2.5.0}/include/gpiod.h +0 -0
  53. {gpiod-2.4.2 → gpiod-2.5.0}/lib/chip.c +0 -0
  54. {gpiod-2.4.2 → gpiod-2.5.0}/lib/info-event.c +0 -0
  55. {gpiod-2.4.2 → gpiod-2.5.0}/lib/internal.c +0 -0
  56. {gpiod-2.4.2 → gpiod-2.5.0}/lib/internal.h +0 -0
  57. {gpiod-2.4.2 → gpiod-2.5.0}/lib/line-settings.c +0 -0
  58. {gpiod-2.4.2 → gpiod-2.5.0}/lib/uapi/gpio.h +0 -0
  59. {gpiod-2.4.2 → gpiod-2.5.0}/setup.cfg +0 -0
  60. {gpiod-2.4.2 → gpiod-2.5.0}/tests/__init__.py +0 -0
  61. {gpiod-2.4.2 → gpiod-2.5.0}/tests/gpiosim/__init__.py +0 -0
  62. {gpiod-2.4.2 → gpiod-2.5.0}/tests/system/__init__.py +0 -0
  63. {gpiod-2.4.2 → gpiod-2.5.0}/tests/tests_chip_info.py +0 -0
  64. {gpiod-2.4.2 → gpiod-2.5.0}/tests/tests_line.py +0 -0
  65. {gpiod-2.4.2 → gpiod-2.5.0}/tests/tests_line_info.py +0 -0
  66. {gpiod-2.4.2 → gpiod-2.5.0}/tests/tests_line_request.py +0 -0
  67. {gpiod-2.4.2 → gpiod-2.5.0}/tests/tests_line_settings.py +0 -0
  68. {gpiod-2.4.2 → gpiod-2.5.0}/tests/tests_module.py +0 -0
@@ -0,0 +1,47 @@
1
+ <!-- SPDX-License-Identifier: CC-BY-SA-4.0 -->
2
+ <!-- SPDX-FileCopyrightText: 2026 Vincent Fazio <vfazio@gmail.com> -->
3
+
4
+ # Changelog
5
+
6
+ All notable changes to this project will be documented in this file.
7
+
8
+ The format is loosely based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
9
+
10
+ ## [Unreleased]
11
+
12
+ ### Added
13
+
14
+ - Add free-threaded CPython support
15
+ - Generate wheels for CPython 3.14t (free-threaded)
16
+ - Include the license file into the source and binary distributions
17
+
18
+ ### Changed
19
+
20
+ - Remove `wheel` from build dependencies
21
+ - Allow `Chip.close` to be called multiple times without raising an error
22
+ - Allow `LineRequest.release` to be called multiple times without raising an error
23
+ - (Internal) Add more patterns to `.gitignore`
24
+ - (Internal) Update linter configuration
25
+ - (Internal) Refactor code to conform to updated linter configuration
26
+ - (Internal) Refactor code to use Python 3.10 type annotations
27
+ - (Internal) Introduce a dependency group for linting
28
+ - (Internal) Simplify Chip finalization
29
+ - (Internal) Simplify LineRequest finalization
30
+ - (Internal) Use newer functions/macros in the C extension.
31
+ - (Internal) Migrate to multi-phase module initialization
32
+ - (Internal) Removed duplicate call to `gpiod_line_settings_set_edge_detection`
33
+ - (Internal) Add multi-threaded tests
34
+
35
+ ### Fixed
36
+
37
+ - Fix refcount imbalance due to missing `Py_INCREF` when querying line names
38
+ - Fix refcount imbalance by not calling `Py_DECREF` when `PyList_SetItem` fails
39
+ - Require `setuptools` v77 or higher to avoid build errors
40
+
41
+ ### Security
42
+
43
+ - Fix possible buffer overflows when setting/getting `LineRequest` values
44
+
45
+ ### Removed
46
+
47
+ - Support for Python 3.9 has been dropped
@@ -5,6 +5,7 @@ include setup.py
5
5
  include build_tests.py
6
6
  include README.md
7
7
  include libgpiod-version.txt
8
+ include CHANGELOG.md
8
9
 
9
10
  recursive-include gpiod *.py
10
11
  recursive-include tests *.py
@@ -1,11 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gpiod
3
- Version: 2.4.2
3
+ Version: 2.5.0
4
4
  Summary: Python bindings for libgpiod
5
5
  Author-email: Bartosz Golaszewski <brgl@bgdev.pl>
6
6
  License-Expression: LGPL-2.1-or-later
7
7
  Project-URL: Homepage, https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git
8
8
  Project-URL: Issues, https://github.com/brgl/libgpiod/issues/
9
+ Project-URL: Changelog, https://github.com/brgl/libgpiod/blob/master/bindings/python/CHANGELOG.md
9
10
  Platform: linux
10
11
  Classifier: Development Status :: 5 - Production/Stable
11
12
  Classifier: Operating System :: POSIX :: Linux
@@ -13,13 +14,13 @@ Classifier: Typing :: Typed
13
14
  Classifier: Programming Language :: Python
14
15
  Classifier: Programming Language :: Python :: 3
15
16
  Classifier: Programming Language :: Python :: 3 :: Only
16
- Classifier: Programming Language :: Python :: 3.9
17
17
  Classifier: Programming Language :: Python :: 3.10
18
18
  Classifier: Programming Language :: Python :: 3.11
19
19
  Classifier: Programming Language :: Python :: 3.12
20
20
  Classifier: Programming Language :: Python :: 3.13
21
21
  Classifier: Programming Language :: Python :: 3.14
22
- Requires-Python: >=3.9.0
22
+ Classifier: Programming Language :: Python :: Free Threading :: 3 - Stable
23
+ Requires-Python: >=3.10
23
24
  Description-Content-Type: text/markdown
24
25
  License-File: LICENSE
25
26
  Dynamic: license-file
@@ -31,10 +32,16 @@ Dynamic: license-file
31
32
 
32
33
  These are the official Python bindings for [libgpiod](https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/about/).
33
34
 
35
+ Both GIL-enabled and free-threaded CPython are supported.
36
+
37
+ The Python bindings, much like the C API they wrap, are not thread-safe and do
38
+ require external synchronization by the caller to serialize access to objects
39
+ shared across threads.
40
+
34
41
  The gpiod library has been vendored into this package for your convenience and
35
42
  this version of gpiod is independent from your system package.
36
43
 
37
- Binary wheels are not provided. The source package requires python3-dev.
44
+ Binary wheels are provided for some platforms. The source package requires python3-dev.
38
45
 
39
46
  ## Rationale
40
47
 
@@ -133,7 +140,7 @@ with gpiod.request_lines(
133
140
  The test suite for the python bindings can be run by calling:
134
141
 
135
142
  ```
136
- make python-tests-run
143
+ python -B -m tests
137
144
  ```
138
145
 
139
146
  from the `libgpiod/bindings/python` directory as root (necessary to be able
@@ -146,10 +153,12 @@ When making changes, ensure type checks and linting still pass:
146
153
  ```
147
154
  python3 -m venv venv
148
155
  . venv/bin/activate
149
- pip install mypy ruff
156
+ pip install --group lint
150
157
  mypy; ruff format; ruff check
151
158
  ```
152
159
 
160
+ Note that pip >=25.1 is necessary for `--group` support.
161
+
153
162
  Ideally the gpiod library will continue to pass strict checks:
154
163
 
155
164
  ```
@@ -5,10 +5,16 @@
5
5
 
6
6
  These are the official Python bindings for [libgpiod](https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/about/).
7
7
 
8
+ Both GIL-enabled and free-threaded CPython are supported.
9
+
10
+ The Python bindings, much like the C API they wrap, are not thread-safe and do
11
+ require external synchronization by the caller to serialize access to objects
12
+ shared across threads.
13
+
8
14
  The gpiod library has been vendored into this package for your convenience and
9
15
  this version of gpiod is independent from your system package.
10
16
 
11
- Binary wheels are not provided. The source package requires python3-dev.
17
+ Binary wheels are provided for some platforms. The source package requires python3-dev.
12
18
 
13
19
  ## Rationale
14
20
 
@@ -107,7 +113,7 @@ with gpiod.request_lines(
107
113
  The test suite for the python bindings can be run by calling:
108
114
 
109
115
  ```
110
- make python-tests-run
116
+ python -B -m tests
111
117
  ```
112
118
 
113
119
  from the `libgpiod/bindings/python` directory as root (necessary to be able
@@ -120,12 +126,14 @@ When making changes, ensure type checks and linting still pass:
120
126
  ```
121
127
  python3 -m venv venv
122
128
  . venv/bin/activate
123
- pip install mypy ruff
129
+ pip install --group lint
124
130
  mypy; ruff format; ruff check
125
131
  ```
126
132
 
133
+ Note that pip >=25.1 is necessary for `--group` support.
134
+
127
135
  Ideally the gpiod library will continue to pass strict checks:
128
136
 
129
137
  ```
130
138
  mypy --strict
131
- ```
139
+ ```
@@ -19,15 +19,14 @@ import glob
19
19
  import tempfile
20
20
  from os import getenv, path
21
21
 
22
- from setuptools import Distribution, Extension
22
+ from setuptools import Distribution, Extension, logging
23
23
  from setuptools.command.build_ext import build_ext
24
24
 
25
+ logging.configure()
26
+
25
27
  TOP_SRCDIR = getenv("TOP_SRCDIR", "../../")
26
28
  TOP_BUILDDIR = getenv("TOP_BUILDDIR", "../../")
27
29
 
28
- # __version__
29
- with open("gpiod/version.py", "r") as fd:
30
- exec(fd.read())
31
30
 
32
31
  # The tests are run in-place with PYTHONPATH set to bindings/python
33
32
  # so we need the gpiod extension module too.
@@ -70,26 +69,10 @@ system_ext = Extension(
70
69
 
71
70
  dist = Distribution(
72
71
  {
73
- "name": "gpiod",
74
72
  "ext_modules": [gpiosim_ext, system_ext, gpiod_ext],
75
- "version": __version__,
76
- "platforms": ["linux"],
77
73
  }
78
74
  )
79
75
 
80
- try:
81
- from setuptools.logging import configure
82
-
83
- configure()
84
- except ImportError:
85
- try:
86
- from distutils.log import DEBUG, set_verbosity
87
-
88
- set_verbosity(DEBUG)
89
- except ImportError:
90
- # We can still build the tests, it will just be very quiet.
91
- pass
92
-
93
76
  with tempfile.TemporaryDirectory(prefix="libgpiod-") as temp_dir:
94
77
  command = build_ext(dist)
95
78
  command.inplace = True
@@ -8,7 +8,6 @@ This module wraps the native C API of libgpiod in a set of python classes.
8
8
  """
9
9
 
10
10
  from collections.abc import Iterable
11
- from typing import Optional, Union
12
11
 
13
12
  from . import (
14
13
  _ext,
@@ -87,10 +86,10 @@ def is_gpiochip_device(path: str) -> bool:
87
86
 
88
87
  def request_lines(
89
88
  path: str,
90
- config: dict[Union[Iterable[Union[int, str]], int, str], Optional[LineSettings]],
91
- consumer: Optional[str] = None,
92
- event_buffer_size: Optional[int] = None,
93
- output_values: Optional[dict[Union[int, str], line.Value]] = None,
89
+ config: dict[Iterable[int | str] | int | str, LineSettings | None],
90
+ consumer: str | None = None,
91
+ event_buffer_size: int | None = None,
92
+ output_values: dict[int | str, line.Value] | None = None,
94
93
  ) -> LineRequest:
95
94
  """
96
95
  Open a GPIO chip pointed to by 'path', request lines according to the
@@ -1,8 +1,6 @@
1
1
  # SPDX-License-Identifier: LGPL-2.1-or-later
2
2
  # SPDX-FileCopyrightText: 2024 Vincent Fazio <vfazio@gmail.com>
3
3
 
4
- from typing import Optional
5
-
6
4
  from .chip_info import ChipInfo
7
5
  from .edge_event import EdgeEvent
8
6
  from .info_event import InfoEvent
@@ -32,7 +30,7 @@ class Request:
32
30
  def get_values(self, offsets: list[int], values: list[Value]) -> None: ...
33
31
  def set_values(self, values: dict[int, Value]) -> None: ...
34
32
  def reconfigure_lines(self, line_cfg: LineConfig) -> None: ...
35
- def read_edge_events(self, max_events: Optional[int]) -> list[EdgeEvent]: ...
33
+ def read_edge_events(self, max_events: int | None) -> list[EdgeEvent]: ...
36
34
  @property
37
35
  def chip_name(self) -> str: ...
38
36
  @property
@@ -47,12 +45,12 @@ class Chip:
47
45
  def get_info(self) -> ChipInfo: ...
48
46
  def line_offset_from_id(self, id: str) -> int: ...
49
47
  def get_line_info(self, offset: int, watch: bool) -> LineInfo: ...
50
- def get_line_name(self, offset: int) -> Optional[str]: ...
48
+ def get_line_name(self, offset: int) -> str | None: ...
51
49
  def request_lines(
52
50
  self,
53
51
  line_cfg: LineConfig,
54
- consumer: Optional[str],
55
- event_buffer_size: Optional[int],
52
+ consumer: str | None,
53
+ event_buffer_size: int | None,
56
54
  ) -> Request: ...
57
55
  def read_info_event(self) -> InfoEvent: ...
58
56
  def close(self) -> None: ...
@@ -5,7 +5,7 @@ from __future__ import annotations
5
5
 
6
6
  from datetime import timedelta
7
7
  from select import select
8
- from typing import TYPE_CHECKING, Optional, Union
8
+ from typing import TYPE_CHECKING
9
9
 
10
10
  if TYPE_CHECKING:
11
11
  from collections.abc import Generator, Iterable
@@ -15,8 +15,8 @@ if TYPE_CHECKING:
15
15
  __all__ = ["poll_fd", "config_iter"]
16
16
 
17
17
 
18
- def poll_fd(fd: int, timeout: Optional[Union[timedelta, float]] = None) -> bool:
19
- sec: Union[float, None]
18
+ def poll_fd(fd: int, timeout: timedelta | float | None = None) -> bool:
19
+ sec: float | None
20
20
  if isinstance(timeout, timedelta):
21
21
  sec = timeout.total_seconds()
22
22
  else:
@@ -27,8 +27,8 @@ def poll_fd(fd: int, timeout: Optional[Union[timedelta, float]] = None) -> bool:
27
27
 
28
28
 
29
29
  def config_iter(
30
- config: dict[Union[Iterable[Union[int, str]], int, str], Optional[LineSettings]],
31
- ) -> Generator[tuple[Union[int, str], Optional[LineSettings]]]:
30
+ config: dict[Iterable[int | str] | int | str, LineSettings | None],
31
+ ) -> Generator[tuple[int | str, LineSettings | None]]:
32
32
  for key, settings in config.items():
33
33
  if isinstance(key, int) or isinstance(key, str):
34
34
  yield key, settings
@@ -4,7 +4,7 @@
4
4
  from __future__ import annotations
5
5
 
6
6
  from errno import ENOENT
7
- from typing import TYPE_CHECKING, Optional, Union, cast
7
+ from typing import TYPE_CHECKING, cast
8
8
 
9
9
  from . import _ext
10
10
  from ._internal import config_iter, poll_fd
@@ -50,6 +50,9 @@ class Chip:
50
50
 
51
51
  with gpiod.Chip(path="/dev/gpiochip0") as chip:
52
52
  do_something(chip)
53
+
54
+ Synchronization: objects of this class require external synchronization.
55
+ Protect calls with a lock when sharing an instance across threads.
53
56
  """
54
57
 
55
58
  def __init__(self, path: str):
@@ -60,8 +63,8 @@ class Chip:
60
63
  path:
61
64
  Path to the GPIO character device file.
62
65
  """
63
- self._chip: Union[_ext.Chip, None] = _ext.Chip(path)
64
- self._info: Union[ChipInfo, None] = None
66
+ self._chip: _ext.Chip | None = _ext.Chip(path)
67
+ self._info: ChipInfo | None = None
65
68
 
66
69
  def __bool__(self) -> bool:
67
70
  """
@@ -81,9 +84,9 @@ class Chip:
81
84
 
82
85
  def __exit__(
83
86
  self,
84
- exc_type: Optional[type[BaseException]],
85
- exc_value: Optional[BaseException],
86
- traceback: Optional[TracebackType],
87
+ exc_type: type[BaseException] | None,
88
+ exc_value: BaseException | None,
89
+ traceback: TracebackType | None,
87
90
  ) -> None:
88
91
  """
89
92
  Controlled execution exit callback.
@@ -99,9 +102,9 @@ class Chip:
99
102
  Close the associated GPIO chip descriptor. The chip object must no
100
103
  longer be used after this method is called.
101
104
  """
102
- self._check_closed()
103
- cast("_ext.Chip", self._chip).close()
104
- self._chip = None
105
+ if self._chip is not None:
106
+ self._chip.close()
107
+ self._chip = None
105
108
 
106
109
  def get_info(self) -> ChipInfo:
107
110
  """
@@ -117,7 +120,7 @@ class Chip:
117
120
 
118
121
  return self._info
119
122
 
120
- def line_offset_from_id(self, id: Union[str, int]) -> int:
123
+ def line_offset_from_id(self, id: str | int) -> int:
121
124
  """
122
125
  Map a line's identifier to its offset within the chip.
123
126
 
@@ -155,13 +158,13 @@ class Chip:
155
158
 
156
159
  return offset
157
160
 
158
- def _get_line_info(self, line: Union[int, str], watch: bool) -> LineInfo:
161
+ def _get_line_info(self, line: int | str, watch: bool) -> LineInfo:
159
162
  self._check_closed()
160
163
  return cast("_ext.Chip", self._chip).get_line_info(
161
164
  self.line_offset_from_id(line), watch
162
165
  )
163
166
 
164
- def get_line_info(self, line: Union[int, str]) -> LineInfo:
167
+ def get_line_info(self, line: int | str) -> LineInfo:
165
168
  """
166
169
  Get the snapshot of information about the line at given offset.
167
170
 
@@ -174,7 +177,7 @@ class Chip:
174
177
  """
175
178
  return self._get_line_info(line, watch=False)
176
179
 
177
- def watch_line_info(self, line: Union[int, str]) -> LineInfo:
180
+ def watch_line_info(self, line: int | str) -> LineInfo:
178
181
  """
179
182
  Get the snapshot of information about the line at given offset and
180
183
  start watching it for future changes.
@@ -188,7 +191,7 @@ class Chip:
188
191
  """
189
192
  return self._get_line_info(line, watch=True)
190
193
 
191
- def unwatch_line_info(self, line: Union[int, str]) -> None:
194
+ def unwatch_line_info(self, line: int | str) -> None:
192
195
  """
193
196
  Stop watching a line for status changes.
194
197
 
@@ -201,9 +204,7 @@ class Chip:
201
204
  self.line_offset_from_id(line)
202
205
  )
203
206
 
204
- def wait_info_event(
205
- self, timeout: Optional[Union[timedelta, float]] = None
206
- ) -> bool:
207
+ def wait_info_event(self, timeout: timedelta | float | None = None) -> bool:
207
208
  """
208
209
  Wait for line status change events on any of the watched lines on the
209
210
  chip.
@@ -237,12 +238,10 @@ class Chip:
237
238
 
238
239
  def request_lines(
239
240
  self,
240
- config: dict[
241
- Union[Iterable[Union[int, str]], int, str], Optional[LineSettings]
242
- ],
243
- consumer: Optional[str] = None,
244
- event_buffer_size: Optional[int] = None,
245
- output_values: Optional[dict[Union[int, str], Value]] = None,
241
+ config: dict[Iterable[int | str] | int | str, LineSettings | None],
242
+ consumer: str | None = None,
243
+ event_buffer_size: int | None = None,
244
+ output_values: dict[int | str, Value] | None = None,
246
245
  ) -> LineRequest:
247
246
  """
248
247
  Request a set of lines for exclusive usage.
@@ -10,7 +10,9 @@ __all__ = ["ChipInfo"]
10
10
  @dataclass(frozen=True, repr=False)
11
11
  class ChipInfo:
12
12
  """
13
- Snapshot of a chip's status.
13
+ Immutable snapshot of a chip's status.
14
+
15
+ Synchronization: none required
14
16
  """
15
17
 
16
18
  name: str
@@ -13,6 +13,8 @@ __all__ = ["EdgeEvent"]
13
13
  class EdgeEvent:
14
14
  """
15
15
  Immutable object containing data about a single edge event.
16
+
17
+ Synchronization: none required
16
18
  """
17
19
 
18
20
  class Type(Enum):
@@ -32,10 +32,19 @@ chip_init(chip_object *self, PyObject *args, PyObject *Py_UNUSED(ignored))
32
32
  return 0;
33
33
  }
34
34
 
35
+ static void internal_chip_close(chip_object *self)
36
+ {
37
+ if (self->chip) {
38
+ Py_BEGIN_ALLOW_THREADS;
39
+ gpiod_chip_close(self->chip);
40
+ Py_END_ALLOW_THREADS;
41
+ self->chip = NULL;
42
+ }
43
+ }
44
+
35
45
  static void chip_finalize(chip_object *self)
36
46
  {
37
- if (self->chip)
38
- PyObject_CallMethod((PyObject *)self, "close", "");
47
+ internal_chip_close(self);
39
48
  }
40
49
 
41
50
  static PyObject *chip_path(chip_object *self, void *Py_UNUSED(ignored))
@@ -62,10 +71,7 @@ static PyGetSetDef chip_getset[] = {
62
71
 
63
72
  static PyObject *chip_close(chip_object *self, PyObject *Py_UNUSED(ignored))
64
73
  {
65
- Py_BEGIN_ALLOW_THREADS;
66
- gpiod_chip_close(self->chip);
67
- Py_END_ALLOW_THREADS;
68
- self->chip = NULL;
74
+ internal_chip_close(self);
69
75
 
70
76
  Py_RETURN_NONE;
71
77
  }
@@ -79,7 +85,9 @@ static PyObject *chip_get_info(chip_object *self, PyObject *Py_UNUSED(ignored))
79
85
  if (!type)
80
86
  return NULL;
81
87
 
88
+ Py_BEGIN_ALLOW_THREADS;
82
89
  info = gpiod_chip_get_info(self->chip);
90
+ Py_END_ALLOW_THREADS;
83
91
  if (!info) {
84
92
  Py_DECREF(type);
85
93
  return PyErr_SetFromErrno(PyExc_OSError);
@@ -166,12 +174,7 @@ static PyObject *chip_get_line_name(chip_object *self, PyObject *args)
166
174
  return Py_gpiod_SetErrFromErrno();
167
175
 
168
176
  name = gpiod_line_info_get_name(info);
169
- if (!name) {
170
- Py_INCREF(Py_None);
171
- line_name = Py_None;
172
- } else {
173
- line_name = PyUnicode_FromString(name);
174
- }
177
+ line_name = (name) ? PyUnicode_FromString(name) : Py_NewRef(Py_None);
175
178
 
176
179
  gpiod_line_info_free(info);
177
180
 
@@ -266,7 +269,7 @@ make_request_config(PyObject *consumer_obj, PyObject *event_buffer_size_obj)
266
269
  return NULL;
267
270
  }
268
271
 
269
- if (consumer_obj != Py_None) {
272
+ if (!Py_IsNone(consumer_obj)) {
270
273
  consumer = PyUnicode_AsUTF8(consumer_obj);
271
274
  if (!consumer) {
272
275
  gpiod_request_config_free(req_cfg);
@@ -276,7 +279,7 @@ make_request_config(PyObject *consumer_obj, PyObject *event_buffer_size_obj)
276
279
  gpiod_request_config_set_consumer(req_cfg, consumer);
277
280
  }
278
281
 
279
- if (event_buffer_size_obj != Py_None) {
282
+ if (!Py_IsNone(event_buffer_size_obj)) {
280
283
  event_buffer_size = PyLong_AsSize_t(event_buffer_size_obj);
281
284
  if (PyErr_Occurred()) {
282
285
  gpiod_request_config_free(req_cfg);
@@ -12,7 +12,7 @@ void Py_gpiod_dealloc(PyObject *self)
12
12
  if (ret < 0)
13
13
  return;
14
14
 
15
- PyObject_Del(self);
15
+ PyObject_Free(self);
16
16
  }
17
17
 
18
18
  PyObject *Py_gpiod_SetErrFromErrno(void)
@@ -64,6 +64,8 @@ PyObject *Py_gpiod_SetErrFromErrno(void)
64
64
  return PyErr_SetFromErrno(exc);
65
65
  }
66
66
 
67
+ /* TODO: remove when 3.14 is the minimum version */
68
+ #if PY_VERSION_HEX < 0x030E0000
67
69
  PyObject *Py_gpiod_GetModuleAttrString(const char *modname,
68
70
  const char *attrname)
69
71
  {
@@ -78,6 +80,7 @@ PyObject *Py_gpiod_GetModuleAttrString(const char *modname,
78
80
 
79
81
  return attribute;
80
82
  }
83
+ #endif
81
84
 
82
85
  unsigned int Py_gpiod_PyLongAsUnsignedInt(PyObject *pylong)
83
86
  {
@@ -8,8 +8,6 @@
8
8
  #include <Python.h>
9
9
 
10
10
  PyObject *Py_gpiod_SetErrFromErrno(void);
11
- PyObject *Py_gpiod_GetModuleAttrString(const char *modname,
12
- const char *attrname);
13
11
  unsigned int Py_gpiod_PyLongAsUnsignedInt(PyObject *pylong);
14
12
  void Py_gpiod_dealloc(PyObject *self);
15
13
  PyObject *Py_gpiod_MakeRequestObject(struct gpiod_line_request *request,
@@ -17,4 +15,12 @@ PyObject *Py_gpiod_MakeRequestObject(struct gpiod_line_request *request,
17
15
  struct gpiod_line_config *Py_gpiod_LineConfigGetData(PyObject *obj);
18
16
  struct gpiod_line_settings *Py_gpiod_LineSettingsGetData(PyObject *obj);
19
17
 
18
+ #if PY_VERSION_HEX >= 0x030E0000
19
+ /* Alias to standard function available in 3.14 */
20
+ #define Py_gpiod_GetModuleAttrString PyImport_ImportModuleAttrString
21
+ #else
22
+ PyObject *Py_gpiod_GetModuleAttrString(const char *modname,
23
+ const char *attrname);
24
+ #endif /* PY_VERSION_HEX >= 0x030E0000 */
25
+
20
26
  #endif /* __LIBGPIOD_PYTHON_MODULE_H__ */
@@ -119,6 +119,10 @@ line_config_set_output_values(line_config_object *self, PyObject *args)
119
119
  next = PyIter_Next(iter);
120
120
  if (!next) {
121
121
  Py_DECREF(iter);
122
+ if (PyErr_Occurred()) {
123
+ PyMem_Free(valbuf);
124
+ return NULL;
125
+ }
122
126
  break;
123
127
  }
124
128