Skip to content

Commit

Permalink
Giving DtypeTuple the Dtype base class.
Browse files Browse the repository at this point in the history
  • Loading branch information
scott-griffiths committed Feb 5, 2025
1 parent e4a9698 commit 71b5830
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions bitformat/_bits.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ def _format_bits(bits: Bits, bits_per_group: int, sep: str, dtype: Dtype | Dtype
colour_end: str, width: int | None = None) -> tuple[str, int]:
get_fn = dtype.unpack
chars_per_group = Bits._chars_per_dtype(dtype, bits_per_group)
if isinstance(dtype, Dtype):
if not isinstance(dtype, DtypeTuple):
if dtype.name == DtypeName.BYTES: # Special case for bytes to print one character each.
get_fn = Bits._get_bytes_printable
if dtype.name == DtypeName.BOOL: # Special case for bool to print '1' or '0' instead of `True` or `False`.
Expand Down Expand Up @@ -1098,7 +1098,7 @@ def _format_bits(bits: Bits, bits_per_group: int, sep: str, dtype: Dtype | Dtype
@staticmethod
def _chars_per_dtype(dtype: Dtype | DtypeTuple, bits_per_group: int):
"""How many characters are needed to represent a number of bits with a given Dtype."""
if isinstance(dtype, Dtype):
if not isinstance(dtype, DtypeTuple):
return Register().name_to_def[dtype.name].bitlength2chars_fn(bits_per_group)
# Start with '[' then add the number of characters for each element and add ', ' for each element, ending with a ']'.
chars = sum(Bits._chars_per_dtype(d, bits_per_group) for d in dtype) + 2 + 2 * (len(dtype) - 1)
Expand Down
2 changes: 1 addition & 1 deletion bitformat/_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ def __str__(self) -> str:
return f"[{self.base_dtype.name}{self.base_dtype.endianness.value}{size_str};{items_str}]"


class DtypeTuple:
class DtypeTuple(Dtype):
"""A data type class, representing a tuple of concrete interpretations of binary data.
DtypeTuple instances are immutable. They are often created implicitly elsewhere via a token string.
Expand Down

0 comments on commit 71b5830

Please # to comment.