Skip to content

Commit e6794f6

Browse files
Update union type syntax to use | (UP038) (#399)
1 parent 8b21331 commit e6794f6

15 files changed

Lines changed: 40 additions & 41 deletions

File tree

src/openlifu/bf/apod_methods/maxangle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class MaxAngle(ApodizationMethod):
2323
"""Angle units"""
2424

2525
def __post_init__(self):
26-
if not isinstance(self.max_angle, (int, float)):
26+
if not isinstance(self.max_angle, int | float):
2727
raise TypeError(f"Max angle must be a number, got {type(self.max_angle).__name__}.")
2828
if self.max_angle < 0:
2929
raise ValueError(f"Max angle must be non-negative, got {self.max_angle}.")

src/openlifu/bf/apod_methods/piecewiselinear.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ class PiecewiseLinear(ApodizationMethod):
2626
"""Angle units"""
2727

2828
def __post_init__(self):
29-
if not isinstance(self.zero_angle, (int, float)):
29+
if not isinstance(self.zero_angle, int | float):
3030
raise TypeError(f"Zero angle must be a number, got {type(self.zero_angle).__name__}.")
3131
if self.zero_angle < 0:
3232
raise ValueError(f"Zero angle must be non-negative, got {self.zero_angle}.")
33-
if not isinstance(self.rolloff_angle, (int, float)):
33+
if not isinstance(self.rolloff_angle, int | float):
3434
raise TypeError(f"Rolloff angle must be a number, got {type(self.rolloff_angle).__name__}.")
3535
if self.rolloff_angle < 0:
3636
raise ValueError(f"Rolloff angle must be non-negative, got {self.rolloff_angle}.")

src/openlifu/bf/delay_methods/direct.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Direct(DelayMethod):
1919
"""Speed of sound in the medium (m/s)"""
2020

2121
def __post_init__(self):
22-
if not isinstance(self.c0, (int, float)):
22+
if not isinstance(self.c0, int | float):
2323
raise TypeError("Speed of sound must be a number")
2424
if self.c0 <= 0:
2525
raise ValueError("Speed of sound must be greater than 0")

src/openlifu/bf/focal_patterns/wheel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __post_init__(self):
3434
raise TypeError(f"Center must be a boolean, got {type(self.center).__name__}.")
3535
if not isinstance(self.num_spokes, int) or self.num_spokes < 1:
3636
raise ValueError(f"Number of spokes must be a positive integer, got {self.num_spokes}.")
37-
if not isinstance(self.spoke_radius, (int, float)) or self.spoke_radius <= 0:
37+
if not isinstance(self.spoke_radius, int | float) or self.spoke_radius <= 0:
3838
raise ValueError(f"Spoke radius must be a positive number, got {self.spoke_radius}.")
3939
super().__post_init__()
4040

src/openlifu/io/LIFUHVController.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def echo(self, echo_data=None) -> tuple[bytes, int]:
170170
raise ValueError("Console Device not connected")
171171

172172
# Check if echo_data is a byte array
173-
if echo_data is not None and not isinstance(echo_data, (bytes, bytearray)):
173+
if echo_data is not None and not isinstance(echo_data, bytes | bytearray):
174174
raise TypeError("echo_data must be a byte array")
175175

176176
r = self.uart.send_packet(

src/openlifu/io/LIFUTXDevice.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def echo(self, echo_data = None) -> tuple[bytes, int]:
298298
return None, None
299299

300300
# Check if echo_data is a byte array
301-
if echo_data is not None and not isinstance(echo_data, (bytes, bytearray)):
301+
if echo_data is not None and not isinstance(echo_data, bytes | bytearray):
302302
raise TypeError("echo_data must be a byte array")
303303

304304
r = self.uart.send_packet(id=None, packetType=OW_CONTROLLER, command=OW_CMD_ECHO, data=echo_data)

src/openlifu/io/LIFUUart.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ def send_packet(self, id=None, packetType=OW_ACK, command=OW_CMD_NOP, addr=0, re
445445
id = self.packet_count
446446

447447
if data:
448-
if not isinstance(data, (bytes, bytearray)):
448+
if not isinstance(data, bytes | bytearray):
449449
raise ValueError("Data must be bytes or bytearray")
450450
payload = data
451451
payload_length = len(payload)

src/openlifu/plan/param_constraint.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ def __post_init__(self):
3434
if self.error_value and (not isinstance(self.error_value, tuple) or len(self.error_value) != 2 or self.error_value[0] >= self.error_value[1]):
3535
raise ValueError("Error value must be a sorted tuple of two numbers")
3636
elif self.operator in ['<', '<=', '>', '>=']:
37-
if self.warning_value is not None and not isinstance(self.warning_value, (int, float)):
37+
if self.warning_value is not None and not isinstance(self.warning_value, int | float):
3838
raise ValueError("Warning value must be a single value")
39-
if self.error_value is not None and not isinstance(self.error_value, (int, float)):
39+
if self.error_value is not None and not isinstance(self.error_value, int | float):
4040
raise ValueError("Error value must be a single value")
4141

4242
@staticmethod

src/openlifu/plan/solution_analysis.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,18 +269,18 @@ def __post_init__(self):
269269
raise ValueError("Reference sound speed must be greater than 0")
270270
if self.ref_density <= 0:
271271
raise ValueError("Reference density must be greater than 0")
272-
if not isinstance(self.mainlobe_aspect_ratio, (tuple, list)) or len(self.mainlobe_aspect_ratio) != 3:
272+
if not isinstance(self.mainlobe_aspect_ratio, tuple | list) or len(self.mainlobe_aspect_ratio) != 3:
273273
raise TypeError("Mainlobe aspect ratio must be a tuple or list of three floats (lat, ele, ax)")
274274
self.mainlobe_aspect_ratio = tuple(self.mainlobe_aspect_ratio) # Ensure it's a tuple
275-
if not all(isinstance(x, (int, float)) for x in self.mainlobe_aspect_ratio):
275+
if not all(isinstance(x, int | float) for x in self.mainlobe_aspect_ratio):
276276
raise TypeError("Mainlobe aspect ratio must contain only numbers")
277-
if not isinstance(self.mainlobe_radius, (int, float)) or self.mainlobe_radius <= 0:
277+
if not isinstance(self.mainlobe_radius, int | float) or self.mainlobe_radius <= 0:
278278
raise ValueError("Mainlobe radius must be a positive number")
279-
if not isinstance(self.beamwidth_radius, (int, float)) or self.beamwidth_radius <= 0:
279+
if not isinstance(self.beamwidth_radius, int | float) or self.beamwidth_radius <= 0:
280280
raise ValueError("Beamwidth radius must be a positive number")
281-
if not isinstance(self.sidelobe_radius, (int, float)) or self.sidelobe_radius <= 0:
281+
if not isinstance(self.sidelobe_radius, int | float) or self.sidelobe_radius <= 0:
282282
raise ValueError("Sidelobe radius must be a positive number")
283-
if not isinstance(self.sidelobe_zmin, (int, float)) or self.sidelobe_zmin < 0:
283+
if not isinstance(self.sidelobe_zmin, int | float) or self.sidelobe_zmin < 0:
284284
raise ValueError("Sidelobe minimum z must be a non-negative number")
285285
if not isinstance(self.distance_units, str):
286286
raise TypeError("Distance units must be a string")

src/openlifu/plan/target_constraints.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ def __post_init__(self):
4545
raise TypeError("Dimension units must be a string")
4646
if getunittype(self.units) != 'distance':
4747
raise ValueError(f"Units must be a length unit, got {self.units}")
48-
if not isinstance(self.min, (int, float)):
48+
if not isinstance(self.min, int | float):
4949
raise TypeError("Minimum value must be a number")
50-
if not isinstance(self.max, (int, float)):
50+
if not isinstance(self.max, int | float):
5151
raise TypeError("Maximum value must be a number")
5252
if self.min > self.max:
5353
raise ValueError("Minimum value cannot be greater than maximum value")

0 commit comments

Comments
 (0)