Unverified 提交 31b853fb authored 作者: Frédéric Bastien's avatar Frédéric Bastien 提交者: GitHub

Merge pull request #6664 from andyfaff/deprec

MAINT: collections import is deprecated
...@@ -6,7 +6,15 @@ from __future__ import absolute_import, print_function, division ...@@ -6,7 +6,15 @@ from __future__ import absolute_import, print_function, division
from six import PY3, b, BytesIO, next from six import PY3, b, BytesIO, next
from six.moves import configparser from six.moves import configparser
from six.moves import reload_module as reload 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'] __all__ = ['PY3', 'b', 'BytesIO', 'next', 'configparser', 'reload']
...@@ -37,8 +45,6 @@ if PY3: ...@@ -37,8 +45,6 @@ if PY3:
return unbound.__func__ return unbound.__func__
return unbound return unbound
from collections import OrderedDict, MutableMapping as DictMixin
def decode(x): def decode(x):
return x.decode() return x.decode()
...@@ -58,8 +64,6 @@ else: ...@@ -58,8 +64,6 @@ else:
cmp = cmp cmp = cmp
from collections import OrderedDict, MutableMapping as DictMixin
def decode(x): def decode(x):
return x return x
...@@ -76,7 +80,7 @@ __all__ += ['cmp', 'operator_div', 'DictMixin', 'OrderedDict', 'decode', ...@@ -76,7 +80,7 @@ __all__ += ['cmp', 'operator_div', 'DictMixin', 'OrderedDict', 'decode',
class DefaultOrderedDict(OrderedDict): class DefaultOrderedDict(OrderedDict):
def __init__(self, default_factory=None, *a, **kw): def __init__(self, default_factory=None, *a, **kw):
if (default_factory is not None and 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') raise TypeError('first argument must be callable')
OrderedDict.__init__(self, *a, **kw) OrderedDict.__init__(self, *a, **kw)
self.default_factory = default_factory self.default_factory = default_factory
......
from __future__ import absolute_import, print_function, division 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 types
import weakref import weakref
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论