Module digint.notation_format
notation_format
Defines the NotationFromat
type, a dataclass that holds key information about notating numbers.
Also provides a pre defined DEFAULT_FORMAT
, a common notation formating.
Classes
class NotationFormat (*value_symbols: str, undefined_symbol: Optional[str] = None, positive_symbol: Optional[str] = None, negative_symbol: Optional[str] = None, radix_point_symbol: Optional[str] = None, group_split_symbol: Optional[str] = None, group_split_count: int = 0, implicit_positive: bool = False, implicit_negative: bool = False)
-
A dataclass that holds common notation formating information.
Expand source code
@dataclass(init=False) class NotationFormat(SequenceABC, HashableABC): """ `NotationFormat` A dataclass that holds common notation formating information. """ value_symbols:Tuple[str, ...] = tuple() undefined_symbol:Optional[str] = None positive_symbol:Optional[str] = None negative_symbol:Optional[str] = None radix_point_symbol:Optional[str] = None group_split_symbol:Optional[str] = None group_split_count:int = 3 implicit_positive:bool = False implicit_negative:bool = False def __init__(self, *value_symbols:str, undefined_symbol:Optional[str] = None, positive_symbol:Optional[str] = None, negative_symbol:Optional[str] = None, radix_point_symbol:Optional[str] = None, group_split_symbol:Optional[str] = None, group_split_count:int = 0, implicit_positive:bool = False, implicit_negative:bool = False ): self.__frozen:bool = False self.value_symbols:Tuple[str, ...] = value_symbols self.undefined_symbol:Optional[str] = undefined_symbol self.negative_symbol:Optional[str] = negative_symbol self.positive_symbol:Optional[str] = positive_symbol self.radix_point_symbol:Optional[str] = radix_point_symbol self.group_split_symbol:Optional[str] = group_split_symbol self.group_split_count:int = group_split_count self.implicit_positive:bool = implicit_positive self.implicit_negative:bool = implicit_negative self.__frozen = True def __setattribute__(self, name: str, value: Any): if self.__frozen: raise FrozenInstanceError(value, name, self) return super().__setattr__(name, value) @property def unity(self) -> Optional[str]: """ `unity` Returns: The 'unity' symbol (the symbol associated with the value of 1), if defined, from the `value_symbols`. If not defined, returns `None`. """ return self.value_symbols[1] if len(self.value_symbols) >= 1 else None @property def naught(self) -> Optional[str]: """ `naught` Returns: The 'naught' symbol (the symbol associated with the value of 0), if defined, from the `value_symbols`. If not defined, returns `None`. """ return self.value_symbols[0] if len(self.value_symbols) >= 0 else None def get_value(self, symbol:str) -> Optional[int]: """ `get_value` Looks for the first instance of the given symbol in the `value_symbols`. Arguments: `symbol` -- The symbol to look up. Returns: The index (and therefroe the value) of the symbol in `value_symbols` if possible, otherwise returns `None`. """ return None if symbol not in self.value_symbols else self.value_symbols.index(symbol) @overload def __getitem__(self, index:int) -> str: ... @overload def __getitem__(self, index:slice) -> Tuple[str, ...]: ... def __getitem__(self, index:Union[int, slice]) -> Union[str, Tuple[str, ...]]: # noqa:301 return self.value_symbols[index] def get_digit(self, index:int) -> Optional[str]: """ `get_digit` Looks for the symbol for the given value, if possible`. Arguments: `index` -- The index (the digit's value) to find the symbol of. Returns: The symbol of the given value from `value_symbols` if possible, otherwise returns `None`. """ if index < 0 or index >= len(self.value_symbols): return self.undefined_symbol else: return self.value_symbols[index] def __len__(self): return len(self.value_symbols) def __iter__(self) -> Iterator[str]: return iter(self.value_symbols) def __reverse__(self) -> Iterator[str]: return reversed(self.value_symbols) def copy(self, *_) -> 'NotationFormat': """ `copy` Returns a deep copy of the object. """ return NotationFormat(*self.value_symbols, undefined_symbol = self.undefined_symbol, positive_symbol = self.positive_symbol, negative_symbol = self.negative_symbol, radix_point_symbol = self.radix_point_symbol, group_split_symbol = self.group_split_symbol, group_split_count = self.group_split_count, implicit_positive = self.implicit_positive, implicit_negative = self.implicit_negative ) __copy__ = copy __deepcopy__ = copy def __hash__(self) -> int: return hash(asdict(self))
Ancestors
- collections.abc.Sequence
- collections.abc.Reversible
- collections.abc.Collection
- collections.abc.Sized
- collections.abc.Iterable
- collections.abc.Container
- collections.abc.Hashable
Class variables
var group_split_count : int
var group_split_symbol : Optional[str]
var implicit_negative : bool
var implicit_positive : bool
var negative_symbol : Optional[str]
var positive_symbol : Optional[str]
var radix_point_symbol : Optional[str]
var undefined_symbol : Optional[str]
var value_symbols : Tuple[str, ...]
Instance variables
prop naught : Optional[str]
-
naught
Returns
The 'naught' symbol (the symbol associated with the value of 0), if defined, from the
value_symbols
. If not defined, returnsNone
.Expand source code
@property def naught(self) -> Optional[str]: """ `naught` Returns: The 'naught' symbol (the symbol associated with the value of 0), if defined, from the `value_symbols`. If not defined, returns `None`. """ return self.value_symbols[0] if len(self.value_symbols) >= 0 else None
prop unity : Optional[str]
-
unity
Returns
The 'unity' symbol (the symbol associated with the value of 1), if defined, from the
value_symbols
. If not defined, returnsNone
.Expand source code
@property def unity(self) -> Optional[str]: """ `unity` Returns: The 'unity' symbol (the symbol associated with the value of 1), if defined, from the `value_symbols`. If not defined, returns `None`. """ return self.value_symbols[1] if len(self.value_symbols) >= 1 else None
Methods
def copy(self, *_) ‑> NotationFormat
-
copy
Returns a deep copy of the object.
def get_digit(self, index: int) ‑> Optional[str]
-
get_digit
Looks for the symbol for the given value, if possible`.
Arguments
index
– The index (the digit's value) to find the symbol of.Returns
The symbol of the given value from
value_symbols
if possible, otherwise returnsNone
. def get_value(self, symbol: str) ‑> Optional[int]
-
get_value
Looks for the first instance of the given symbol in the
value_symbols
.Arguments
symbol
– The symbol to look up.Returns
The index (and therefroe the value) of the symbol in
value_symbols
if possible, otherwise returnsNone
.