From a47348099c024d4cd745c7efcd9c6846dc8ced7d Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Wed, 1 Oct 2025 08:34:19 +0200 Subject: [PATCH] Fix checking pyi files --- devolo_plc_api/device_api/deviceapi.py | 2 +- devolo_plc_api/device_api/deviceapi.pyi | 1 - devolo_plc_api/plcnet_api/plcnetapi.pyi | 1 - scripts/stubgen.py | 28 ------------------------- 4 files changed, 1 insertion(+), 31 deletions(-) diff --git a/devolo_plc_api/device_api/deviceapi.py b/devolo_plc_api/device_api/deviceapi.py index ef8a00e..930fcfe 100644 --- a/devolo_plc_api/device_api/deviceapi.py +++ b/devolo_plc_api/device_api/deviceapi.py @@ -78,7 +78,7 @@ def __init__(self, ip: str, session: AsyncClient, info: ZeroconfServiceInfo) -> self._version = info.properties["Version"] features: str = info.properties.get("Features", "") - self.features = features.split(",") if features else ["reset", "update", "led", "intmtg"] + self.features: list[str] = features.split(",") if features else ["reset", "update", "led", "intmtg"] self.password = "" @_feature("led") diff --git a/devolo_plc_api/device_api/deviceapi.pyi b/devolo_plc_api/device_api/deviceapi.pyi index 4381a91..3aeda26 100644 --- a/devolo_plc_api/device_api/deviceapi.pyi +++ b/devolo_plc_api/device_api/deviceapi.pyi @@ -2,7 +2,6 @@ @generated by stubgen. Do not edit manually! isort:skip_file """ -from __future__ import annotations from .multiap_pb2 import WifiMultiApGetResponse from .support_pb2 import SupportInfoDump from .updatefirmware_pb2 import UpdateFirmwareCheck diff --git a/devolo_plc_api/plcnet_api/plcnetapi.pyi b/devolo_plc_api/plcnet_api/plcnetapi.pyi index cfeb429..75858f1 100644 --- a/devolo_plc_api/plcnet_api/plcnetapi.pyi +++ b/devolo_plc_api/plcnet_api/plcnetapi.pyi @@ -2,7 +2,6 @@ @generated by stubgen. Do not edit manually! isort:skip_file """ -from __future__ import annotations from .getnetworkoverview_pb2 import GetNetworkOverview from devolo_plc_api.clients import Protobuf from devolo_plc_api.zeroconf import ZeroconfServiceInfo as ZeroconfServiceInfo diff --git a/scripts/stubgen.py b/scripts/stubgen.py index d2b35c6..f3f6525 100755 --- a/scripts/stubgen.py +++ b/scripts/stubgen.py @@ -2,13 +2,11 @@ """Generate stub files for API classes with async and sync interface.""" from __future__ import annotations -import re import sys from contextlib import suppress from copy import copy from pathlib import Path -from mypy.nodes import ConditionalExpr, Expression, ListExpr from mypy.stubgen import ( ASTStubGenerator, Options, @@ -29,22 +27,6 @@ class ApiStubGenerator(ASTStubGenerator): """Generate stub text from a mypy AST.""" - def get_str_type_of_node(self, rvalue: Expression, can_infer_optional: bool = False, can_be_any: bool = True) -> str: - """Get type of node as string.""" - if isinstance(rvalue, ConditionalExpr): - if_type = self.get_str_type_of_node(rvalue.if_expr, can_infer_optional=can_infer_optional, can_be_any=False) - else_type = self.get_str_type_of_node(rvalue.else_expr, can_infer_optional=can_infer_optional, can_be_any=False) - if if_type and else_type and if_type != else_type: - return f"{if_type} | {else_type}" - return if_type or else_type or "Any" if can_be_any else "" - if isinstance(rvalue, ListExpr): - list_item_type = { - self.get_str_type_of_node(item, can_infer_optional=can_infer_optional, can_be_any=can_be_any) - for item in rvalue.items - } - return f"list[{' | '.join(list_item_type)}]" - return super().get_str_type_of_node(rvalue, can_infer_optional=can_infer_optional, can_be_any=can_be_any) - def add_sync(self) -> None: """Add sync methods.""" output = copy(self._output) @@ -52,13 +34,6 @@ def add_sync(self) -> None: if "async" in output[i]: self.add(output[i].replace("async_", "").replace("async ", "")) - def fix_union_annotations(self) -> None: - """Fix Union annotations.""" - for i, output in enumerate(self._output): - if match := re.search(r"Union\[([a-z, ]+)\]", output): - types = match[1].replace(",", " |") - self._output[i] = output.replace(match[0], types) - def generate_stubs() -> None: """Generate stubs - main entry point for the program.""" @@ -101,9 +76,6 @@ def generate_stub_from_ast(mod: StubSource, target: str, parse_only: bool, inclu return mod.ast.accept(gen) - if "annotations" in mod.ast.future_import_flags: - gen.add_import_line("from __future__ import annotations\n") - gen.fix_union_annotations() gen.add_sync() old_output = ""