1. Block attempts to delete constant members from the Class.
2. Block attempts to reassign\rebind a constant member from the Class.
3. Validate letter case of constant member name from the Class.
4. Validate constant member origin type annotation is Final.
5. Validate constant member value type is immutable built-in type.
6. Validate constant member value type is a specific type.
from constant_class import StrConstant
class MyConstant(StrConstant):
FOO = 'foo1'
BAR = 'bar1'
-
- _len_ ->
len(MyConstant) == 2
- _iter_ ->
[c for c in MyConstant] == ['FOO', 'BAR]
- _contains_ ->
'FOO' in MyConstant is True
- _getitem_ ->
MyConstant['FOO'] == 'foo1'
- _repr_, _str_ ->
str(MyConstant) == 'MyConstant(FOO=foo1, BAR=bar1)'
- _len_ ->
-
- has_value(value: object) -> bool ->
MyConstant.has_value('foo1') is True
- has_key(key: str) -> bool ->
MyConstant.has_key('FOO') is True
- get(key: str, default: Optional[object] = None) -> object ->
MyConstant.get('FOO') == 'foo1'
- to_dict -> Dict[str, object] ->
MyConstant.to_dict == {'FOO': 'foo1', 'BAR': 'bar1}
- items -> List[Tuple[str, Any]] ->
MyConstant.items == [('FOO', 'foo1') ('BAR', 'bar1)]
- keys -> List[str] ->
MyConstant.keys == ['FOO', 'BAR']
- values -> List[object] ->
MyConstant.values == ['foo1', 'bar1']
- has_value(value: object) -> bool ->
-
- _letter_case_match_func_: Callable[[str], bool] -> Member name must be specific letter case.
- _error_msg_: str -> Error when Member name is not a specific letter case.
- _strict_type_: Type = object -> Default - Member value type must be specific type.
- _strict_final_: bool = True -> Default - Member origin type annotation must be <Final>.
- _strict_immutable_: bool = True -> Default - Member value type must be <immutable> built-in type.
- Constant:
- Member name must be <SCREAMING_SNAKE_CASE>.
- Member origin type annotation must be <Final>.
- Member value type must be <immutable> built-in type.
- StrConstant:
- Member name must be <SCREAMING_SNAKE_CASE>.
- Member origin type annotation must be <Final>.
- Member value type must be <str> type.
- IntConstant:
- Member name must be <SCREAMING_SNAKE_CASE>.
- Member origin type annotation must be <Final>.
- Member value type must be <int> type.
- SnakeConstant:
- Member name must be <snake_case>.
- Member origin type annotation must be <Final>.
- Member value type must be <immutable> built-in type.
- PascalConstant:
- Member name must be <PascalCase>.
- Member origin type annotation must be <Final>.
- Member value type must be <immutable> built-in type.
- CamelConstant:
- Member name must be <camelCase>.
- Member origin type annotation must be <Final>.
- Member value type must be <immutable> built-in type.
- MixedConstant:
- Anything allowed.