Skip to content

Commit b56f13d

Browse files
committed
fix it for python 3.8
Signed-off-by: Andreas Lauser <andreas.lauser@mercedes-benz.com>
1 parent 73d7d32 commit b56f13d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

odxtools/standardlengthtype.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ def __get_used_mask(self, internal_value: AtomicOdxType) -> Optional[bytes]:
8181
if self.is_condensed:
8282
# if a condensed bitmask is specified, the number of bits
8383
# set to one in the bit mask are used in the PDU
84-
bit_sz = self.bit_mask.bit_count()
84+
85+
# TODO: this is pretty slow. replace it by
86+
# `self.bit_mask.bit_count()` once we require python >=
87+
# 3.10.
88+
bit_sz = bin(self.bit_mask).count("1")
8589
used_mask = (1 << bit_sz) - 1
8690

8791
return used_mask.to_bytes((bit_sz + 7) // 8, endianness)
@@ -176,7 +180,10 @@ def __unapply_mask(self, raw_value: AtomicOdxType) -> AtomicOdxType:
176180

177181
def get_static_bit_length(self) -> Optional[int]:
178182
if self.bit_mask is not None and self.is_condensed:
179-
return self.bit_mask.bit_count()
183+
# TODO: this is pretty slow. replace it by
184+
# `self.bit_mask.bit_count()` once we require python >=
185+
# 3.10.
186+
return bin(self.bit_mask).count("1")
180187

181188
return self.bit_length
182189

0 commit comments

Comments
 (0)