Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import ABC from collections.abc instead of collections for Python 3.9 compatibility. #197

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions bitstring.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
"""
r"""
This package defines classes that simplify bit-wise creation, manipulation and
interpretation of data.

Expand Down Expand Up @@ -72,9 +72,13 @@
import os
import struct
import operator
import collections
import array

try:
from collections.abc import Iterable
except ImportError:
from collections import Iterable

byteorder = sys.byteorder

bytealigned = False
Expand Down Expand Up @@ -1311,7 +1315,7 @@ def _setauto(self, s, length, offset):
data = bytearray((s + 7) // 8)
self._datastore = ByteStore(data, s, 0)
return
if isinstance(s, collections.Iterable):
if isinstance(s, Iterable):
# Evaluate each item as True or False and set bits to 1 or 0.
self._setbin_unsafe(''.join(str(int(bool(x))) for x in s))
return
Expand Down Expand Up @@ -3501,7 +3505,7 @@ def invert(self, pos=None):
if pos is None:
self._invert_all()
return
if not isinstance(pos, collections.Iterable):
if not isinstance(pos, Iterable):
pos = (pos,)
length = self.len

Expand Down Expand Up @@ -3589,7 +3593,7 @@ def byteswap(self, fmt=None, start=None, end=None, repeat=True):
bytesizes.append(PACK_CODE_SIZE[f])
else:
bytesizes.extend([PACK_CODE_SIZE[f[-1]]] * int(f[:-1]))
elif isinstance(fmt, collections.Iterable):
elif isinstance(fmt, Iterable):
bytesizes = fmt
for bytesize in bytesizes:
if not isinstance(bytesize, numbers.Integral) or bytesize < 0:
Expand Down
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
\\cleardoublepage
""" % release

latex_elements = {'preamble': '\setcounter{tocdepth}{2}\definecolor{VerbatimBorderColor}{rgb}{1,1,1}',
latex_elements = {'preamble': r'\setcounter{tocdepth}{2}\definecolor{VerbatimBorderColor}{rgb}{1,1,1}',
'fncychap': '\\usepackage[Sonny]{fncychap}',
'maketitle': titlepage,
'papersize': 'a4paper',
Expand Down
9 changes: 7 additions & 2 deletions test/test_bitstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
import bitstring
import copy
import os
import collections

try:
from collections.abc import Iterable
except ImportError:
from collections import Iterable

from bitstring import BitStream, ConstBitStream, pack
from bitstring import offsetcopy

Expand Down Expand Up @@ -3457,7 +3462,7 @@ def testPackingDefaultIntWithKeyword(self):
self.assertEqual(s.len, 17)

def testInitFromIterable(self):
self.assertTrue(isinstance(range(10), collections.Iterable))
self.assertTrue(isinstance(range(10), Iterable))
s = ConstBitStream(range(12))
self.assertEqual(s, '0x7ff')

Expand Down