Skip to content

Commit 3ecba9c

Browse files
authored
Merge pull request #409 from andlaus/minor_python3.10_fixes
Minor python3.10 fixes
2 parents fb32ba5 + 72f4d54 commit 3ecba9c

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

odxtools/multiplexer.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
orig_origin = encode_state.origin_byte_position
119119
encode_state.origin_byte_position = encode_state.cursor_byte_position
120120

121-
if isinstance(physical_value, list | tuple) and len(physical_value) == 2:
121+
if isinstance(physical_value, (list, tuple)) and len(physical_value) == 2:
122122
case_spec, case_value = physical_value
123123
elif isinstance(physical_value, dict) and len(physical_value) == 1:
124124
case_spec, case_value = next(iter(physical_value.items()))

odxtools/standardlengthtype.py

+2-9
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,7 @@ def __get_used_mask(self, internal_value: AtomicOdxType) -> bytes | None:
7272
if self.is_condensed:
7373
# if a condensed bitmask is specified, the number of bits
7474
# set to one in the bit mask are used in the PDU
75-
76-
# TODO: this is pretty slow. replace it by
77-
# `self.bit_mask.bit_count()` once we require python >=
78-
# 3.10.
79-
bit_sz = bin(self.bit_mask).count("1")
75+
bit_sz = self.bit_mask.bit_count()
8076
used_mask = (1 << bit_sz) - 1
8177

8278
return used_mask.to_bytes((bit_sz + 7) // 8, endianness)
@@ -171,10 +167,7 @@ def __unapply_mask(self, raw_value: AtomicOdxType) -> AtomicOdxType:
171167

172168
def get_static_bit_length(self) -> int | None:
173169
if self.bit_mask is not None and self.is_condensed:
174-
# TODO: this is pretty slow. replace it by
175-
# `self.bit_mask.bit_count()` once we require python >=
176-
# 3.10.
177-
return bin(self.bit_mask).count("1")
170+
return self.bit_mask.bit_count()
178171

179172
return self.bit_length
180173

0 commit comments

Comments
 (0)