mirror of
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git
synced 2026-10-25 12:39:18 +03:00
* Update pyproject.toml to require Python 3.10+ for runtime * Update mypy's target version to 3.10 syntax * Drop ruff's target version as it's inferred by the project's requires-python value * Remove the linter settings that ignored UP007 & UP0045 * Update type annotations to conform to active linter rules Closes: https://github.com/brgl/libgpiod/issues/151 Signed-off-by: Vincent Fazio <vfazio@gmail.com> Link: https://patch.msgid.link/20260329182832.39824-1-vfazio@gmail.com Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
38 lines
1.0 KiB
Python
38 lines
1.0 KiB
Python
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
# SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import timedelta
|
|
from select import select
|
|
from typing import TYPE_CHECKING
|
|
|
|
if TYPE_CHECKING:
|
|
from collections.abc import Generator, Iterable
|
|
|
|
from .line_settings import LineSettings
|
|
|
|
__all__ = ["poll_fd", "config_iter"]
|
|
|
|
|
|
def poll_fd(fd: int, timeout: timedelta | float | None = None) -> bool:
|
|
sec: float | None
|
|
if isinstance(timeout, timedelta):
|
|
sec = timeout.total_seconds()
|
|
else:
|
|
sec = timeout
|
|
|
|
readable, _, _ = select([fd], [], [], sec)
|
|
return True if fd in readable else False
|
|
|
|
|
|
def config_iter(
|
|
config: dict[Iterable[int | str] | int | str, LineSettings | None],
|
|
) -> Generator[tuple[int | str, LineSettings | None]]:
|
|
for key, settings in config.items():
|
|
if isinstance(key, int) or isinstance(key, str):
|
|
yield key, settings
|
|
else:
|
|
for subkey in key:
|
|
yield subkey, settings
|