Coverage for hdl_registers/constant/string_constant.py: 100%
17 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-11 20:51 +0000
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-11 20:51 +0000
1# --------------------------------------------------------------------------------------------------
2# Copyright (c) Lukas Vik. All rights reserved.
3#
4# This file is part of the hdl-registers project, an HDL register generator fast enough to run
5# in real time.
6# https://hdl-registers.com
7# https://github.com/hdl-registers/hdl-registers
8# --------------------------------------------------------------------------------------------------
11from .constant import Constant
14class StringConstant(Constant):
15 def __init__(self, name: str, value: str, description: str = "") -> None:
16 """
17 Arguments:
18 name: The name of the constant.
19 value: The constant value.
20 description: Textual description for the constant.
21 """
22 self.name = name
23 self.description = description
25 self._value = ""
26 # Assign self._value via setter
27 self.value = value
29 @property
30 def value(self) -> str:
31 """
32 Getter for value.
33 """
34 return self._value
36 @value.setter
37 def value(self, value: str) -> None:
38 """
39 Setter for value that performs sanity checks.
40 """
41 if not isinstance(value, str):
42 raise TypeError(
43 f'Constant "{self.name}" has invalid data type "{type(value)}". Value: "{value}".'
44 )
46 self._value = value
48 def __repr__(self) -> str:
49 return f"""{self.__class__.__name__}(\
50name={self.name},\
51value={self.value},\
52description={self.description},\
53)"""