Skip to content

Commit

Permalink
Don't display length for Dtypes without lengths or with only one poss…
Browse files Browse the repository at this point in the history
…ible length.
  • Loading branch information
scott-griffiths committed Dec 19, 2023
1 parent c83383d commit a50a38e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion bitstring/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ def create(cls, meta_dtype: MetaDtype, length: Optional[int]) -> Dtype:
return x

def __str__(self) -> str:
length_str = '' if (self.length == 0) else str(self.length)
hide_length = self.is_unknown_length
if self.name in dtype_register._always_fixed_length_cache.keys():
hide_length = True
length_str = '' if hide_length else str(self.length)
return f"{self.name}{length_str}"

def __repr__(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class BasicFunctionality(unittest.TestCase):

def testSettingBool(self):
b = Dtype('bool')
self.assertEqual(str(b), 'bool1')
self.assertEqual(str(b), 'bool')
self.assertEqual(b.name, 'bool')
self.assertEqual(b.length, 1)

Expand Down

0 comments on commit a50a38e

Please sign in to comment.