bindings: python: specify the symbols to export explicitly
PATCH 1/1 bindings: python: specify the symbols to export explicitly
From: Bartosz Golaszewski <[email protected]>
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 <[email protected]>
--- bindings/python/gpiod/chip.py | 2 ++ bindings/python/gpiod/chip_info.py | 2 ++ bindings/python/gpiod/edge_event.py | 2 ++ bindings/python/gpiod/exception.py | 2 ++ bindings/python/gpiod/ext/module.c | 15 ++++++++++++++- bindings/python/gpiod/info_event.py | 2 ++ bindings/python/gpiod/internal.py | 2 ++ bindings/python/gpiod/line.py | 2 ++ bindings/python/gpiod/line_info.py | 2 ++ bindings/python/gpiod/line_request.py | 2 ++ bindings/python/gpiod/line_settings.py | 2 ++ 11 files changed, 34 insertions(+), 1 deletion(-)
bindings/python/gpiod/chip.py +2 -0
@@ -17,6 +17,8 @@ from errno import ENOENT from select import select from typing import Union, Optional +__all__ = "Chip" + class Chip: """
bindings/python/gpiod/chip_info.py +2 -0
@@ -4,6 +4,8 @@ from dataclasses import dataclass +__all__ = "ChipInfo" + @dataclass(frozen=True, repr=False) class ChipInfo:
bindings/python/gpiod/edge_event.py +2 -0
@@ -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:
bindings/python/gpiod/exception.py +2 -0
@@ -1,6 +1,8 @@ # SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <[email protected]> +__all__ = ["ChipClosedError", "RequestReleasedError"] + class ChipClosedError(Exception): """
bindings/python/gpiod/ext/module.c +14 -1
@@ -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) {
bindings/python/gpiod/info_event.py +2 -0
@@ -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:
bindings/python/gpiod/internal.py +2 -0
@@ -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):
bindings/python/gpiod/line.py +2 -0
@@ -5,6 +5,8 @@ from . import _ext from enum import Enum +__all__ = ["Value", "Direction", "Bias", "Drive", "Edge", "Clock"] + class Value(Enum): """Logical line states."""
bindings/python/gpiod/line_info.py +2 -0
@@ -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:
bindings/python/gpiod/line_request.py +2 -0
@@ -11,6 +11,8 @@ from collections.abc import Iterable from datetime import timedelta from typing import Optional, Union +__all__ = "LineRequest" + class LineRequest: """
bindings/python/gpiod/line_settings.py +2 -0
@@ -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:
Signature · 1 line
2.39.2