Skip to content

Commit 2cd252b

Browse files
committed
Remove unnecessary unwrapping
Instead of accepting and passing `None` as default to signify a tuple with 3 `nan`s, we can just use a tuple with 3 `nan`s (tuples are immutable, and thus safe to use as function defaults). Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 8d3d4a5 commit 2cd252b

File tree

1 file changed

+12
-36
lines changed

1 file changed

+12
-36
lines changed

tests/utils/component_data_wrapper.py

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ def __init__( # pylint: disable=too-many-arguments
101101
component_id: int,
102102
timestamp: datetime,
103103
active_power: float = math.nan,
104-
current_per_phase: tuple[float, float, float] | None = None,
105-
voltage_per_phase: tuple[float, float, float] | None = None,
104+
current_per_phase: tuple[float, float, float] = (math.nan, math.nan, math.nan),
105+
voltage_per_phase: tuple[float, float, float] = (math.nan, math.nan, math.nan),
106106
active_power_inclusion_lower_bound: float = math.nan,
107107
active_power_exclusion_lower_bound: float = math.nan,
108108
active_power_inclusion_upper_bound: float = math.nan,
@@ -122,16 +122,8 @@ def __init__( # pylint: disable=too-many-arguments
122122
component_id=component_id,
123123
timestamp=timestamp,
124124
active_power=active_power,
125-
current_per_phase=(
126-
current_per_phase
127-
if current_per_phase
128-
else (math.nan, math.nan, math.nan)
129-
),
130-
voltage_per_phase=(
131-
voltage_per_phase
132-
if voltage_per_phase
133-
else (math.nan, math.nan, math.nan)
134-
),
125+
current_per_phase=current_per_phase,
126+
voltage_per_phase=voltage_per_phase,
135127
active_power_inclusion_lower_bound=active_power_inclusion_lower_bound,
136128
active_power_exclusion_lower_bound=active_power_exclusion_lower_bound,
137129
active_power_inclusion_upper_bound=active_power_inclusion_upper_bound,
@@ -165,8 +157,8 @@ def __init__( # pylint: disable=too-many-arguments
165157
component_id: int,
166158
timestamp: datetime,
167159
active_power: float = math.nan,
168-
current_per_phase: tuple[float, float, float] | None = None,
169-
voltage_per_phase: tuple[float, float, float] | None = None,
160+
current_per_phase: tuple[float, float, float] = (math.nan, math.nan, math.nan),
161+
voltage_per_phase: tuple[float, float, float] = (math.nan, math.nan, math.nan),
170162
frequency: float = 50.0,
171163
cable_state: EVChargerCableState = EVChargerCableState.UNSPECIFIED,
172164
component_state: EVChargerComponentState = EVChargerComponentState.UNSPECIFIED,
@@ -180,16 +172,8 @@ def __init__( # pylint: disable=too-many-arguments
180172
component_id=component_id,
181173
timestamp=timestamp,
182174
active_power=active_power,
183-
current_per_phase=(
184-
current_per_phase
185-
if current_per_phase
186-
else (math.nan, math.nan, math.nan)
187-
),
188-
voltage_per_phase=(
189-
voltage_per_phase
190-
if voltage_per_phase
191-
else (math.nan, math.nan, math.nan)
192-
),
175+
current_per_phase=current_per_phase,
176+
voltage_per_phase=voltage_per_phase,
193177
frequency=frequency,
194178
cable_state=cable_state,
195179
component_state=component_state,
@@ -219,8 +203,8 @@ def __init__( # pylint: disable=too-many-arguments
219203
component_id: int,
220204
timestamp: datetime,
221205
active_power: float = math.nan,
222-
current_per_phase: tuple[float, float, float] | None = None,
223-
voltage_per_phase: tuple[float, float, float] | None = None,
206+
current_per_phase: tuple[float, float, float] = (math.nan, math.nan, math.nan),
207+
voltage_per_phase: tuple[float, float, float] = (math.nan, math.nan, math.nan),
224208
frequency: float = math.nan,
225209
) -> None:
226210
"""Initialize the MeterDataWrapper.
@@ -232,16 +216,8 @@ def __init__( # pylint: disable=too-many-arguments
232216
component_id=component_id,
233217
timestamp=timestamp,
234218
active_power=active_power,
235-
current_per_phase=(
236-
current_per_phase
237-
if current_per_phase
238-
else (math.nan, math.nan, math.nan)
239-
),
240-
voltage_per_phase=(
241-
voltage_per_phase
242-
if voltage_per_phase
243-
else (math.nan, math.nan, math.nan)
244-
),
219+
current_per_phase=current_per_phase,
220+
voltage_per_phase=voltage_per_phase,
245221
frequency=frequency,
246222
)
247223

0 commit comments

Comments
 (0)