bitarray 3.7.0__tar.gz → 3.7.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bitarray
3
- Version: 3.7.0
3
+ Version: 3.7.2
4
4
  Summary: efficient arrays of booleans -- C extension
5
5
  Home-page: https://github.com/ilanschnell/bitarray
6
6
  Author: Ilan Schnell
@@ -19,6 +19,7 @@ Classifier: Programming Language :: Python :: 3.10
19
19
  Classifier: Programming Language :: Python :: 3.11
20
20
  Classifier: Programming Language :: Python :: 3.12
21
21
  Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
22
23
  Classifier: Topic :: Utilities
23
24
  License-File: LICENSE
24
25
  Dynamic: author
@@ -76,7 +77,7 @@ Key features
76
77
  Installation
77
78
  ------------
78
79
 
79
- Python wheels are are available on PyPI for all mayor platforms and Python
80
+ Python wheels are are available on PyPI for all major platforms and Python
80
81
  versions. Which means you can simply:
81
82
 
82
83
  .. code-block:: shell-session
@@ -89,7 +90,7 @@ Once you have installed the package, you may want to test it:
89
90
 
90
91
  $ python -c 'import bitarray; bitarray.test()'
91
92
  bitarray is installed in: /Users/ilan/bitarray/bitarray
92
- bitarray version: 3.7.0
93
+ bitarray version: 3.7.2
93
94
  sys.version: 3.13.5 (main, Jun 16 2025) [Clang 18.1.8]
94
95
  sys.prefix: /Users/ilan/miniforge
95
96
  pointer size: 64 bit
@@ -104,7 +105,7 @@ Once you have installed the package, you may want to test it:
104
105
  .........................................................................
105
106
  ................................................................
106
107
  ----------------------------------------------------------------------
107
- Ran 599 tests in 0.166s
108
+ Ran 597 tests in 0.165s
108
109
 
109
110
  OK
110
111
 
@@ -256,85 +257,15 @@ shift (``>>``) always shifts towards higher indices.
256
257
  Bit-endianness
257
258
  --------------
258
259
 
259
- Unless explicitly converting to machine representation, i.e. initializing
260
- the buffer directly, using ``.tobytes()``, ``.frombytes()``, ``.tofile()``
261
- or ``.fromfile()``, as well as using ``memoryview()``, the bit-endianness
262
- will have no effect on any computation, and one can skip this section.
263
-
264
- Since bitarrays allows addressing individual bits, where the machine
265
- represents 8 bits in one byte, there are two obvious choices for this
266
- mapping: little-endian and big-endian.
267
-
268
- When dealing with the machine representation of bitarray objects, it is
269
- recommended to always explicitly specify the endianness.
270
-
271
- By default, bitarrays use big-endian representation:
272
-
273
- .. code-block:: python
274
-
275
- >>> a = bitarray(b'A')
276
- >>> a.endian
277
- 'big'
278
- >>> a
279
- bitarray('01000001')
280
- >>> a[6] = 1
281
- >>> a.tobytes()
282
- b'C'
283
-
284
- Big-endian means that the most-significant bit comes first.
285
- Here, ``a[0]`` is the lowest address (index) and most significant bit,
286
- and ``a[7]`` is the highest address and least significant bit.
287
-
288
- When creating a new bitarray object, the endianness can always be
289
- specified explicitly:
290
-
291
- .. code-block:: python
292
-
293
- >>> a = bitarray(b'A', endian='little')
294
- >>> a
295
- bitarray('10000010')
296
- >>> a.endian
297
- 'little'
298
-
299
- Here, the low-bit comes first because little-endian means that increasing
300
- numeric significance corresponds to an increasing address.
301
- So ``a[0]`` is the lowest address and least significant bit,
302
- and ``a[7]`` is the highest address and most significant bit.
303
-
304
- The bit-endianness is a property of the bitarray object.
305
- The endianness cannot be changed once a bitarray object has been created.
306
- When comparing bitarray objects, the endianness (and hence the machine
307
- representation) is irrelevant; what matters is the mapping from indices
308
- to bits:
309
-
310
- .. code-block:: python
311
-
312
- >>> bitarray('11001', endian='big') == bitarray('11001', endian='little')
313
- True
314
- >>> a = bitarray(b'\x01', endian='little')
315
- >>> b = bitarray(b'\x80', endian='big')
316
- >>> a == b
317
- True
318
- >>> a.tobytes() == b.tobytes()
319
- False
320
-
321
- Bitwise operations (``|``, ``^``, ``&=``, ``|=``, ``^=``, ``~``) are
322
- implemented efficiently using the corresponding byte operations in C, i.e. the
323
- operators act on the machine representation of the bitarray objects.
324
- Therefore, it is not possible to perform bitwise operators on bitarrays
325
- with different endianness.
326
-
327
- As mentioned above, the endianness can not be changed once an object is
328
- created. However, you can create a new bitarray with different endianness:
329
-
330
- .. code-block:: python
331
-
332
- >>> a = bitarray('111000', endian='little')
333
- >>> b = bitarray(a, endian='big')
334
- >>> b
335
- bitarray('111000')
336
- >>> a == b
337
- True
260
+ For many purposes the bit-endianness is not of any relevance to the end user
261
+ and can be regarded as an implementation detail of bitarray objects.
262
+ However, there are use cases when the bit-endianness becomes important.
263
+ These use cases involve explicitly reading and writing the bitarray buffer
264
+ using ``.tobytes()``, ``.frombytes()``, ``.tofile()`` or ``.fromfile()``,
265
+ importing and exporting buffers. Also, a number of utility functions
266
+ in ``bitarray.util`` will return different results depending on
267
+ bit-endianness, such as ``ba2hex()`` or ``ba2int``.
268
+ To better understand this topic, please read `bit-endianness <https://github.com/ilanschnell/bitarray/blob/master/doc/endianness.rst>`__.
338
269
 
339
270
 
340
271
  Buffer protocol
@@ -421,7 +352,7 @@ and can therefore be used as a dictionary key:
421
352
  Reference
422
353
  =========
423
354
 
424
- bitarray version: 3.7.0 -- `change log <https://github.com/ilanschnell/bitarray/blob/master/doc/changelog.rst>`__
355
+ bitarray version: 3.7.2 -- `change log <https://github.com/ilanschnell/bitarray/blob/master/doc/changelog.rst>`__
425
356
 
426
357
  In the following, ``item`` and ``value`` are usually a single bit -
427
358
  an integer 0 or 1.
@@ -799,6 +730,11 @@ This sub-module was added in version 1.2.
799
730
  Also, ``a`` may be any object that exposes a writable buffer.
800
731
  Nothing about this function is specific to bitarray objects.
801
732
 
733
+ We should mention that Python's ``array.array`` object has a
734
+ method ``.byteswap()`` with similar functionality. However, unlike
735
+ bitarray's ``util.byteswap()`` function, this method is limited to
736
+ swapping 2, 4, or 8 consecutive bytes.
737
+
802
738
  New in version 3.4
803
739
 
804
740
 
@@ -874,6 +810,10 @@ This sub-module was added in version 1.2.
874
810
  When ``odd=True``, only odd prime numbers are represented in the resulting
875
811
  bitarray ``a``, and ``a[i]`` corresponds to ``2*i+1`` being prime or not.
876
812
 
813
+ Apart from working with prime numbers, this function is useful for
814
+ testing, as it provides a simple way to create a well-defined bitarray
815
+ of any length.
816
+
877
817
  New in version 3.7
878
818
 
879
819
 
@@ -936,11 +876,7 @@ This sub-module was added in version 1.2.
936
876
  set to one. Mathematically equivalent to setting (in a bitarray of
937
877
  length ``n``) all bits at indices ``random.sample(range(n), k)`` to one.
938
878
  The random bitarrays are reproducible when giving Python's ``random.seed()``
939
- with a specific seed value.
940
-
941
- This function requires Python 3.9 or higher, as it depends on the standard
942
- library function ``random.randbytes()``. Raises ``NotImplementedError``
943
- when Python version is too low.
879
+ a specific seed value.
944
880
 
945
881
  New in version 3.6
946
882
 
@@ -44,7 +44,7 @@ Key features
44
44
  Installation
45
45
  ------------
46
46
 
47
- Python wheels are are available on PyPI for all mayor platforms and Python
47
+ Python wheels are are available on PyPI for all major platforms and Python
48
48
  versions. Which means you can simply:
49
49
 
50
50
  .. code-block:: shell-session
@@ -57,7 +57,7 @@ Once you have installed the package, you may want to test it:
57
57
 
58
58
  $ python -c 'import bitarray; bitarray.test()'
59
59
  bitarray is installed in: /Users/ilan/bitarray/bitarray
60
- bitarray version: 3.7.0
60
+ bitarray version: 3.7.2
61
61
  sys.version: 3.13.5 (main, Jun 16 2025) [Clang 18.1.8]
62
62
  sys.prefix: /Users/ilan/miniforge
63
63
  pointer size: 64 bit
@@ -72,7 +72,7 @@ Once you have installed the package, you may want to test it:
72
72
  .........................................................................
73
73
  ................................................................
74
74
  ----------------------------------------------------------------------
75
- Ran 599 tests in 0.166s
75
+ Ran 597 tests in 0.165s
76
76
 
77
77
  OK
78
78
 
@@ -224,85 +224,15 @@ shift (``>>``) always shifts towards higher indices.
224
224
  Bit-endianness
225
225
  --------------
226
226
 
227
- Unless explicitly converting to machine representation, i.e. initializing
228
- the buffer directly, using ``.tobytes()``, ``.frombytes()``, ``.tofile()``
229
- or ``.fromfile()``, as well as using ``memoryview()``, the bit-endianness
230
- will have no effect on any computation, and one can skip this section.
231
-
232
- Since bitarrays allows addressing individual bits, where the machine
233
- represents 8 bits in one byte, there are two obvious choices for this
234
- mapping: little-endian and big-endian.
235
-
236
- When dealing with the machine representation of bitarray objects, it is
237
- recommended to always explicitly specify the endianness.
238
-
239
- By default, bitarrays use big-endian representation:
240
-
241
- .. code-block:: python
242
-
243
- >>> a = bitarray(b'A')
244
- >>> a.endian
245
- 'big'
246
- >>> a
247
- bitarray('01000001')
248
- >>> a[6] = 1
249
- >>> a.tobytes()
250
- b'C'
251
-
252
- Big-endian means that the most-significant bit comes first.
253
- Here, ``a[0]`` is the lowest address (index) and most significant bit,
254
- and ``a[7]`` is the highest address and least significant bit.
255
-
256
- When creating a new bitarray object, the endianness can always be
257
- specified explicitly:
258
-
259
- .. code-block:: python
260
-
261
- >>> a = bitarray(b'A', endian='little')
262
- >>> a
263
- bitarray('10000010')
264
- >>> a.endian
265
- 'little'
266
-
267
- Here, the low-bit comes first because little-endian means that increasing
268
- numeric significance corresponds to an increasing address.
269
- So ``a[0]`` is the lowest address and least significant bit,
270
- and ``a[7]`` is the highest address and most significant bit.
271
-
272
- The bit-endianness is a property of the bitarray object.
273
- The endianness cannot be changed once a bitarray object has been created.
274
- When comparing bitarray objects, the endianness (and hence the machine
275
- representation) is irrelevant; what matters is the mapping from indices
276
- to bits:
277
-
278
- .. code-block:: python
279
-
280
- >>> bitarray('11001', endian='big') == bitarray('11001', endian='little')
281
- True
282
- >>> a = bitarray(b'\x01', endian='little')
283
- >>> b = bitarray(b'\x80', endian='big')
284
- >>> a == b
285
- True
286
- >>> a.tobytes() == b.tobytes()
287
- False
288
-
289
- Bitwise operations (``|``, ``^``, ``&=``, ``|=``, ``^=``, ``~``) are
290
- implemented efficiently using the corresponding byte operations in C, i.e. the
291
- operators act on the machine representation of the bitarray objects.
292
- Therefore, it is not possible to perform bitwise operators on bitarrays
293
- with different endianness.
294
-
295
- As mentioned above, the endianness can not be changed once an object is
296
- created. However, you can create a new bitarray with different endianness:
297
-
298
- .. code-block:: python
299
-
300
- >>> a = bitarray('111000', endian='little')
301
- >>> b = bitarray(a, endian='big')
302
- >>> b
303
- bitarray('111000')
304
- >>> a == b
305
- True
227
+ For many purposes the bit-endianness is not of any relevance to the end user
228
+ and can be regarded as an implementation detail of bitarray objects.
229
+ However, there are use cases when the bit-endianness becomes important.
230
+ These use cases involve explicitly reading and writing the bitarray buffer
231
+ using ``.tobytes()``, ``.frombytes()``, ``.tofile()`` or ``.fromfile()``,
232
+ importing and exporting buffers. Also, a number of utility functions
233
+ in ``bitarray.util`` will return different results depending on
234
+ bit-endianness, such as ``ba2hex()`` or ``ba2int``.
235
+ To better understand this topic, please read `bit-endianness <https://github.com/ilanschnell/bitarray/blob/master/doc/endianness.rst>`__.
306
236
 
307
237
 
308
238
  Buffer protocol
@@ -389,7 +319,7 @@ and can therefore be used as a dictionary key:
389
319
  Reference
390
320
  =========
391
321
 
392
- bitarray version: 3.7.0 -- `change log <https://github.com/ilanschnell/bitarray/blob/master/doc/changelog.rst>`__
322
+ bitarray version: 3.7.2 -- `change log <https://github.com/ilanschnell/bitarray/blob/master/doc/changelog.rst>`__
393
323
 
394
324
  In the following, ``item`` and ``value`` are usually a single bit -
395
325
  an integer 0 or 1.
@@ -767,6 +697,11 @@ This sub-module was added in version 1.2.
767
697
  Also, ``a`` may be any object that exposes a writable buffer.
768
698
  Nothing about this function is specific to bitarray objects.
769
699
 
700
+ We should mention that Python's ``array.array`` object has a
701
+ method ``.byteswap()`` with similar functionality. However, unlike
702
+ bitarray's ``util.byteswap()`` function, this method is limited to
703
+ swapping 2, 4, or 8 consecutive bytes.
704
+
770
705
  New in version 3.4
771
706
 
772
707
 
@@ -842,6 +777,10 @@ This sub-module was added in version 1.2.
842
777
  When ``odd=True``, only odd prime numbers are represented in the resulting
843
778
  bitarray ``a``, and ``a[i]`` corresponds to ``2*i+1`` being prime or not.
844
779
 
780
+ Apart from working with prime numbers, this function is useful for
781
+ testing, as it provides a simple way to create a well-defined bitarray
782
+ of any length.
783
+
845
784
  New in version 3.7
846
785
 
847
786
 
@@ -904,11 +843,7 @@ This sub-module was added in version 1.2.
904
843
  set to one. Mathematically equivalent to setting (in a bitarray of
905
844
  length ``n``) all bits at indices ``random.sample(range(n), k)`` to one.
906
845
  The random bitarrays are reproducible when giving Python's ``random.seed()``
907
- with a specific seed value.
908
-
909
- This function requires Python 3.9 or higher, as it depends on the standard
910
- library function ``random.randbytes()``. Raises ``NotImplementedError``
911
- when Python version is too low.
846
+ a specific seed value.
912
847
 
913
848
  New in version 3.6
914
849
 
@@ -9,14 +9,13 @@ Please find a description of this package at:
9
9
 
10
10
  Author: Ilan Schnell
11
11
  """
12
- from __future__ import absolute_import
13
12
  from collections import namedtuple
14
13
 
15
- from bitarray._bitarray import (bitarray, decodetree, _sysinfo,
16
- bits2bytes, _bitarray_reconstructor,
17
- get_default_endian, _set_default_endian,
18
- __version__)
19
-
14
+ from bitarray._bitarray import (
15
+ bitarray, decodetree, bits2bytes, _bitarray_reconstructor,
16
+ get_default_endian, _set_default_endian, _sysinfo,
17
+ BITARRAY_VERSION as __version__
18
+ )
20
19
 
21
20
  __all__ = ['bitarray', 'frozenbitarray', 'decodetree', 'bits2bytes']
22
21
 
@@ -117,6 +117,9 @@ class bitarray:
117
117
  def __delitem__(self,
118
118
  i: Union[int, slice, bitarray, Sequence]) -> None: ...
119
119
 
120
+ def __buffer__(self, flags: int, /) -> memoryview: ...
121
+ def __release_buffer__(self, buffer: memoryview, /) -> None: ...
122
+
120
123
  def __add__(self, other: bitarray) -> bitarray: ...
121
124
  def __iadd__(self, other: bitarray) -> bitarray: ...
122
125
  def __mul__(self, n: int) -> bitarray: ...
@@ -1323,9 +1323,8 @@ bitarray_invert(bitarrayobject *self, PyObject *args)
1323
1323
  return NULL;
1324
1324
  }
1325
1325
  self->ob_item[i / 8] ^= BITMASK(self, i);
1326
- Py_RETURN_NONE;
1327
1326
  }
1328
- if (PySlice_Check(arg)) {
1327
+ else if (PySlice_Check(arg)) {
1329
1328
  Py_ssize_t start, stop, step, slicelength;
1330
1329
 
1331
1330
  if (PySlice_GetIndicesEx(arg, self->nbits,
@@ -1333,15 +1332,15 @@ bitarray_invert(bitarrayobject *self, PyObject *args)
1333
1332
  return NULL;
1334
1333
  adjust_step_positive(slicelength, &start, &stop, &step);
1335
1334
  invert_range(self, start, stop, step);
1336
- Py_RETURN_NONE;
1337
1335
  }
1338
- if (arg == Py_None) {
1336
+ else if (arg == Py_None) {
1339
1337
  invert_span(self, 0, self->nbits);
1340
- Py_RETURN_NONE;
1341
1338
  }
1342
-
1343
- return PyErr_Format(PyExc_TypeError, "index expect, not '%s' object",
1344
- Py_TYPE(arg)->tp_name);
1339
+ else {
1340
+ return PyErr_Format(PyExc_TypeError, "index expect, not '%s' object",
1341
+ Py_TYPE(arg)->tp_name);
1342
+ }
1343
+ Py_RETURN_NONE;
1345
1344
  }
1346
1345
 
1347
1346
  PyDoc_STRVAR(invert_doc,
@@ -3613,7 +3612,7 @@ endian_from_string(const char *str)
3613
3612
  return ENDIAN_BIG;
3614
3613
 
3615
3614
  PyErr_Format(PyExc_ValueError, "bit-endianness must be either "
3616
- "'little' or 'big', not '%s'", str);
3615
+ "'little' or 'big', not '%s'", str);
3617
3616
  return -1;
3618
3617
  }
3619
3618
 
@@ -4193,7 +4192,8 @@ sysinfo(PyObject *module, PyObject *args)
4193
4192
  R("DEBUG", 0);
4194
4193
  #endif
4195
4194
 
4196
- return PyErr_Format(PyExc_KeyError, "%s", key);
4195
+ PyErr_SetString(PyExc_KeyError, key);
4196
+ return NULL;
4197
4197
  #undef R
4198
4198
  }
4199
4199
 
@@ -4287,8 +4287,8 @@ PyInit__bitarray(void)
4287
4287
  return NULL;
4288
4288
  Py_SET_TYPE(&SearchIter_Type, &PyType_Type);
4289
4289
 
4290
- PyModule_AddObject(m, "__version__",
4291
- PyUnicode_FromString(BITARRAY_VERSION));
4290
+ if (PyModule_AddStringMacro(m, BITARRAY_VERSION) < 0)
4291
+ return NULL;
4292
4292
 
4293
4293
  return m;
4294
4294
  }
@@ -837,7 +837,7 @@ static const char base64_alphabet[] =
837
837
 
838
838
  /* Given the length of the base m in [1..6] and a character c, return
839
839
  its index in the base 2**m alphabet , or -1 if when c is not included.
840
- Note: i >> m checks if i is in range(0, 2**m) */
840
+ Note: i >> m is true when i is not in range(0, 2**m) */
841
841
  static int
842
842
  digit_to_int(int m, char c)
843
843
  {
@@ -2136,6 +2136,17 @@ module_cfw(PyObject *module, PyObject *args) /* count_from_word() */
2136
2136
  return PyLong_FromSsize_t(count_from_word(a, i));
2137
2137
  }
2138
2138
 
2139
+ static PyObject *
2140
+ module_d2i(PyObject *module, PyObject *args)
2141
+ {
2142
+ int m;
2143
+ char c;
2144
+
2145
+ if (!PyArg_ParseTuple(args, "ic", &m, &c))
2146
+ return NULL;
2147
+ return PyLong_FromLong(digit_to_int(m, c));
2148
+ }
2149
+
2139
2150
  static PyObject *
2140
2151
  module_read_n(PyObject *module, PyObject *args)
2141
2152
  {
@@ -2211,6 +2222,7 @@ static PyMethodDef module_functions[] = {
2211
2222
  {"_setup_table", (PyCFunction) module_setup_table, METH_O, 0},
2212
2223
  {"_zlw", (PyCFunction) module_zlw, METH_O, 0},
2213
2224
  {"_cfw", (PyCFunction) module_cfw, METH_VARARGS, 0},
2225
+ {"_d2i", (PyCFunction) module_d2i, METH_VARARGS, 0},
2214
2226
  {"_read_n", (PyCFunction) module_read_n, METH_VARARGS, 0},
2215
2227
  {"_write_n", (PyCFunction) module_write_n, METH_VARARGS, 0},
2216
2228
  {"_sc_rts", (PyCFunction) module_sc_rts, METH_O, 0},
@@ -2242,7 +2254,8 @@ PyInit__util(void)
2242
2254
  Py_SET_TYPE(&CHDI_Type, &PyType_Type);
2243
2255
 
2244
2256
  #ifndef NDEBUG /* expose segment size in debug mode for testing */
2245
- PyModule_AddObject(m, "_SEGSIZE", PyLong_FromSsize_t(SEGSIZE));
2257
+ if (PyModule_AddIntConstant(m, "_SEGSIZE", SEGSIZE) < 0)
2258
+ return NULL;
2246
2259
  #endif
2247
2260
 
2248
2261
  return m;
@@ -4,7 +4,7 @@
4
4
 
5
5
  Author: Ilan Schnell
6
6
  */
7
- #define BITARRAY_VERSION "3.7.0"
7
+ #define BITARRAY_VERSION "3.7.2"
8
8
 
9
9
  #ifdef STDC_HEADERS
10
10
  # include <stddef.h>
@@ -233,7 +233,7 @@ setup_table(char *table, char kop)
233
233
  for (k = 0; k < 256; k++) {
234
234
  char t = 0, j;
235
235
  for (j = 0; j < 8; j++) {
236
- if (k & 1 << j)
236
+ if (k & 1 << j) {
237
237
  /* j are the indices of active bits in k (little endian) */
238
238
  switch (kop) {
239
239
  case 'a': t += j; break; /* add active indices */
@@ -249,6 +249,7 @@ setup_table(char *table, char kop)
249
249
  case 'r': t |= 128 >> j; break; /* reverse bits */
250
250
  default: Py_UNREACHABLE();
251
251
  }
252
+ }
252
253
  }
253
254
  table[k] = t;
254
255
  }
@@ -1,10 +1,12 @@
1
+ # Copyright (c) 2008 - 2025, Ilan Schnell; All Rights Reserved
2
+ # bitarray is published under the PSF license.
3
+ #
4
+ # Author: Ilan Schnell
1
5
  """
2
6
  Tests for bitarray
3
7
 
4
8
  Author: Ilan Schnell
5
9
  """
6
- from __future__ import absolute_import
7
-
8
10
  import re
9
11
  import os
10
12
  import sys
@@ -13,7 +15,8 @@ import unittest
13
15
  import shutil
14
16
  import tempfile
15
17
  from io import BytesIO, UnsupportedOperation
16
- from random import choice, getrandbits, randrange, randint, shuffle
18
+ from random import choice, choices, getrandbits, randrange, randint, shuffle
19
+ from string import whitespace
17
20
 
18
21
  # imports needed inside tests
19
22
  import array
@@ -57,8 +60,6 @@ def urandom_2(n, endian="<RAND>"):
57
60
  del a[n:]
58
61
  return a
59
62
 
60
- WHITESPACE = ' \n\r\t\v'
61
-
62
63
 
63
64
  class Util(object):
64
65
 
@@ -400,10 +401,10 @@ class CreateObjectTests(unittest.TestCase, Util):
400
401
  self.assertRaises(ValueError, bitarray, '0\U00010348') # UCS4
401
402
 
402
403
  def test_string01_whitespace(self):
403
- a = bitarray(WHITESPACE)
404
+ a = bitarray(whitespace)
404
405
  self.assertEqual(a, bitarray())
405
406
 
406
- for c in WHITESPACE:
407
+ for c in whitespace:
407
408
  a = bitarray(c + '1101110001')
408
409
  self.assertEqual(a, bitarray('1101110001'))
409
410
 
@@ -1406,7 +1407,7 @@ class GetSequenceIndexTests(unittest.TestCase, Util):
1406
1407
  def test_random(self):
1407
1408
  for a in self.randombitarrays():
1408
1409
  n = len(a)
1409
- lst = [randrange(n) for _ in range(n // 2)]
1410
+ lst = choices(range(n), k=n//2)
1410
1411
  b = a[lst]
1411
1412
  self.assertEqual(b, bitarray(a[i] for i in lst))
1412
1413
  self.assertEqual(b.endian, a.endian)
@@ -1439,7 +1440,7 @@ class SetSequenceIndexTests(unittest.TestCase, Util):
1439
1440
  def test_bool_random(self):
1440
1441
  for a in self.randombitarrays():
1441
1442
  n = len(a)
1442
- lst = [randrange(n) for _ in range(n // 2)]
1443
+ lst = choices(range(n), k=n//2)
1443
1444
  b = a.copy()
1444
1445
  v = getrandbits(1)
1445
1446
  a[lst] = v
@@ -1473,7 +1474,7 @@ class SetSequenceIndexTests(unittest.TestCase, Util):
1473
1474
  def test_bitarray_random(self):
1474
1475
  for a in self.randombitarrays():
1475
1476
  n = len(a)
1476
- lst = [randrange(n) for _ in range(n // 2)]
1477
+ lst = choices(range(n), k=n//2)
1477
1478
  c = urandom_2(len(lst))
1478
1479
  b = a.copy()
1479
1480
 
@@ -1544,7 +1545,7 @@ class DelSequenceIndexTests(unittest.TestCase, Util):
1544
1545
  def test_random(self):
1545
1546
  for n in range(100):
1546
1547
  a = urandom_2(n)
1547
- lst = [randrange(n) for _ in range(randint(0, n))]
1548
+ lst = choices(range(n), k=randint(0, n))
1548
1549
  b = a.copy()
1549
1550
  del a[lst]
1550
1551
  self.assertEqual(len(a), n - len(set(lst)))
@@ -2614,7 +2615,7 @@ class ExtendTests(unittest.TestCase, Util):
2614
2615
 
2615
2616
  def test_string01_whitespace(self):
2616
2617
  a = bitarray()
2617
- a.extend(WHITESPACE)
2618
+ a.extend(whitespace)
2618
2619
  self.assertEqual(len(a), 0)
2619
2620
  a.extend('0 1\n0\r1\t0\v1_')
2620
2621
  self.assertEqual(a, bitarray('010101'))
@@ -3230,7 +3231,7 @@ class To01Tests(unittest.TestCase, Util):
3230
3231
  def test_sep(self):
3231
3232
  for a in self.randombitarrays():
3232
3233
  sep = "".join(chr(randint(32, 126))
3233
- for _ in range(randrange(10)))
3234
+ for _ in range(randrange(10)))
3234
3235
  self.assertEqual(a.to01(1, sep), sep.join(str(v) for v in a))
3235
3236
 
3236
3237
  a = bitarray("11100111")
@@ -3442,7 +3443,7 @@ class CountTests(unittest.TestCase, Util):
3442
3443
  def test_sparse(self):
3443
3444
  n = 65536
3444
3445
  a = bitarray(n)
3445
- indices = set(randrange(n) for _ in range(256))
3446
+ indices = set(choices(range(n), k=256))
3446
3447
  a[list(indices)] = 1
3447
3448
  self.assertEqual(a.count(1), len(indices))
3448
3449
  self.assertEqual(a.count(0), n - len(indices))
@@ -3633,7 +3634,7 @@ class IndexTests(unittest.TestCase, Util):
3633
3634
  for _ in range(500):
3634
3635
  n = randrange(1, 200)
3635
3636
  a = zeros(n)
3636
- plst = sorted(randrange(n) for _ in range(1, 10))
3637
+ plst = sorted(choices(range(n), k=9))
3637
3638
  a[plst] = 1
3638
3639
  # test without start and stop
3639
3640
  self.assertEqual(a.find(1, right=0), plst[0])