Skip to content

Commit fb32ba5

Browse files
authored
Merge pull request #408 from andlaus/disable_UP038
ruff: disable deprecated UP038 check
2 parents a00ed19 + 7b01f9c commit fb32ba5

21 files changed

+40
-39
lines changed

odxtools/cli/_print_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def extract_parameter_tabulation_data(parameters: list[Parameter]) -> RichTable:
214214
value_column.append(str(param.coded_values))
215215
value_type_column.append('coded values')
216216
dop_column.append("")
217-
elif isinstance(param, PhysicalConstantParameter | SystemParameter | ValueParameter):
217+
elif isinstance(param, (PhysicalConstantParameter, SystemParameter, ValueParameter)):
218218
# this is a hack to make this routine work for parameters
219219
# which reference DOPs of a type that a is not yet
220220
# internalized. (all parameter objects of the tested types

odxtools/cli/browse.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ def browse(odxdb: Database) -> None:
370370

371371
codec = answer.get("message_type")
372372
if codec is not None:
373-
assert isinstance(codec, Request | Response)
373+
assert isinstance(codec, (Request, Response))
374374
table = extract_parameter_tabulation_data(codec.parameters)
375375
print(table)
376376

odxtools/cli/list.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def print_summary(odxdb: Database,
6161

6262
all_services: list[DiagComm] = sorted(dl.services, key=lambda x: x.short_name)
6363

64-
if isinstance(dl, BaseVariant | EcuVariant):
64+
if isinstance(dl, (BaseVariant, EcuVariant)):
6565
for proto in dl.protocols:
6666
if (can_rx_id := dl.get_can_receive_id(proto.short_name)) is not None:
6767
rich.print(

odxtools/comparaminstance.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def get_subvalue(self, subparam_name: str) -> str | None:
133133
return None
134134

135135
result = value_list[idx]
136-
if result is None and isinstance(subparam, Comparam | ComplexComparam):
136+
if result is None and isinstance(subparam, (Comparam, ComplexComparam)):
137137
result = subparam.physical_default_value
138138
if not isinstance(result, str):
139139
odxraise()

odxtools/compositecodec.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def composite_codec_get_coded_const_prefix(codec: CompositeCodec,
8484

8585
for param in codec.parameters:
8686
if (isinstance(param, MatchingRequestParameter) and param.request_byte_position < len(request_prefix)) or \
87-
isinstance(param, CodedConstParameter|PhysicalConstantParameter) :
87+
isinstance(param, (CodedConstParameter, PhysicalConstantParameter)):
8888
param.encode_into_pdu(physical_value=None, encode_state=encode_state)
8989
else:
9090
break
@@ -132,7 +132,7 @@ def composite_codec_encode_into_pdu(codec: CompositeCodec, physical_value: Param
132132
# the ODX is located last in the PDU...
133133
encode_state.is_end_of_pdu = orig_is_end_of_pdu
134134

135-
if isinstance(param, LengthKeyParameter | TableKeyParameter):
135+
if isinstance(param, (LengthKeyParameter, TableKeyParameter)):
136136
# At this point, we encode a placeholder value for length-
137137
# and table keys, since these can be specified
138138
# implicitly (i.e., by means of parameters that use
@@ -159,7 +159,7 @@ def composite_codec_encode_into_pdu(codec: CompositeCodec, physical_value: Param
159159
# because we allow these to be defined implicitly (i.e. they
160160
# are defined by their respective users)
161161
for param in codec.parameters:
162-
if not isinstance(param, LengthKeyParameter | TableKeyParameter):
162+
if not isinstance(param, (LengthKeyParameter, TableKeyParameter)):
163163
# the current parameter is neither a length- nor a table key
164164
continue
165165

odxtools/compumethods/linearsegment.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def from_compu_scale(scale: CompuScale, *, internal_type: DataType,
5454
inverse_value: int | float = 0
5555
if scale.compu_inverse_value is not None:
5656
x = odxrequire(scale.compu_inverse_value).value
57-
if not isinstance(x, int | float):
57+
if not isinstance(x, (int, float)):
5858
odxraise(f"Non-numeric COMPU-INVERSE-VALUE specified ({x!r})")
5959
inverse_value = x
6060

@@ -75,7 +75,7 @@ def __post_init__(self) -> None:
7575
self.__compute_physical_limits()
7676

7777
def convert_internal_to_physical(self, internal_value: AtomicOdxType) -> float | int:
78-
if not isinstance(internal_value, int | float):
78+
if not isinstance(internal_value, (int, float)):
7979
odxraise(f"Internal values of linear compumethods must "
8080
f"either be int or float (is: {type(internal_value).__name__})")
8181

@@ -90,7 +90,7 @@ def convert_internal_to_physical(self, internal_value: AtomicOdxType) -> float |
9090
return result
9191

9292
def convert_physical_to_internal(self, physical_value: AtomicOdxType) -> float | int:
93-
if not isinstance(physical_value, int | float):
93+
if not isinstance(physical_value, (int, float)):
9494
odxraise(f"Physical values of linear compumethods must "
9595
f"either be int or float (is: {type(physical_value).__name__})")
9696

@@ -151,7 +151,7 @@ def physical_applies(self, physical_value: AtomicOdxType) -> bool:
151151
# Do type checks
152152
expected_type = self.physical_type.python_type
153153
if issubclass(expected_type, float):
154-
if not isinstance(physical_value, int | float):
154+
if not isinstance(physical_value, (int, float)):
155155
return False
156156
else:
157157
if not isinstance(physical_value, expected_type):
@@ -172,7 +172,7 @@ def internal_applies(self, internal_value: AtomicOdxType) -> bool:
172172
# Do type checks
173173
expected_type = self.internal_type.python_type
174174
if issubclass(expected_type, float):
175-
if not isinstance(internal_value, int | float):
175+
if not isinstance(internal_value, (int, float)):
176176
return False
177177
else:
178178
if not isinstance(internal_value, expected_type):

odxtools/compumethods/ratfuncsegment.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def from_compu_scale(scale: CompuScale, value_type: DataType) -> "RatFuncSegment
3939
value_type=scale.range_type)
4040

4141
def convert(self, value: AtomicOdxType) -> float | int:
42-
if not isinstance(value, int | float):
42+
if not isinstance(value, (int, float)):
4343
odxraise(f"Internal values of linear compumethods must "
4444
f"either be int or float (is: {type(value).__name__})")
4545

@@ -69,7 +69,7 @@ def applies(self, value: AtomicOdxType) -> bool:
6969
# Do type checks
7070
expected_type = self.value_type.python_type
7171
if issubclass(expected_type, float):
72-
if not isinstance(value, int | float):
72+
if not isinstance(value, (int, float)):
7373
return False
7474
else:
7575
if not isinstance(value, expected_type):

odxtools/compumethods/scalelinearcompumethod.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def __post_init__(self) -> None:
100100
self._is_invertible = False
101101
break
102102

103-
if not isinstance(x, int | float):
103+
if not isinstance(x, (int, float)):
104104
odxraise("Linear segments must use int or float for all quantities")
105105

106106
# the respective function value at the interval's

odxtools/compumethods/tabintpcompumethod.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ def __post_init__(self) -> None:
7979
internal_point = odxrequire(scale.lower_limit).value
8080
physical_point = odxrequire(scale.compu_const).value
8181

82-
if not isinstance(internal_point, float | int):
82+
if not isinstance(internal_point, (float, int)):
8383
odxraise("The type of values of tab-intp compumethods must "
8484
"either int or float")
85-
if not isinstance(physical_point, float | int):
85+
if not isinstance(physical_point, (float, int)):
8686
odxraise("The type of values of tab-intp compumethods must "
8787
"either int or float")
8888

@@ -140,13 +140,13 @@ def __piecewise_linear_interpolate(self, x: int | float, range_samples: list[int
140140
return None
141141

142142
def convert_physical_to_internal(self, physical_value: AtomicOdxType) -> AtomicOdxType:
143-
if not isinstance(physical_value, int | float):
143+
if not isinstance(physical_value, (int, float)):
144144
odxraise("The type of values of tab-intp compumethods must "
145145
"either int or float", EncodeError)
146146
return None
147147

148148
odxassert(
149-
isinstance(physical_value, int | float),
149+
isinstance(physical_value, (int, float)),
150150
"Only integers and floats can be piecewise linearly interpolated", EncodeError)
151151
result = self.__piecewise_linear_interpolate(physical_value, self._physical_points,
152152
self._internal_points)
@@ -161,14 +161,14 @@ def convert_physical_to_internal(self, physical_value: AtomicOdxType) -> AtomicO
161161
return res
162162

163163
def convert_internal_to_physical(self, internal_value: AtomicOdxType) -> AtomicOdxType:
164-
if not isinstance(internal_value, int | float):
164+
if not isinstance(internal_value, (int, float)):
165165
odxraise(
166166
"The internal type of values of tab-intp compumethods must "
167167
"either int or float", EncodeError)
168168
return None
169169

170170
odxassert(
171-
isinstance(internal_value, int | float),
171+
isinstance(internal_value, (int, float)),
172172
"Only integers and floats can be piecewise linearly interpolated", DecodeError)
173173

174174
result = self.__piecewise_linear_interpolate(internal_value, self._internal_points,
@@ -185,14 +185,14 @@ def convert_internal_to_physical(self, internal_value: AtomicOdxType) -> AtomicO
185185
return res
186186

187187
def is_valid_physical_value(self, physical_value: AtomicOdxType) -> bool:
188-
if not isinstance(physical_value, int | float):
188+
if not isinstance(physical_value, (int, float)):
189189
return False
190190

191191
return min(self.physical_points) <= physical_value and physical_value <= max(
192192
self.physical_points)
193193

194194
def is_valid_internal_value(self, internal_value: AtomicOdxType) -> bool:
195-
if not isinstance(internal_value, int | float):
195+
if not isinstance(internal_value, (int, float)):
196196
return False
197197

198198
return min(self.internal_points) <= internal_value and internal_value <= max(

odxtools/dataobjectproperty.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def encode_into_pdu(self, physical_value: ParameterValue, encode_state: EncodeSt
118118
f"The value {repr(physical_value)} of type {type(physical_value).__name__}"
119119
f" is not a valid.")
120120

121-
if not isinstance(physical_value, int | float | str | BytesTypes):
121+
if not isinstance(physical_value, (int, float, str, BytesTypes)):
122122
odxraise(f"Invalid type '{type(physical_value).__name__}' for physical value. "
123123
f"(Expect atomic type!)")
124124
internal_value = self.compu_method.convert_physical_to_internal(physical_value)

odxtools/environmentdatadescription.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def _get_numerical_dtc_from_parameter(self, param: Parameter,
207207
param_value: ParameterValue | None) -> int:
208208
if isinstance(param, ParameterWithDOP):
209209
dop = param.dop
210-
if not isinstance(dop, DataObjectProperty | DtcDop):
210+
if not isinstance(dop, (DataObjectProperty, DtcDop)):
211211
odxraise(f"The DOP of the parameter referenced by environment data descriptions "
212212
f"must use either be DataObjectProperty or a DtcDop (encountered "
213213
f"{type(param).__name__} for parameter '{param.short_name}' "

odxtools/leadinglengthinfotype.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __post_init__(self) -> None:
5252
@override
5353
def encode_into_pdu(self, internal_value: AtomicOdxType, encode_state: EncodeState) -> None:
5454

55-
if not isinstance(internal_value, str | bytes):
55+
if not isinstance(internal_value, (str, bytes)):
5656
odxraise(
5757
f"LEADING-LENGTH-INFO types can only be used for strings and byte fields, "
5858
f"not {type(internal_value).__name__}", EncodeError)

odxtools/minmaxlengthtype.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def __termination_sequence(self) -> bytes:
7777
@override
7878
def encode_into_pdu(self, internal_value: AtomicOdxType, encode_state: EncodeState) -> None:
7979

80-
if not isinstance(internal_value, str | BytesTypes):
80+
if not isinstance(internal_value, (str, BytesTypes)):
8181
odxraise("MinMaxLengthType is currently only implemented for strings and byte arrays",
8282
EncodeError)
8383

odxtools/nameditemlist.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def __getitem__(self, key: slice) -> list[T]:
142142
...
143143

144144
def __getitem__(self, key: SupportsIndex | str | slice) -> T | list[T]:
145-
if isinstance(key, SupportsIndex | slice):
145+
if isinstance(key, (SupportsIndex, slice)):
146146
return super().__getitem__(key)
147147
else:
148148
return self._item_dict[key]

odxtools/odxtypes.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ def compare_odx_values(a: AtomicOdxType, b: AtomicOdxType) -> int:
109109
# specification. (cf section 7.3.6.5)
110110

111111
# numeric values are compared numerically (duh!)
112-
if isinstance(a, int | float):
113-
if not isinstance(b, int | float):
112+
if isinstance(a, (int, float)):
113+
if not isinstance(b, (int, float)):
114114
odxraise()
115115

116116
tmp = a - b
@@ -239,7 +239,7 @@ def isinstance(self, value: Any) -> bool:
239239
expected_type = self.python_type
240240
if isinstance(value, expected_type):
241241
return True
242-
elif expected_type is float and isinstance(value, int | float):
242+
elif expected_type is float and isinstance(value, (int, float)):
243243
return True
244244
elif self == DataType.A_BYTEFIELD and isinstance(value, BytesTypes):
245245
return True

odxtools/parameters/parameterwithdop.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def get_static_bit_length(self) -> int | None:
7878

7979
@property
8080
def physical_type(self) -> PhysicalType | None:
81-
if isinstance(self.dop, DataObjectProperty | DtcDop):
81+
if isinstance(self.dop, (DataObjectProperty, DtcDop)):
8282
return self.dop.physical_type
8383
else:
8484
return None

odxtools/parameters/tablestructparameter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def _resolve_snrefs(self, context: SnRefContext) -> None:
8989
def _encode_positioned_into_pdu(self, physical_value: ParameterValue | None,
9090
encode_state: EncodeState) -> None:
9191

92-
if not isinstance(physical_value, tuple|list) or \
92+
if not isinstance(physical_value, (tuple, list)) or \
9393
len(physical_value) != 2 or \
9494
not isinstance(physical_value[0], str):
9595
odxraise(

odxtools/statemachine.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def execute(self, service: "DiagService", **service_params: Any
160160

161161
if raw_resp is None:
162162
raise RuntimeError("The calling code must send back a reply")
163-
elif isinstance(raw_resp, bytes | bytearray):
163+
elif isinstance(raw_resp, (bytes, bytearray)):
164164
for decoded_resp_msg in self.diag_layer.decode_response(raw_resp, raw_req):
165165
for stransref in service.state_transition_refs:
166166
# we only execute the first applicable state

odxtools/statetransitionref.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ def _check_applies(ref: Union["StateTransitionRef",
108108
return False
109109
elif not isinstance(
110110
param,
111-
CodedConstParameter | PhysicalConstantParameter | TableKeyParameter | ValueParameter):
111+
(CodedConstParameter, PhysicalConstantParameter, TableKeyParameter, ValueParameter)):
112112
# see checker rule 194 in section B.2 of the spec
113113
odxraise(f"Parameter referenced by state transition ref is of "
114114
f"invalid type {type(param).__name__}")
115115
return False
116-
elif isinstance(param, CodedConstParameter | PhysicalConstantParameter
117-
| TableKeyParameter) and ref.value is not None:
116+
elif isinstance(param, (CodedConstParameter, PhysicalConstantParameter,
117+
TableKeyParameter)) and ref.value is not None:
118118
# see checker rule 193 in section B.2 of the spec. Why can
119119
# no values for constant parameters be specified? (This
120120
# seems to be rather inconvenient...)

odxtools/tablerow.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def _resolve_odxlinks(self, odxlinks: OdxLinkDatabase) -> None:
199199

200200
if self.dop_ref is not None:
201201
self._dop = odxlinks.resolve(self.dop_ref)
202-
if not isinstance(self._dop, DataObjectProperty | DtcDop):
202+
if not isinstance(self._dop, (DataObjectProperty, DtcDop)):
203203
odxraise("The DOP-REF of TABLE-ROWs must reference a simple DOP!")
204204
if self.structure_ref is not None:
205205
self._structure = odxlinks.resolve(self.structure_ref, Structure)
@@ -243,7 +243,7 @@ def _resolve_snrefs(self, context: SnRefContext) -> None:
243243
self._structure = resolve_snref(self.structure_snref, ddd_spec.structures, Structure)
244244
if self.dop_snref is not None:
245245
self._dop = resolve_snref(self.dop_snref, ddd_spec.data_object_props)
246-
if not isinstance(self._dop, DataObjectProperty | DtcDop):
246+
if not isinstance(self._dop, (DataObjectProperty, DtcDop)):
247247
odxraise("The DOP-SNREF of TABLE-ROWs must reference a simple DOP!")
248248

249249
if self.audience is not None:

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ lint.select = [
102102
lint.ignore = [
103103
"E501", # line too long
104104
"F541", # f-string-missing-placeholders
105+
"UP038", # non-pep604-isinstance (deprecated)
105106
]
106107

107108
exclude = [

0 commit comments

Comments
 (0)