[libgpiod][PATCH] bindings: python: specify the symbols to export explicitly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx>

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@xxxxxxxxxx>
---
 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(-)

diff --git a/bindings/python/gpiod/chip.py b/bindings/python/gpiod/chip.py
index 52d0757..da93370 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 a506b55..92b5e6f 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 88f8e9b..bf258c1 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 07ffaa6..f9a83c2 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@xxxxxxxx>
 
+__all__ = ["ChipClosedError", "RequestReleasedError"]
+
 
 class ChipClosedError(Exception):
     """
diff --git a/bindings/python/gpiod/ext/module.c b/bindings/python/gpiod/ext/module.c
index 101d756..25c252a 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 78b1459..481eae6 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 7b4598c..2dddb65 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 c5d5ddf..1cc512f 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 9a6c9bf..c196a6a 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 090467c..096bf18 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 e02e932..458fd81 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:
-- 
2.39.2




[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux