Skip to content

Commit

Permalink
Merge pull request #6664 from andyfaff/deprec
Browse files Browse the repository at this point in the history
MAINT: collections import is deprecated
  • Loading branch information
nouiz committed Dec 8, 2018
2 parents dd6595b + 3262b2a commit 31b853f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
16 changes: 10 additions & 6 deletions theano/compat/__init__.py
Expand Up @@ -6,7 +6,15 @@
from six import PY3, b, BytesIO, next
from six.moves import configparser
from six.moves import reload_module as reload
import collections
try:
from collections.abc import (OrderedDict, MutableMapping as DictMixin,
Callable)
except ImportError:
# this raises an DeprecationWarning on py37 and will become
# and Exception in py38. Importing from collections.abc
# won't work on py27
from collections import (OrderedDict, MutableMapping as DictMixin,
Callable)

__all__ = ['PY3', 'b', 'BytesIO', 'next', 'configparser', 'reload']

Expand Down Expand Up @@ -37,8 +45,6 @@ def get_unbound_function(unbound):
return unbound.__func__
return unbound

from collections import OrderedDict, MutableMapping as DictMixin

def decode(x):
return x.decode()

Expand All @@ -58,8 +64,6 @@ def exc_message(e):

cmp = cmp

from collections import OrderedDict, MutableMapping as DictMixin

def decode(x):
return x

Expand All @@ -76,7 +80,7 @@ def decode_with(x, encoding):
class DefaultOrderedDict(OrderedDict):
def __init__(self, default_factory=None, *a, **kw):
if (default_factory is not None and
not isinstance(default_factory, collections.Callable)):
not isinstance(default_factory, Callable)):
raise TypeError('first argument must be callable')
OrderedDict.__init__(self, *a, **kw)
self.default_factory = default_factory
Expand Down
7 changes: 6 additions & 1 deletion theano/misc/ordered_set.py
@@ -1,6 +1,11 @@
from __future__ import absolute_import, print_function, division

from collections import MutableSet
try:
from collections.abc import MutableSet
except ImportError:
# this raises an DeprecationWarning on py37 and will become
# an Exception in py38
from collections import MutableSet
import types
import weakref

Expand Down

0 comments on commit 31b853f

Please sign in to comment.