From 0e0bec91b617fef785db49685fee412f1698e25b Mon Sep 17 00:00:00 2001 From: Max Chesterfield Date: Fri, 30 May 2025 19:38:58 +1000 Subject: [PATCH 1/3] building a list to pass it to a generator kinda defeats the purpose? Signed-off-by: Max Chesterfield --- .../model/cim/iec61970/base/core/equipment.py | 13 +++++-------- .../base/wires/per_length_phase_impedance.py | 2 +- src/zepben/evolve/util.py | 4 +--- 3 files changed, 7 insertions(+), 12 deletions(-) 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..6d11045ff 100644 --- a/src/zepben/evolve/model/cim/iec61970/base/core/equipment.py +++ b/src/zepben/evolve/model/cim/iec61970/base/core/equipment.py @@ -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..d1e50fc97 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 @@ -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..14c206361 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 if collection is not None else {} def is_none_or_empty(sized: Optional[Sized]) -> bool: From 7cf7388aa4ebcc58d66877b9feb262c2f11b55cd Mon Sep 17 00:00:00 2001 From: Max Chesterfield Date: Tue, 3 Jun 2025 15:49:23 +1000 Subject: [PATCH 2/3] simple is better Signed-off-by: Max Chesterfield --- src/zepben/evolve/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zepben/evolve/util.py b/src/zepben/evolve/util.py index 14c206361..a9109ba81 100644 --- a/src/zepben/evolve/util.py +++ b/src/zepben/evolve/util.py @@ -111,7 +111,7 @@ def nlen(sized: Optional[Sized]) -> int: def ngen(collection: Optional[Iterable[T]]) -> Generator[T, None, None]: - yield from collection if collection is not None else {} + yield from collection or {} def is_none_or_empty(sized: Optional[Sized]) -> bool: From 01424066f4904d0a97d97f7da818c0cef5c04df9 Mon Sep 17 00:00:00 2001 From: Max Chesterfield Date: Tue, 3 Jun 2025 18:38:36 +1000 Subject: [PATCH 3/3] update license date Signed-off-by: Max Chesterfield --- src/zepben/evolve/model/cim/iec61970/base/core/equipment.py | 2 +- .../model/cim/iec61970/base/wires/per_length_phase_impedance.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 6d11045ff..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/. 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 d1e50fc97..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/.