Skip to content

Commit acaaed3

Browse files
authored
Merge pull request #499 from megies/py38_collections_abc
fix collections abc import for py38
2 parents c954b79 + e2c320b commit acaaed3

File tree

6 files changed

+30
-11
lines changed

6 files changed

+30
-11
lines changed

src/future/backports/http/client.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,15 @@
7979
import io
8080
import os
8181
import socket
82-
import collections
8382
from future.backports.urllib.parse import urlsplit
8483
import warnings
8584
from array import array
8685

86+
if PY2:
87+
from collections import Iterable
88+
else:
89+
from collections.abc import Iterable
90+
8791
__all__ = ["HTTPResponse", "HTTPConnection",
8892
"HTTPException", "NotConnected", "UnknownProtocol",
8993
"UnknownTransferEncoding", "UnimplementedFileMode",
@@ -902,7 +906,7 @@ def send(self, data):
902906
try:
903907
self.sock.sendall(data)
904908
except TypeError:
905-
if isinstance(data, collections.Iterable):
909+
if isinstance(data, Iterable):
906910
for d in data:
907911
self.sock.sendall(d)
908912
else:

src/future/types/newbytes.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@
55
different beast to the Python 3 bytes object.
66
"""
77

8-
from collections import Iterable
98
from numbers import Integral
109
import string
1110
import copy
1211

13-
from future.utils import istext, isbytes, PY3, with_metaclass
12+
from future.utils import istext, isbytes, PY2, PY3, with_metaclass
1413
from future.types import no, issubset
1514
from future.types.newobject import newobject
1615

16+
if PY2:
17+
from collections import Iterable
18+
else:
19+
from collections.abc import Iterable
20+
1721

1822
_builtin_bytes = bytes
1923

src/future/types/newint.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from __future__ import division
99

1010
import struct
11-
import collections
1211

1312
from future.types.newbytes import newbytes
1413
from future.types.newobject import newobject
@@ -17,6 +16,9 @@
1716

1817
if PY3:
1918
long = int
19+
from collections.abc import Iterable
20+
else:
21+
from collections import Iterable
2022

2123

2224
class BaseNewInt(type):
@@ -356,7 +358,7 @@ def from_bytes(cls, mybytes, byteorder='big', signed=False):
356358
raise TypeError("cannot convert unicode objects to bytes")
357359
# mybytes can also be passed as a sequence of integers on Py3.
358360
# Test for this:
359-
elif isinstance(mybytes, collections.Iterable):
361+
elif isinstance(mybytes, Iterable):
360362
mybytes = newbytes(mybytes)
361363
b = mybytes if byteorder == 'big' else mybytes[::-1]
362364
if len(b) == 0:

src/future/types/newmemoryview.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
"""
22
A pretty lame implementation of a memoryview object for Python 2.6.
33
"""
4-
5-
from collections import Iterable
64
from numbers import Integral
75
import string
86

9-
from future.utils import istext, isbytes, PY3, with_metaclass
7+
from future.utils import istext, isbytes, PY2, with_metaclass
108
from future.types import no, issubset
119

10+
if PY2:
11+
from collections import Iterable
12+
else:
13+
from collections.abc import Iterable
1214

1315
# class BaseNewBytes(type):
1416
# def __instancecheck__(cls, instance):

src/future/types/newrange.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@
1919
"""
2020
from __future__ import absolute_import
2121

22-
from collections import Sequence, Iterator
22+
from future.utils import PY2
23+
24+
if PY2:
25+
from collections import Sequence, Iterator
26+
else:
27+
from collections.abc import Sequence, Iterator
2328
from itertools import islice
2429

2530
from future.backports.misc import count # with step parameter on Py2.6

src/future/types/newstr.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
4141
"""
4242

43-
from collections import Iterable
4443
from numbers import Number
4544

4645
from future.utils import PY3, istext, with_metaclass, isnewbytes
@@ -51,6 +50,9 @@
5150
if PY3:
5251
# We'll probably never use newstr on Py3 anyway...
5352
unicode = str
53+
from collections.abc import Iterable
54+
else:
55+
from collections import Iterable
5456

5557

5658
class BaseNewStr(type):

0 commit comments

Comments
 (0)