Skip to content

Commit d4cf678

Browse files
tirkarthiautocracy
authored andcommitted
Fix DeprecationWarning regarding collections.abc and isAlive.
1 parent 716ab26 commit d4cf678

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

IPy.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
__version__ = '1.00'
1010

1111
import bisect
12-
import collections
1312
import sys
1413
import types
14+
try:
15+
import collections.abc as collections_abc
16+
except ImportError:
17+
import collections as collections_abc
1518

1619
# Definition of the Ranges for IPv4 IPs
1720
# this should include www.iana.org/assignments/ipv4-address-space
@@ -1022,10 +1025,10 @@ def v46map(self):
10221025
raise ValueError("%s cannot be converted to an IPv4 address."
10231026
% repr(self))
10241027

1025-
class IPSet(collections.MutableSet):
1028+
class IPSet(collections_abc.MutableSet):
10261029
def __init__(self, iterable=[]):
10271030
# Make sure it's iterable, otherwise wrap
1028-
if not isinstance(iterable, collections.Iterable):
1031+
if not isinstance(iterable, collections_abc.Iterable):
10291032
raise TypeError("'%s' object is not iterable" % type(iterable).__name__)
10301033

10311034
# Make sure we only accept IP objects
@@ -1099,7 +1102,7 @@ def len(self):
10991102

11001103
def add(self, value):
11011104
# Make sure it's iterable, otherwise wrap
1102-
if not isinstance(value, collections.Iterable):
1105+
if not isinstance(value, collections_abc.Iterable):
11031106
value = [value]
11041107

11051108
# Check type
@@ -1113,7 +1116,7 @@ def add(self, value):
11131116

11141117
def discard(self, value):
11151118
# Make sure it's iterable, otherwise wrap
1116-
if not isinstance(value, collections.Iterable):
1119+
if not isinstance(value, collections_abc.Iterable):
11171120
value = [value]
11181121

11191122
# This is much faster than iterating over the addresses

test/test_IPy.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,11 @@ def run(self):
788788
it.setDaemon(True)
789789
it.start()
790790
it.join(timeout_duration)
791-
if it.isAlive():
791+
if hasattr(it, 'is_alive'):
792+
is_alive = it.is_alive()
793+
else:
794+
is_alive = it.isAlive()
795+
if is_alive:
792796
return default
793797
else:
794798
return it.result

0 commit comments

Comments
 (0)