Skip to content

Commit

Permalink
Adjustment to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
igorapple committed Dec 29, 2024
1 parent 2dbda71 commit a6c1c2b
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions uds/database/text_data_record.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Definition of TextDataRecord which is class for encode and decode values of data records."""
import copy
from typing import Optional, Tuple, Union, Dict
from uu import decode

from uds.database.abstract_data_record import (AbstractDataRecord, DataRecordType, DataRecordPhysicalValueAlias,
DecodedDataRecord)
Expand All @@ -18,8 +16,7 @@ def __init__(self, name: str, length: int, mapping: Dict[int, str] = None) -> No
"""
super().__init__(name)
self.length = length
# self.__reversed_mapping = None ### should it be deleted?
self.__mapping = mapping
self.mapping = mapping

@property # noqa: F841
def length(self) -> int:
Expand Down Expand Up @@ -98,12 +95,9 @@ def decode(self, raw_value: int) -> DecodedDataRecord: # noqa: F841
:return: Dictionary with physical value for this Data Record.
"""
if self.__reversed_mapping:
try:
decoded_value = self.__reversed_mapping[raw_value]
return DecodedDataRecord(name=self.name, raw_value=decoded_value, physical_value=raw_value)
except KeyError as error:
raise KeyError("raw_value not found in provided mapping.") from error
if raw_value in self.mapping:
physical_value = self.mapping[raw_value]
return DecodedDataRecord(name=self.name, raw_value=physical_value, physical_value=raw_value)
return DecodedDataRecord(name=self.name, raw_value=raw_value, physical_value=raw_value)

def encode(self, physical_value: DataRecordPhysicalValueAlias) -> int: # noqa: F841
Expand All @@ -117,10 +111,6 @@ def encode(self, physical_value: DataRecordPhysicalValueAlias) -> int: # noqa:
if isinstance(physical_value, int):
return physical_value
elif isinstance(physical_value, str):
if self.__mapping:
try:
return self.__mapping[physical_value]
except KeyError as error:
raise KeyError("physical_value not found in provided mapping.") from error
else:
raise TypeError("During encoding of str mapping must be provided.")
if physical_value in self.__reversed_mapping:
return self.__reversed_mapping[physical_value]
raise KeyError("physical_value not found in provided mapping.")

0 comments on commit a6c1c2b

Please sign in to comment.