bindings: python: specify the symbols to export explicitly
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Thu, 25 May 2023 12:02:10 +0000 (14:02 +0200)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Thu, 25 May 2023 13:30:25 +0000 (15:30 +0200)
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>
bindings/python/gpiod/chip.py
bindings/python/gpiod/chip_info.py
bindings/python/gpiod/edge_event.py
bindings/python/gpiod/exception.py
bindings/python/gpiod/ext/module.c
bindings/python/gpiod/info_event.py
bindings/python/gpiod/internal.py
bindings/python/gpiod/line.py
bindings/python/gpiod/line_info.py
bindings/python/gpiod/line_request.py
bindings/python/gpiod/line_settings.py

index 52d0757efb0641d597d9e3b998f66a867fbcdd75..da93370e7713f7336aa343af7c3d2b2ef29b70e3 100644 (file)
@@ -17,6 +17,8 @@ from errno import ENOENT
 from select import select
 from typing import Union, Optional
 
+__all__ = "Chip"
+
 
 class Chip:
     """
index a506b55b4c6ba471e4c022b2214f907f2ed4eaf1..92b5e6f23c7117eaaa3e73ed27305116de7b0af2 100644 (file)
@@ -4,6 +4,8 @@
 
 from dataclasses import dataclass
 
+__all__ = "ChipInfo"
+
 
 @dataclass(frozen=True, repr=False)
 class ChipInfo:
index 88f8e9b0a5b4dc773dad04bd59d7c053acb650a3..bf258c1472abc7b0faa40ed6533c68cefcd85b6b 100644 (file)
@@ -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:
index 07ffaa625a080f7523e961c7263ed3aad0a4af59..f9a83c27b73c4ac3a0f4fac1c1b4421b22545645 100644 (file)
@@ -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):
     """
index 101d7568e46f33a4e4e367b9884d9b9c3ba24eaa..25c252a7dc0a363c9d1963cbe93d6663dff2b749 100644 (file)
@@ -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) {
index 78b1459c1c17f9cc49f7b6b8a809aff1c4f533b7..481eae6c376bc6cb418e03be84511b0de811ff91 100644 (file)
@@ -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:
index 7b4598cb03b573425d3dcd4367d8d24c8cc0023d..2dddb65027ab6a3f8b590a65050203d3189fb8c8 100644 (file)
@@ -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):
index c5d5ddf0ae93fbd860df67753be35285d08671e6..1cc512f7312f20712fa84fac1383495b641ebfee 100644 (file)
@@ -5,6 +5,8 @@
 from . import _ext
 from enum import Enum
 
+__all__ = ["Value", "Direction", "Bias", "Drive", "Edge", "Clock"]
+
 
 class Value(Enum):
     """Logical line states."""
index 9a6c9bff17b89563088a53f07aa08dd2b8e0822e..c196a6aedeb48223ff5aec27b415c3ac690a84b1 100644 (file)
@@ -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:
index 090467ca13d0fe917774a87aeb36d80f36eee702..096bf1897561686a4d7e855f9d2c0c326c789c76 100644 (file)
@@ -11,6 +11,8 @@ from collections.abc import Iterable
 from datetime import timedelta
 from typing import Optional, Union
 
+__all__ = "LineRequest"
+
 
 class LineRequest:
     """
index e02e9324b92201f0a2a2576720598bb0e3008c03..458fd8163f04c9a461f8522be284bf404b55bc18 100644 (file)
@@ -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: