diff --git a/src/zepben/evolve/model/cim/iec61970/base/core/equipment.py b/src/zepben/evolve/model/cim/iec61970/base/core/equipment.py index 6e3e436b8..dcb99d570 100644 --- a/src/zepben/evolve/model/cim/iec61970/base/core/equipment.py +++ b/src/zepben/evolve/model/cim/iec61970/base/core/equipment.py @@ -1,4 +1,4 @@ -# Copyright 2024 Zeppelin Bend Pty Ltd +# Copyright 2025 Zeppelin Bend Pty Ltd # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at https://mozilla.org/MPL/2.0/. @@ -132,19 +132,19 @@ def num_substations(self) -> int: """ Returns The number of `zepben.evolve.cim.iec61970.base.core.substation.Substation`s associated with this `Equipment` """ - return len(_of_type(self._equipment_containers, Substation)) + return len(list(_of_type(self._equipment_containers, Substation))) def num_sites(self) -> int: """ Returns The number of `Site`s associated with this `Equipment` """ - return len(_of_type(self._equipment_containers, Site)) + return len(list(_of_type(self._equipment_containers, Site))) def num_normal_feeders(self) -> int: """ Returns The number of normal `Feeder`s associated with this `Equipment` """ - return len(_of_type(self._equipment_containers, Feeder)) + return len(list(_of_type(self._equipment_containers, Feeder))) def num_usage_points(self) -> int: """ @@ -358,9 +358,6 @@ def clear_operational_restrictions(self) -> Equipment: return self -def _of_type(containers: Optional[List[EquipmentContainer]], ectype: Type[TEquipmentContainer]) -> List[TEquipmentContainer]: - if containers: - return [ec for ec in containers if isinstance(ec, ectype)] - else: - return [] +def _of_type(containers: Optional[List[EquipmentContainer]], ectype: Type[TEquipmentContainer]) -> Generator[TEquipmentContainer, None, None]: + yield from (ec for ec in containers if isinstance(ec, ectype)) if containers is not None else {} diff --git a/src/zepben/evolve/model/cim/iec61970/base/wires/per_length_phase_impedance.py b/src/zepben/evolve/model/cim/iec61970/base/wires/per_length_phase_impedance.py index 20fc308a5..f9f4460f9 100644 --- a/src/zepben/evolve/model/cim/iec61970/base/wires/per_length_phase_impedance.py +++ b/src/zepben/evolve/model/cim/iec61970/base/wires/per_length_phase_impedance.py @@ -1,4 +1,4 @@ -# Copyright 2024 Zeppelin Bend Pty Ltd +# Copyright 2025 Zeppelin Bend Pty Ltd # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at https://mozilla.org/MPL/2.0/. @@ -41,7 +41,7 @@ def diagonal(self) -> Generator[PhaseImpedanceData, None, None]: """ Get only the diagonal elements of the matrix, i.e toPhase == fromPhase. """ - return ngen([pid for pid in self._data if pid.from_phase == pid.to_phase]) + return ngen(pid for pid in self._data if pid.from_phase == pid.to_phase) def num_data(self): """Return the number of :class:`PhaseImpedanceData` associated with this :class:`PerLengthPhaseImpedance`.""" diff --git a/src/zepben/evolve/util.py b/src/zepben/evolve/util.py index 0d958d62a..a9109ba81 100644 --- a/src/zepben/evolve/util.py +++ b/src/zepben/evolve/util.py @@ -111,9 +111,7 @@ def nlen(sized: Optional[Sized]) -> int: def ngen(collection: Optional[Iterable[T]]) -> Generator[T, None, None]: - if collection: - for item in collection: - yield item + yield from collection or {} def is_none_or_empty(sized: Optional[Sized]) -> bool: