Skip to content

Commit 1cf8143

Browse files
Revert "Improve typing (#238)"
This reverts commit cc8d776.
1 parent cc8d776 commit 1cf8143

15 files changed

+127
-111
lines changed

tests/software_tests/can/test_extended_addressing_information.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_validate_packet_ai__valid(self, addressing_type, can_id, target_address
7171
can_id=can_id,
7272
target_address=target_address) == {
7373
AbstractCanAddressingInformation.ADDRESSING_FORMAT_NAME: CanAddressingFormat.EXTENDED_ADDRESSING,
74-
AbstractCanAddressingInformation.ADDRESSING_TYPE_NAME: self.mock_validate_addressing_type.return_value,
74+
AbstractCanAddressingInformation.ADDRESSING_TYPE_NAME: addressing_type,
7575
AbstractCanAddressingInformation.CAN_ID_NAME: can_id,
7676
AbstractCanAddressingInformation.TARGET_ADDRESS_NAME: target_address,
7777
AbstractCanAddressingInformation.SOURCE_ADDRESS_NAME: None,

tests/software_tests/can/test_normal_addressing_information.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def test_validate_packet_ai__valid(self, addressing_type, can_id):
6666
assert Normal11BitCanAddressingInformation.validate_packet_ai(addressing_type=addressing_type,
6767
can_id=can_id) == {
6868
AbstractCanAddressingInformation.ADDRESSING_FORMAT_NAME: CanAddressingFormat.NORMAL_11BIT_ADDRESSING,
69-
AbstractCanAddressingInformation.ADDRESSING_TYPE_NAME: self.mock_validate_addressing_type.return_value,
69+
AbstractCanAddressingInformation.ADDRESSING_TYPE_NAME: addressing_type,
7070
AbstractCanAddressingInformation.CAN_ID_NAME: can_id,
7171
AbstractCanAddressingInformation.TARGET_ADDRESS_NAME: None,
7272
AbstractCanAddressingInformation.SOURCE_ADDRESS_NAME: None,
@@ -159,7 +159,7 @@ def test_validate_packet_ai__valid_without_can_id(self, addressing_type, target_
159159
target_address=target_address,
160160
source_address=source_address) == {
161161
AbstractCanAddressingInformation.ADDRESSING_FORMAT_NAME: CanAddressingFormat.NORMAL_FIXED_ADDRESSING,
162-
AbstractCanAddressingInformation.ADDRESSING_TYPE_NAME: self.mock_validate_addressing_type.return_value,
162+
AbstractCanAddressingInformation.ADDRESSING_TYPE_NAME: addressing_type,
163163
AbstractCanAddressingInformation.CAN_ID_NAME: self.mock_can_id_handler_class.encode_normal_fixed_addressed_can_id.return_value,
164164
AbstractCanAddressingInformation.TARGET_ADDRESS_NAME: target_address,
165165
AbstractCanAddressingInformation.SOURCE_ADDRESS_NAME: source_address,
@@ -170,7 +170,7 @@ def test_validate_packet_ai__valid_without_can_id(self, addressing_type, target_
170170
self.mock_can_id_handler_class.validate_can_id.assert_not_called()
171171
self.mock_can_id_handler_class.decode_normal_fixed_addressed_can_id.assert_not_called()
172172
self.mock_can_id_handler_class.encode_normal_fixed_addressed_can_id.assert_called_once_with(
173-
addressing_type=self.mock_validate_addressing_type.return_value,
173+
addressing_type=addressing_type,
174174
target_address=target_address,
175175
source_address=source_address
176176
)
@@ -187,7 +187,7 @@ def test_validate_packet_ai__valid_with_can_id(self, addressing_type, can_id, ta
187187
decoded_target_address = target_address or "ta"
188188
decoded_source_address = source_address or "sa"
189189
self.mock_can_id_handler_class.decode_normal_fixed_addressed_can_id.return_value = {
190-
self.mock_can_id_handler_class.ADDRESSING_TYPE_NAME: self.mock_validate_addressing_type.return_value,
190+
self.mock_can_id_handler_class.ADDRESSING_TYPE_NAME: addressing_type,
191191
self.mock_can_id_handler_class.TARGET_ADDRESS_NAME: decoded_target_address,
192192
self.mock_can_id_handler_class.SOURCE_ADDRESS_NAME: decoded_source_address,
193193
}
@@ -196,7 +196,7 @@ def test_validate_packet_ai__valid_with_can_id(self, addressing_type, can_id, ta
196196
target_address=target_address,
197197
source_address=source_address) == {
198198
AbstractCanAddressingInformation.ADDRESSING_FORMAT_NAME: CanAddressingFormat.NORMAL_FIXED_ADDRESSING,
199-
AbstractCanAddressingInformation.ADDRESSING_TYPE_NAME: self.mock_validate_addressing_type.return_value,
199+
AbstractCanAddressingInformation.ADDRESSING_TYPE_NAME: addressing_type,
200200
AbstractCanAddressingInformation.CAN_ID_NAME: can_id,
201201
AbstractCanAddressingInformation.TARGET_ADDRESS_NAME: decoded_target_address,
202202
AbstractCanAddressingInformation.SOURCE_ADDRESS_NAME: decoded_source_address,

tests/software_tests/packet/test_can_packet_type.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ def test_inheritance__abstract_packet_type(self):
2424

2525
@pytest.mark.parametrize("value", [2, 3, CanPacketType.CONSECUTIVE_FRAME, CanPacketType.FLOW_CONTROL])
2626
def test_is_initial_packet_type__false(self, value):
27-
self.mock_validate_member.side_effect = lambda arg: arg
2827
assert CanPacketType.is_initial_packet_type(value) is False
2928
self.mock_validate_member.assert_called_once_with(value)
3029

3130
@pytest.mark.parametrize("value", [0, 1, CanPacketType.FIRST_FRAME, CanPacketType.SINGLE_FRAME])
3231
def test_is_initial_packet_type__true(self, value):
33-
self.mock_validate_member.side_effect = lambda arg: arg
3432
assert CanPacketType.is_initial_packet_type(value) is True
3533
self.mock_validate_member.assert_called_once_with(value)

tests/software_tests/utilities/test_bytes_operations.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def teardown_method(self):
4040
([0x98, 0x76, 0x54, 0x32, 0x1F], Endianness.LITTLE_ENDIAN, 0x1F32547698),
4141
])
4242
def test_bytes_list_to_int(self, bytes_list, endianness, expected_output):
43-
self.mock_validate_endianness.side_effect = lambda arg: arg
4443
assert bytes_list_to_int(bytes_list=bytes_list, endianness=endianness) == expected_output
4544
self.mock_validate_raw_bytes.assert_called_once_with(bytes_list)
4645
self.mock_validate_endianness.assert_called_once_with(endianness)

uds/can/addressing_information.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,12 @@ def decode_packet_ai(cls,
137137
"""
138138
from_data_bytes = cls.decode_ai_data_bytes(addressing_format=addressing_format, ai_data_bytes=ai_data_bytes)
139139
from_can_id = CanIdHandler.decode_can_id(addressing_format=addressing_format, can_id=can_id)
140-
return cls.DecodedAIParamsAlias(
141-
addressing_type=from_can_id.get(AbstractCanAddressingInformation.ADDRESSING_TYPE_NAME, None), # type: ignore # noqa: E501
142-
target_address=from_data_bytes.get(AbstractCanAddressingInformation.TARGET_ADDRESS_NAME, None) # type: ignore # noqa: E501
143-
or from_can_id.get(AbstractCanAddressingInformation.TARGET_ADDRESS_NAME, None),
144-
source_address=from_can_id.get(AbstractCanAddressingInformation.SOURCE_ADDRESS_NAME, None), # type: ignore
145-
address_extension=from_data_bytes.get(AbstractCanAddressingInformation.ADDRESS_EXTENSION_NAME, None)) # type: ignore # noqa: E501
140+
items_names = (AbstractCanAddressingInformation.ADDRESSING_TYPE_NAME,
141+
AbstractCanAddressingInformation.TARGET_ADDRESS_NAME,
142+
AbstractCanAddressingInformation.SOURCE_ADDRESS_NAME,
143+
AbstractCanAddressingInformation.ADDRESS_EXTENSION_NAME)
144+
return {name: from_data_bytes.get(name, None) or from_can_id.get(name, None)
145+
for name in items_names} # type: ignore
146146

147147
@classmethod
148148
def decode_ai_data_bytes(cls,
@@ -166,12 +166,12 @@ def decode_ai_data_bytes(cls,
166166
ai_data_bytes=ai_data_bytes)
167167
if addressing_format in {CanAddressingFormat.NORMAL_11BIT_ADDRESSING,
168168
CanAddressingFormat.NORMAL_FIXED_ADDRESSING}:
169-
return cls.DataBytesAIParamsAlias()
169+
return {}
170170
if addressing_format == CanAddressingFormat.EXTENDED_ADDRESSING:
171-
return cls.DataBytesAIParamsAlias(target_address=ai_data_bytes[0])
171+
return {AbstractCanAddressingInformation.TARGET_ADDRESS_NAME: ai_data_bytes[0]} # type: ignore
172172
if addressing_format in {CanAddressingFormat.MIXED_11BIT_ADDRESSING,
173173
CanAddressingFormat.MIXED_29BIT_ADDRESSING}:
174-
return cls.DataBytesAIParamsAlias(address_extension=ai_data_bytes[0])
174+
return {AbstractCanAddressingInformation.ADDRESS_EXTENSION_NAME: ai_data_bytes[0]} # type: ignore
175175
raise NotImplementedError(f"Missing implementation for: {addressing_format}")
176176

177177
@classmethod
@@ -197,11 +197,11 @@ def encode_ai_data_bytes(cls,
197197
CanAddressingFormat.NORMAL_FIXED_ADDRESSING):
198198
return []
199199
if addressing_format == CanAddressingFormat.EXTENDED_ADDRESSING:
200-
validate_raw_byte(target_address) # type: ignore
200+
validate_raw_byte(target_address)
201201
return [target_address] # type: ignore
202202
if addressing_format in (CanAddressingFormat.MIXED_11BIT_ADDRESSING,
203203
CanAddressingFormat.MIXED_29BIT_ADDRESSING):
204-
validate_raw_byte(address_extension) # type: ignore
204+
validate_raw_byte(address_extension)
205205
return [address_extension] # type: ignore
206206
raise NotImplementedError(f"Missing implementation for: {addressing_format}")
207207

uds/can/extended_addressing_information.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,16 @@ def validate_packet_ai(cls,
4646
if (source_address, address_extension) != (None, None):
4747
raise UnusedArgumentError("Values of Source Address and Address Extension are not supported by "
4848
"Extended Addressing format and all must be None.")
49-
addressing_type = AddressingType.validate_member(addressing_type)
50-
CanIdHandler.validate_can_id(can_id) # type: ignore
51-
validate_raw_byte(target_address) # type: ignore
49+
AddressingType.validate_member(addressing_type)
50+
CanIdHandler.validate_can_id(can_id)
51+
validate_raw_byte(target_address)
5252
if not CanIdHandler.is_extended_addressed_can_id(can_id): # type: ignore
5353
raise InconsistentArgumentsError(f"Provided value of CAN ID is not compatible with "
5454
f"Extended Addressing Format. Actual value: {can_id}")
55-
return PacketAIParamsAlias(addressing_format=CanAddressingFormat.EXTENDED_ADDRESSING,
56-
addressing_type=addressing_type,
57-
can_id=can_id, # type: ignore
58-
target_address=target_address,
59-
source_address=source_address,
60-
address_extension=address_extension)
55+
return PacketAIParamsAlias(
56+
addressing_format=CanAddressingFormat.EXTENDED_ADDRESSING,
57+
addressing_type=addressing_type,
58+
can_id=can_id, # type: ignore
59+
target_address=target_address,
60+
source_address=source_address,
61+
address_extension=address_extension)

uds/can/flow_control.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
__all__ = ["CanFlowStatus", "CanSTminTranslator", "CanFlowControlHandler", "UnrecognizedSTminWarning"]
1111

12-
from typing import Optional
12+
from typing import Optional, Any
1313
from warnings import warn
1414

1515
from aenum import unique
@@ -119,7 +119,7 @@ def encode(cls, time_value: TimeMillisecondsAlias) -> int:
119119
raise ValueError(f"Provided value is out of valid STmin ranges. Actual value: {time_value}")
120120

121121
@classmethod
122-
def is_time_value(cls, value: TimeMillisecondsAlias) -> bool:
122+
def is_time_value(cls, value: Any) -> bool:
123123
"""
124124
Check if provided value is a valid time value of STmin.
125125
@@ -425,8 +425,8 @@ def __encode_valid_flow_status(cls,
425425
"""
426426
CanFlowStatus.validate_member(flow_status)
427427
if flow_status == CanFlowStatus.ContinueToSend:
428-
validate_raw_byte(block_size) # type: ignore
429-
validate_raw_byte(st_min) # type: ignore
428+
validate_raw_byte(block_size)
429+
validate_raw_byte(st_min)
430430
else:
431431
if block_size is not None:
432432
validate_raw_byte(block_size)

uds/can/frame_fields.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
__all__ = ["CanIdHandler", "CanDlcHandler", "DEFAULT_FILLER_BYTE"]
1111

12-
from typing import Optional, Tuple, Set, TypedDict, Dict
12+
from typing import Any, Optional, Tuple, Set, TypedDict, Dict
1313
from bisect import bisect_left
1414

1515
from uds.transmission_attributes import AddressingType
@@ -95,9 +95,9 @@ def decode_can_id(cls, addressing_format: CanAddressingFormat, can_id: int) -> C
9595
if addressing_format in (CanAddressingFormat.NORMAL_11BIT_ADDRESSING,
9696
CanAddressingFormat.EXTENDED_ADDRESSING,
9797
CanAddressingFormat.MIXED_11BIT_ADDRESSING):
98-
return cls.CanIdAIAlias(addressing_type=None,
99-
target_address=None,
100-
source_address=None) # no addressing information can be decoded
98+
return {cls.ADDRESSING_TYPE_NAME: None, # type: ignore
99+
cls.TARGET_ADDRESS_NAME: None,
100+
cls.SOURCE_ADDRESS_NAME: None} # no addressing information can be decoded
101101
raise NotImplementedError(f"Unknown addressing format value was provided: {addressing_format}")
102102

103103
@classmethod
@@ -122,13 +122,15 @@ def decode_normal_fixed_addressed_can_id(cls, can_id: int) -> CanIdAIAlias:
122122
source_address = can_id & 0xFF
123123
can_id_offset = can_id & (~0xFFFF) # value with Target Address and Source Address information erased
124124
if can_id_offset == cls.NORMAL_FIXED_PHYSICAL_ADDRESSING_OFFSET:
125-
return cls.CanIdAIAlias(addressing_type=AddressingType.PHYSICAL,
126-
target_address=target_address,
127-
source_address=source_address)
125+
addressing_type = AddressingType(AddressingType.PHYSICAL)
126+
return {cls.ADDRESSING_TYPE_NAME: addressing_type, # type: ignore
127+
cls.TARGET_ADDRESS_NAME: target_address,
128+
cls.SOURCE_ADDRESS_NAME: source_address}
128129
if can_id_offset == cls.NORMAL_FIXED_FUNCTIONAL_ADDRESSING_OFFSET:
129-
return cls.CanIdAIAlias(addressing_type=AddressingType.FUNCTIONAL,
130-
target_address=target_address,
131-
source_address=source_address)
130+
addressing_type = AddressingType(AddressingType.FUNCTIONAL)
131+
return {cls.ADDRESSING_TYPE_NAME: addressing_type, # type: ignore
132+
cls.TARGET_ADDRESS_NAME: target_address,
133+
cls.SOURCE_ADDRESS_NAME: source_address}
132134
raise NotImplementedError("CAN ID in Normal Fixed Addressing format was provided, but cannot be handled."
133135
f"Actual value: {can_id}")
134136

@@ -154,13 +156,15 @@ def decode_mixed_addressed_29bit_can_id(cls, can_id: int) -> CanIdAIAlias:
154156
source_address = can_id & 0xFF
155157
can_id_offset = can_id & (~0xFFFF) # value with Target Address and Source Address information erased
156158
if can_id_offset == cls.MIXED_29BIT_PHYSICAL_ADDRESSING_OFFSET:
157-
return cls.CanIdAIAlias(addressing_type=AddressingType.PHYSICAL,
158-
target_address=target_address,
159-
source_address=source_address)
159+
addressing_type = AddressingType(AddressingType.PHYSICAL)
160+
return {cls.ADDRESSING_TYPE_NAME: addressing_type, # type: ignore
161+
cls.TARGET_ADDRESS_NAME: target_address,
162+
cls.SOURCE_ADDRESS_NAME: source_address}
160163
if can_id_offset == cls.MIXED_29BIT_FUNCTIONAL_ADDRESSING_OFFSET:
161-
return cls.CanIdAIAlias(addressing_type=AddressingType.FUNCTIONAL,
162-
target_address=target_address,
163-
source_address=source_address)
164+
addressing_type = AddressingType(AddressingType.FUNCTIONAL)
165+
return {cls.ADDRESSING_TYPE_NAME: addressing_type, # type: ignore
166+
cls.TARGET_ADDRESS_NAME: target_address,
167+
cls.SOURCE_ADDRESS_NAME: source_address}
164168
raise NotImplementedError("CAN ID in Normal Fixed Addressing format was provided, but cannot be handled."
165169
f"Actual value: {can_id}")
166170

@@ -372,7 +376,7 @@ def is_extended_can_id(cls, can_id: int) -> bool:
372376
return isinstance(can_id, int) and cls.MIN_EXTENDED_VALUE <= can_id <= cls.MAX_EXTENDED_VALUE
373377

374378
@classmethod
375-
def validate_can_id(cls, value: int, extended_can_id: Optional[bool] = None) -> None:
379+
def validate_can_id(cls, value: Any, extended_can_id: Optional[bool] = None) -> None:
376380
"""
377381
Validate whether provided value is either Standard or Extended CAN ID.
378382
@@ -481,7 +485,7 @@ def is_can_fd_specific_dlc(cls, dlc: int) -> bool:
481485
return dlc in cls.__DLC_SPECIFIC_FOR_CAN_FD
482486

483487
@classmethod
484-
def validate_dlc(cls, value: int) -> None:
488+
def validate_dlc(cls, value: Any) -> None:
485489
"""
486490
Validate whether the provided value is a valid value of CAN DLC.
487491
@@ -496,7 +500,7 @@ def validate_dlc(cls, value: int) -> None:
496500
raise ValueError(f"Provided value is out of DLC values range. Actual value: {value}")
497501

498502
@classmethod
499-
def validate_data_bytes_number(cls, value: int, exact_value: bool = True) -> None:
503+
def validate_data_bytes_number(cls, value: Any, exact_value: bool = True) -> None:
500504
"""
501505
Validate whether provided value is a valid number of data bytes that might be carried a CAN frame.
502506

0 commit comments

Comments
 (0)