def __init__(self, bits, length=None):
        if isinstance(bits, int):
            if length is None:
                length = bits.bit_length()
            else:
                assert length >= bits.bit_length()
            if bits < 0:
                bits &= (1 << length) - 1
            hash_value = None
        elif isinstance(bits, BitString):
            # No need to make a copy because we use immutable bit arrays
            bits, length, hash_value = bits._bits, bits._length, bits._hash
        elif isinstance(bits, str):
            bit_str = bits
            bits = 0
            for char in bit_str:
                bits <<= 1
                if char == '1':
                    bits += 1
                else:
                    assert char == '0'
            if length is None:
                length = len(bit_str)
            else:
                assert length >= len(bit_str)
            hash_value = None
        else:
            bit_sequence = bits
            bits = 0
            count = 0
            for bit in bit_sequence:
                count += 1
                bits <<= 1
                if bit:
                    bits += 1
            if length is None:
                length = count
            else:
                assert length >= count
            hash_value = None

        super().__init__(bits, hash_value)
        self._length = length
dataset/ETHPy150Open hosford42/xcs/xcs/_python_bitstrings.py/BitString.__init__/original