From bcf7176a714364759dab5937483693063e2dd810 Mon Sep 17 00:00:00 2001 From: Scott Griffiths Date: Wed, 12 Jun 2024 21:28:51 +0100 Subject: [PATCH] Deleting some unused code. --- bitformat/bits.py | 72 +------------------------------------------ bitformat/bitstore.py | 6 ---- 2 files changed, 1 insertion(+), 77 deletions(-) diff --git a/bitformat/bits.py b/bitformat/bits.py index ab82f27..6caa5b9 100644 --- a/bitformat/bits.py +++ b/bitformat/bits.py @@ -4,7 +4,6 @@ import sys import struct import io -import re from collections import abc from typing import Union, Iterable, Any, TextIO, overload, Iterator, Type, TypeVar import bitformat @@ -111,10 +110,8 @@ def _create_from_bitstype(cls: Type[TBits], auto: BitsType, /) -> TBits: b = super().__new__(cls) if isinstance(auto, str): b._bitstore = bitstore_helpers.str_to_bitstore(auto) - elif isinstance(auto, Bits): - b._bitstore = auto._bitstore.copy() elif isinstance(auto, (bytes, bytearray, memoryview)): - b._bitstore = BitStore.frombytes(bytearray(auto)) + b._bitstore = BitStore.frombytes(bytes(auto)) elif isinstance(auto, io.BytesIO): b._bitstore = BitStore.frombytes(auto.getvalue()) elif isinstance(auto, abc.Iterable): @@ -562,59 +559,6 @@ def _addright(self, bs: Bits, /) -> None: """Add a bitstring to the RHS of the current bitstring.""" self._bitstore += bs._bitstore - def _addleft(self, bs: Bits, /) -> None: - """Prepend a bitstring to the current bitstring.""" - if bs._bitstore.immutable: - self._bitstore = bs._bitstore._copy() + self._bitstore - else: - self._bitstore = bs._bitstore + self._bitstore - - def _truncateleft(self: TBits, bits: int, /) -> TBits: - """Truncate bits from the start of the bitstring. Return the truncated bits.""" - assert 0 <= bits <= len(self) - if bits == 0: - return self.__class__() - truncated_bits = self._absolute_slice(0, bits) - if bits == len(self): - self._clear() - return truncated_bits - self._bitstore = self._bitstore.getslice_msb0(bits, None) - return truncated_bits - - def _truncateright(self: TBits, bits: int, /) -> TBits: - """Truncate bits from the end of the bitstring. Return the truncated bits.""" - assert 0 <= bits <= len(self) - if bits == 0: - return self.__class__() - truncated_bits = self._absolute_slice(len(self) - bits, len(self)) - if bits == len(self): - self._clear() - return truncated_bits - self._bitstore = self._bitstore.getslice_msb0(None, -bits) - return truncated_bits - - def _insert(self, bs: Bits, pos: int, /) -> None: - """Insert bs at pos.""" - assert 0 <= pos <= len(self) - self._bitstore[pos: pos] = bs._bitstore - return - - def _overwrite(self, bs: Bits, pos: int, /) -> None: - """Overwrite with bs at pos.""" - assert 0 <= pos <= len(self) - if bs is self: - # Just overwriting with self, so do nothing. - assert pos == 0 - return - self._bitstore[pos: pos + len(bs)] = bs._bitstore - - def _delete(self, bits: int, pos: int, /) -> None: - """Delete bits at pos.""" - assert 0 <= pos <= len(self) - assert pos + bits <= len(self), f"pos={pos}, bits={bits}, len={len(self)}" - del self._bitstore[pos: pos + bits] - return - def _reversebytes(self, start: int, end: int) -> None: """Reverse bytes in-place.""" assert (end - start) % 8 == 0 @@ -630,20 +574,6 @@ def _invert_all(self) -> None: """Invert every bit.""" self._bitstore.invert() - def _ilshift(self: TBits, n: int, /) -> TBits: - """Shift bits by n to the left in place. Return self.""" - assert 0 < n <= len(self) - self._addright(Bits(n)) - self._truncateleft(n) - return self - - def _irshift(self: TBits, n: int, /) -> TBits: - """Shift bits by n to the right in place. Return self.""" - assert 0 < n <= len(self) - self._addleft(Bits(n)) - self._truncateright(n) - return self - def _imul(self: TBits, n: int, /) -> TBits: """Concatenate n copies of self in place. Return self.""" assert n >= 0 diff --git a/bitformat/bitstore.py b/bitformat/bitstore.py index f13f0c2..fe62188 100644 --- a/bitformat/bitstore.py +++ b/bitformat/bitstore.py @@ -165,9 +165,6 @@ def _copy(self) -> BitStore: s_copy._bitarray = copy.copy(self._bitarray) return s_copy - def copy(self) -> BitStore: - return self - def __getitem__(self, item: Union[int, slice], /) -> Union[int, BitStore]: # Use getindex or getslice instead raise NotImplementedError @@ -201,6 +198,3 @@ def setitem(self, key, value, /): self._bitarray.__setitem__(key, value._bitarray) else: self._bitarray.__setitem__(key, value) - - def delitem(self, key, /): - self._bitarray.__delitem__(key)