Skip to content

Commit 67aced2

Browse files
CopilotiMicknl
andcommitted
Fix import pollution and remove redundant enum conversion
- Replace wildcard imports with explicit enum re-exports in __init__.py - Remove redundant enum conversion logic in create_server_config (ServerConfig.__init__ already handles it) - Add type: ignore comments for mypy limitations with attrs constructors Co-authored-by: iMicknl <1424596+iMicknl@users.noreply.github.com>
1 parent 68db312 commit 67aced2

File tree

2 files changed

+39
-49
lines changed

2 files changed

+39
-49
lines changed

pyoverkiz/enums/__init__.py

Lines changed: 36 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,39 @@
11
"""Convenience re-exports for the enums package."""
22

3-
# flake8: noqa: F403
4-
5-
from enum import Enum
6-
7-
from pyoverkiz.enums import command as _command
8-
from pyoverkiz.enums import execution as _execution
9-
from pyoverkiz.enums import gateway as _gateway
10-
from pyoverkiz.enums import general as _general
11-
from pyoverkiz.enums import measured_value_type as _measured_value_type
12-
from pyoverkiz.enums import protocol as _protocol
13-
from pyoverkiz.enums import server as _server
14-
from pyoverkiz.enums import state as _state
15-
from pyoverkiz.enums import ui as _ui
16-
from pyoverkiz.enums import ui_profile as _ui_profile
17-
from pyoverkiz.enums.command import *
18-
from pyoverkiz.enums.execution import *
19-
from pyoverkiz.enums.gateway import *
20-
from pyoverkiz.enums.general import *
21-
from pyoverkiz.enums.measured_value_type import *
22-
from pyoverkiz.enums.protocol import *
23-
from pyoverkiz.enums.server import *
24-
from pyoverkiz.enums.state import *
25-
from pyoverkiz.enums.ui import *
26-
from pyoverkiz.enums.ui_profile import *
27-
28-
__all__ = sorted(
29-
{
30-
name
31-
for module in (
32-
_command,
33-
_execution,
34-
_gateway,
35-
_general,
36-
_measured_value_type,
37-
_protocol,
38-
_server,
39-
_state,
40-
_ui,
41-
_ui_profile,
42-
)
43-
for name, obj in vars(module).items()
44-
if isinstance(obj, type) and issubclass(obj, Enum)
45-
}
3+
# Explicitly re-export all Enum subclasses to avoid wildcard import issues
4+
from pyoverkiz.enums.command import CommandMode, OverkizCommand, OverkizCommandParam
5+
from pyoverkiz.enums.execution import (
6+
ExecutionState,
7+
ExecutionSubType,
8+
ExecutionType,
469
)
10+
from pyoverkiz.enums.gateway import GatewaySubType, GatewayType, UpdateBoxStatus
11+
from pyoverkiz.enums.general import DataType, EventName, FailureType, ProductType
12+
from pyoverkiz.enums.measured_value_type import MeasuredValueType
13+
from pyoverkiz.enums.protocol import Protocol
14+
from pyoverkiz.enums.server import APIType, Server
15+
from pyoverkiz.enums.ui import UIClass, UIWidget
16+
from pyoverkiz.enums.ui_profile import UIProfile
17+
18+
__all__ = [
19+
"APIType",
20+
"CommandMode",
21+
"DataType",
22+
"EventName",
23+
"ExecutionState",
24+
"ExecutionSubType",
25+
"ExecutionType",
26+
"FailureType",
27+
"GatewaySubType",
28+
"GatewayType",
29+
"MeasuredValueType",
30+
"OverkizCommand",
31+
"OverkizCommandParam",
32+
"ProductType",
33+
"Protocol",
34+
"Server",
35+
"UIClass",
36+
"UIProfile",
37+
"UIWidget",
38+
"UpdateBoxStatus",
39+
]

pyoverkiz/utils.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,14 @@ def create_server_config(
3737
configuration_url: str | None = None,
3838
) -> ServerConfig:
3939
"""Generate server configuration with the provided endpoint and metadata."""
40-
resolved_server = (
41-
server if isinstance(server, Server) or server is None else Server(server)
42-
)
43-
resolved_type = type if isinstance(type, APIType) else APIType(type)
40+
# ServerConfig.__init__ accepts str | enum types and converts them internally
4441
return ServerConfig(
45-
server=resolved_server,
42+
server=server, # type: ignore[arg-type]
4643
name=name,
4744
endpoint=endpoint,
4845
manufacturer=manufacturer,
4946
configuration_url=configuration_url,
50-
type=resolved_type,
47+
type=type, # type: ignore[arg-type]
5148
)
5249

5350

0 commit comments

Comments
 (0)