Skip to content

Commit 41d1c85

Browse files
authored
Merge pull request #418 from altendky/415-altendky-deprecation_warnings
Fix several warnings
2 parents 5c7cdfb + 83b2274 commit 41d1c85

File tree

13 files changed

+71
-26
lines changed

13 files changed

+71
-26
lines changed

src/future/backports/misc.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import subprocess
1818
from math import ceil as oldceil
19-
from collections import Mapping, MutableMapping
2019

2120
from operator import itemgetter as _itemgetter, eq as _eq
2221
import sys
@@ -25,7 +24,12 @@
2524
from itertools import repeat as _repeat, chain as _chain, starmap as _starmap
2625
from socket import getaddrinfo, SOCK_STREAM, error, socket
2726

28-
from future.utils import iteritems, itervalues, PY26, PY3
27+
from future.utils import iteritems, itervalues, PY2, PY26, PY3
28+
29+
if PY2:
30+
from collections import Mapping, MutableMapping
31+
else:
32+
from collections.abc import Mapping, MutableMapping
2933

3034

3135
def ceil(x):

src/future/backports/urllib/request.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,17 @@
109109
import socket
110110
import sys
111111
import time
112-
import collections
113112
import tempfile
114113
import contextlib
115114
import warnings
116115

116+
from future.utils import PY2
117+
118+
if PY2:
119+
from collections import Iterable
120+
else:
121+
from collections.abc import Iterable
122+
117123
# check for SSL
118124
try:
119125
import ssl
@@ -1221,7 +1227,7 @@ def do_request_(self, request):
12211227
mv = memoryview(data)
12221228
size = len(mv) * mv.itemsize
12231229
except TypeError:
1224-
if isinstance(data, collections.Iterable):
1230+
if isinstance(data, Iterable):
12251231
raise ValueError("Content-Length should be specified "
12261232
"for iterable data of type %r %r" % (type(data),
12271233
data))

src/past/builtins/misc.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
import inspect
44

5-
from future.utils import PY3, exec_
5+
from future.utils import PY2, PY3, exec_
6+
7+
if PY2:
8+
from collections import Mapping
9+
else:
10+
from collections.abc import Mapping
611

712
if PY3:
813
import builtins
@@ -76,7 +81,7 @@ def execfile(filename, myglobals=None, mylocals=None):
7681
raise TypeError('globals must be a mapping')
7782
if not isinstance(mylocals, Mapping):
7883
raise TypeError('locals must be a mapping')
79-
with open(filename, "rbU") as fin:
84+
with open(filename, "rb") as fin:
8085
source = fin.read()
8186
code = compile(source, filename, "exec")
8287
exec_(code, myglobals, mylocals)

src/past/types/oldstr.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44

55
from numbers import Integral
66

7-
from past.utils import with_metaclass
7+
from past.utils import PY2, with_metaclass
8+
9+
if PY2:
10+
from collections import Iterable
11+
else:
12+
from collections.abc import Iterable
813

914
_builtin_bytes = bytes
1015

tests/test_future/test_backports.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,21 @@
1010
import inspect
1111
import pickle
1212
from random import randrange, shuffle
13-
from collections import Mapping, MutableMapping
1413

1514
from future.backports.misc import (count,
1615
_count,
1716
OrderedDict,
1817
Counter,
1918
ChainMap,
2019
_count_elements)
21-
from future.utils import PY26
20+
from future.utils import PY2, PY26
2221
from future.tests.base import unittest, skip26, expectedFailurePY27
2322

23+
if PY2:
24+
from collections import Mapping, MutableMapping
25+
else:
26+
from collections.abc import Mapping, MutableMapping
27+
2428

2529
class CountTest(unittest.TestCase):
2630
"""Test the count function."""

tests/test_future/test_bytes.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,12 +701,15 @@ def test_multiple_inheritance(self):
701701
"""
702702
Issue #96 (for newbytes instead of newobject)
703703
"""
704-
import collections
704+
if utils.PY2:
705+
from collections import Container
706+
else:
707+
from collections.abc import Container
705708

706709
class Base(bytes):
707710
pass
708711

709-
class Foo(Base, collections.Container):
712+
class Foo(Base, Container):
710713
def __contains__(self, item):
711714
return False
712715

tests/test_future/test_dict.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,15 @@ def test_multiple_inheritance(self):
111111
"""
112112
Issue #96 (for newdict instead of newobject)
113113
"""
114-
import collections
114+
if utils.PY2:
115+
from collections import Container
116+
else:
117+
from collections.abc import Container
115118

116119
class Base(dict):
117120
pass
118121

119-
class Foo(Base, collections.Container):
122+
class Foo(Base, Container):
120123
def __contains__(self, item):
121124
return False
122125

tests/test_future/test_int.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def __int__(self):
344344

345345
class Foo3(int):
346346
def __int__(self):
347-
return self
347+
return self.real
348348

349349
class Foo4(int):
350350
def __int__(self):
@@ -1069,12 +1069,12 @@ def test_multiple_inheritance(self):
10691069
"""
10701070
Issue #96 (for newint instead of newobject)
10711071
"""
1072-
import collections
1072+
import collections.abc
10731073

10741074
class Base(int):
10751075
pass
10761076

1077-
class Foo(Base, collections.Container):
1077+
class Foo(Base, collections.abc.Container):
10781078
def __add__(self, other):
10791079
return 0
10801080

tests/test_future/test_list.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,15 @@ def test_multiple_inheritance(self):
162162
"""
163163
Issue #96 (for newdict instead of newobject)
164164
"""
165-
import collections
165+
if utils.PY2:
166+
from collections import Container
167+
else:
168+
from collections.abc import Container
166169

167170
class Base(list):
168171
pass
169172

170-
class Foo(Base, collections.Container):
173+
class Foo(Base, Container):
171174
def __contains__(self, item):
172175
return False
173176

tests/test_future/test_object.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,15 @@ def test_multiple_inheritance(self):
209209
"""
210210
Issue #96
211211
"""
212-
import collections
212+
if utils.PY2:
213+
from collections import Container
214+
else:
215+
from collections.abc import Container
213216

214217
class Base(object):
215218
pass
216219

217-
class Foo(Base, collections.Container):
220+
class Foo(Base, Container):
218221
def __contains__(self, item):
219222
return False
220223

tests/test_future/test_range.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@
66
from future.builtins import range
77
from future.tests.base import unittest
88

9-
from collections import Iterator, Sequence
109
from operator import attrgetter
1110

11+
from future.utils import PY2
12+
13+
if PY2:
14+
from collections import Iterator, Sequence
15+
else:
16+
from collections.abc import Iterator, Sequence
17+
1218

1319
class RangeTests(unittest.TestCase):
1420
def test_range(self):
@@ -192,7 +198,7 @@ def test_rev_stepped_slice_rev_stepped_range(self):
192198

193199
def test_slice_zero_step(self):
194200
msg = '^slice step cannot be zero$'
195-
with self.assertRaisesRegexp(ValueError, msg):
201+
with self.assertRaisesRegex(ValueError, msg):
196202
range(8)[::0]
197203

198204
def test_properties(self):

tests/test_future/test_str.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,12 +529,15 @@ def test_multiple_inheritance(self):
529529
"""
530530
Issue #96 (for newstr instead of newobject)
531531
"""
532-
import collections
532+
if utils.PY2:
533+
from collections import Container
534+
else:
535+
from collections.abc import Container
533536

534537
class Base(str):
535538
pass
536539

537-
class Foo(Base, collections.Container):
540+
class Foo(Base, Container):
538541
def __contains__(self, item):
539542
return False
540543

tests/test_future/test_urllib_response.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from future.tests.base import unittest
99

1010

11-
class TestFile(object):
11+
class File(object):
1212

1313
def __init__(self):
1414
self.closed = False
@@ -28,7 +28,7 @@ class Testaddbase(unittest.TestCase):
2828
# TODO(jhylton): Write tests for other functionality of addbase()
2929

3030
def setUp(self):
31-
self.fp = TestFile()
31+
self.fp = File()
3232
self.addbase = urllib_response.addbase(self.fp)
3333

3434
def test_with(self):

0 commit comments

Comments
 (0)