Skip to content

Commit 995c766

Browse files
Break circular dependency between Current and Fuse
The circular dependency between `Current` and `Fuse` is causing issues when `component` is imported. Signed-off-by: Daniel Zullo <[email protected]>
1 parent 4932941 commit 995c766

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/frequenz/sdk/microgrid/component/_component.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22
# Copyright © 2022 Frequenz Energy-as-a-Service GmbH
33

44
"""Defines the components that can be used in a microgrid."""
5+
from __future__ import annotations
56

67
from dataclasses import dataclass
78
from enum import Enum
9+
from typing import TYPE_CHECKING
810

911
import frequenz.api.common.components_pb2 as components_pb
1012
import frequenz.api.microgrid.grid_pb2 as grid_pb
1113
import frequenz.api.microgrid.inverter_pb2 as inverter_pb
1214

13-
from ...timeseries import Current, Fuse
15+
if TYPE_CHECKING:
16+
# Break circular import by enclosing these type hints in a `TYPE_CHECKING` block.
17+
from ...timeseries import Fuse
1418

1519

1620
class ComponentType(Enum):
@@ -139,6 +143,8 @@ def _component_metadata_from_protobuf(
139143
component_category: components_pb.ComponentCategory.ValueType,
140144
component_metadata: grid_pb.Metadata,
141145
) -> GridMetadata | None:
146+
from ...timeseries import Current, Fuse # pylint: disable=import-outside-toplevel
147+
142148
if component_category == components_pb.ComponentCategory.COMPONENT_CATEGORY_GRID:
143149
max_current = Current.from_amperes(component_metadata.rated_fuse_current)
144150
fuse = Fuse(max_current)

0 commit comments

Comments
 (0)