Coverage for hdl_registers/constant/string_constant.py: 100%
17 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-29 06:41 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-29 06:41 +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 """
16 Represent a string constant.
17 See :ref:`constant_string` for details.
18 """
20 def __init__(self, name: str, value: str, description: str = "") -> None:
21 """
22 Arguments:
23 name: The name of the constant.
24 value: The constant value.
25 description: Textual description for the constant.
26 """
27 self.name = name
28 self.description = description
30 self._value = ""
31 # Assign self._value via setter
32 self.value = value
34 @property
35 def value(self) -> str:
36 """
37 Getter for value.
38 """
39 return self._value
41 @value.setter
42 def value(self, value: str) -> None:
43 """
44 Setter for value that performs sanity checks.
45 """
46 if not isinstance(value, str):
47 raise TypeError(
48 f'Constant "{self.name}" has invalid data type "{type(value)}". Value: "{value}".'
49 )
51 self._value = value
53 def __repr__(self) -> str:
54 return f"""{self.__class__.__name__}(\
55name={self.name},\
56value={self.value},\
57description={self.description},\
58)"""