diff options
author | Bartosz Golaszewski <bartosz.golaszewski@linaro.org> | 2023-05-25 14:02:10 +0200 |
---|---|---|
committer | Bartosz Golaszewski <bartosz.golaszewski@linaro.org> | 2023-05-25 15:30:25 +0200 |
commit | 4687bcc4f48a9894469ee240e0c67c42d56169c3 (patch) | |
tree | 8322b8c719d74f8de615bf3b75456ac49d111e9b | |
parent | c6b0cd777010f0cf00c3d04b00efd79353b66174 (diff) | |
download | libgpiod-4687bcc4f48a9894469ee240e0c67c42d56169c3.tar.gz |
bindings: python: specify the symbols to export explicitly
We're currently unintentionally exporting a bunch of symbols that should
remain local to sub-modules. Use __all__ where appropriate so that we
don't re-export standard library functions such as select() etc. in the
gpiod module.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
-rw-r--r-- | bindings/python/gpiod/chip.py | 2 | ||||
-rw-r--r-- | bindings/python/gpiod/chip_info.py | 2 | ||||
-rw-r--r-- | bindings/python/gpiod/edge_event.py | 2 | ||||
-rw-r--r-- | bindings/python/gpiod/exception.py | 2 | ||||
-rw-r--r-- | bindings/python/gpiod/ext/module.c | 15 | ||||
-rw-r--r-- | bindings/python/gpiod/info_event.py | 2 | ||||
-rw-r--r-- | bindings/python/gpiod/internal.py | 2 | ||||
-rw-r--r-- | bindings/python/gpiod/line.py | 2 | ||||
-rw-r--r-- | bindings/python/gpiod/line_info.py | 2 | ||||
-rw-r--r-- | bindings/python/gpiod/line_request.py | 2 | ||||
-rw-r--r-- | bindings/python/gpiod/line_settings.py | 2 |
11 files changed, 34 insertions, 1 deletions
diff --git a/bindings/python/gpiod/chip.py b/bindings/python/gpiod/chip.py index 52d0757e..da93370e 100644 --- a/bindings/python/gpiod/chip.py +++ b/bindings/python/gpiod/chip.py @@ -17,6 +17,8 @@ from errno import ENOENT from select import select from typing import Union, Optional +__all__ = "Chip" + class Chip: """ diff --git a/bindings/python/gpiod/chip_info.py b/bindings/python/gpiod/chip_info.py index a506b55b..92b5e6f2 100644 --- a/bindings/python/gpiod/chip_info.py +++ b/bindings/python/gpiod/chip_info.py @@ -4,6 +4,8 @@ from dataclasses import dataclass +__all__ = "ChipInfo" + @dataclass(frozen=True, repr=False) class ChipInfo: diff --git a/bindings/python/gpiod/edge_event.py b/bindings/python/gpiod/edge_event.py index 88f8e9b0..bf258c14 100644 --- a/bindings/python/gpiod/edge_event.py +++ b/bindings/python/gpiod/edge_event.py @@ -5,6 +5,8 @@ from . import _ext from dataclasses import dataclass from enum import Enum +__all__ = "EdgeEvent" + @dataclass(frozen=True, init=False, repr=False) class EdgeEvent: diff --git a/bindings/python/gpiod/exception.py b/bindings/python/gpiod/exception.py index 07ffaa62..f9a83c27 100644 --- a/bindings/python/gpiod/exception.py +++ b/bindings/python/gpiod/exception.py @@ -1,6 +1,8 @@ # SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl> +__all__ = ["ChipClosedError", "RequestReleasedError"] + class ChipClosedError(Exception): """ diff --git a/bindings/python/gpiod/ext/module.c b/bindings/python/gpiod/ext/module.c index 101d7568..25c252a7 100644 --- a/bindings/python/gpiod/ext/module.c +++ b/bindings/python/gpiod/ext/module.c @@ -157,8 +157,8 @@ static PyTypeObject *types[] = { PyMODINIT_FUNC PyInit__ext(void) { const struct module_const *modconst; + PyObject *module, *all; PyTypeObject **type; - PyObject *module; int ret; module = PyModule_Create(&module_def); @@ -172,6 +172,19 @@ PyMODINIT_FUNC PyInit__ext(void) return NULL; } + all = PyList_New(0); + if (!all) { + Py_DECREF(module); + return NULL; + } + + ret = PyModule_AddObjectRef(module, "__all__", all); + Py_DECREF(all); + if (ret) { + Py_DECREF(module); + return NULL; + } + for (type = types; *type; type++) { ret = PyModule_AddType(module, *type); if (ret) { diff --git a/bindings/python/gpiod/info_event.py b/bindings/python/gpiod/info_event.py index 78b1459c..481eae6c 100644 --- a/bindings/python/gpiod/info_event.py +++ b/bindings/python/gpiod/info_event.py @@ -6,6 +6,8 @@ from .line_info import LineInfo from dataclasses import dataclass from enum import Enum +__all__ = "InfoEvent" + @dataclass(frozen=True, init=False, repr=False) class InfoEvent: diff --git a/bindings/python/gpiod/internal.py b/bindings/python/gpiod/internal.py index 7b4598cb..2dddb650 100644 --- a/bindings/python/gpiod/internal.py +++ b/bindings/python/gpiod/internal.py @@ -5,6 +5,8 @@ from datetime import timedelta from select import select from typing import Optional, Union +__all__ = [] + def poll_fd(fd: int, timeout: Optional[Union[timedelta, float]] = None) -> bool: if isinstance(timeout, timedelta): diff --git a/bindings/python/gpiod/line.py b/bindings/python/gpiod/line.py index c5d5ddf0..1cc512f7 100644 --- a/bindings/python/gpiod/line.py +++ b/bindings/python/gpiod/line.py @@ -5,6 +5,8 @@ from . import _ext from enum import Enum +__all__ = ["Value", "Direction", "Bias", "Drive", "Edge", "Clock"] + class Value(Enum): """Logical line states.""" diff --git a/bindings/python/gpiod/line_info.py b/bindings/python/gpiod/line_info.py index 9a6c9bff..c196a6ae 100644 --- a/bindings/python/gpiod/line_info.py +++ b/bindings/python/gpiod/line_info.py @@ -6,6 +6,8 @@ from dataclasses import dataclass from datetime import timedelta from gpiod.line import Direction, Bias, Drive, Edge, Clock +__all__ = "LineInfo" + @dataclass(frozen=True, init=False, repr=False) class LineInfo: diff --git a/bindings/python/gpiod/line_request.py b/bindings/python/gpiod/line_request.py index 090467ca..096bf189 100644 --- a/bindings/python/gpiod/line_request.py +++ b/bindings/python/gpiod/line_request.py @@ -11,6 +11,8 @@ from collections.abc import Iterable from datetime import timedelta from typing import Optional, Union +__all__ = "LineRequest" + class LineRequest: """ diff --git a/bindings/python/gpiod/line_settings.py b/bindings/python/gpiod/line_settings.py index e02e9324..458fd816 100644 --- a/bindings/python/gpiod/line_settings.py +++ b/bindings/python/gpiod/line_settings.py @@ -6,6 +6,8 @@ from dataclasses import dataclass from datetime import timedelta from gpiod.line import Direction, Bias, Drive, Edge, Clock, Value +__all__ = "LineSettings" + @dataclass(repr=False) class LineSettings: |