3
3
from typing import List , Literal , Optional
4
4
from xml .etree import ElementTree
5
5
6
- from typing_extensions import SupportsBytes , override
6
+ from typing_extensions import override
7
7
8
8
from .decodestate import DecodeState
9
9
from .diagcodedtype import DctType , DiagCodedType
10
10
from .encodestate import EncodeState
11
11
from .exceptions import odxassert , odxraise , odxrequire
12
12
from .odxlink import OdxDocFragment
13
13
from .odxtypes import AtomicOdxType , DataType , odxstr_to_bool
14
- from .utils import dataclass_fields_asdict
14
+ from .utils import BytesTypes , dataclass_fields_asdict
15
15
16
16
17
17
@dataclass
@@ -91,7 +91,7 @@ def __get_used_mask(self, internal_value: AtomicOdxType) -> Optional[bytes]:
91
91
return used_mask .to_bytes ((bit_sz + 7 ) // 8 , endianness )
92
92
93
93
sz : int
94
- if isinstance (internal_value , ( bytearray , SupportsBytes ) ):
94
+ if isinstance (internal_value , BytesTypes ):
95
95
sz = len (bytes (internal_value ))
96
96
else :
97
97
sz = (odxrequire (self .get_static_bit_length ()) + 7 ) // 8
@@ -107,7 +107,7 @@ def __apply_mask(self, internal_value: AtomicOdxType) -> AtomicOdxType:
107
107
108
108
if self .is_condensed :
109
109
int_value : int
110
- if isinstance (internal_value , ( bytearray , SupportsBytes ) ):
110
+ if isinstance (internal_value , BytesTypes ):
111
111
int_value = int .from_bytes (internal_value , 'big' )
112
112
elif isinstance (internal_value , int ):
113
113
int_value = internal_value
@@ -126,14 +126,14 @@ def __apply_mask(self, internal_value: AtomicOdxType) -> AtomicOdxType:
126
126
127
127
mask_bit += 1
128
128
129
- if isinstance (internal_value , ( bytearray , SupportsBytes ) ):
129
+ if isinstance (internal_value , BytesTypes ):
130
130
return result .to_bytes (len (internal_value ), 'big' )
131
131
132
132
return result
133
133
134
134
if isinstance (internal_value , int ):
135
135
return internal_value & self .bit_mask
136
- if isinstance (internal_value , ( bytearray , SupportsBytes ) ):
136
+ if isinstance (internal_value , BytesTypes ):
137
137
int_value = int .from_bytes (internal_value , 'big' )
138
138
int_value &= self .bit_mask
139
139
return int_value .to_bytes (len (bytes (internal_value )), 'big' )
@@ -146,7 +146,7 @@ def __unapply_mask(self, raw_value: AtomicOdxType) -> AtomicOdxType:
146
146
return raw_value
147
147
if self .is_condensed :
148
148
int_value : int
149
- if isinstance (raw_value , ( bytearray , SupportsBytes ) ):
149
+ if isinstance (raw_value , BytesTypes ):
150
150
int_value = int .from_bytes (raw_value , 'big' )
151
151
elif isinstance (raw_value , int ):
152
152
int_value = raw_value
@@ -164,16 +164,16 @@ def __unapply_mask(self, raw_value: AtomicOdxType) -> AtomicOdxType:
164
164
165
165
mask_bit += 1
166
166
167
- if isinstance (raw_value , ( bytearray , SupportsBytes ) ):
167
+ if isinstance (raw_value , BytesTypes ):
168
168
return result .to_bytes (len (raw_value ), 'big' )
169
169
170
170
return result
171
171
if isinstance (raw_value , int ):
172
172
return raw_value & self .bit_mask
173
- if isinstance (raw_value , ( bytearray , SupportsBytes ) ):
173
+ if isinstance (raw_value , BytesTypes ):
174
174
int_value = int .from_bytes (raw_value , 'big' )
175
175
int_value &= self .bit_mask
176
- return int_value
176
+ return int_value . to_bytes ( len ( raw_value ), 'big' )
177
177
178
178
odxraise (f'Can not apply a bit_mask on a value of type { type (raw_value )} ' )
179
179
return raw_value
0 commit comments