提交 473d74ea authored 作者: Frédéric Bastien's avatar Frédéric Bastien 提交者: GitHub

Merge pull request #6741 from hroncok/python39

Various Python 3.9 related import changes
......@@ -6,15 +6,16 @@ from __future__ import absolute_import, print_function, division
from six import PY3, b, BytesIO, next
from six.moves import configparser
from six.moves import reload_module as reload
from collections import OrderedDict
try:
from collections.abc import (OrderedDict, MutableMapping as DictMixin,
Callable)
from collections.abc import (Callable, Iterable, Mapping, ValuesView,
MutableMapping as DictMixin)
except ImportError:
# this raises an DeprecationWarning on py37 and will become
# and Exception in py38. Importing from collections.abc
# and Exception in py39. Importing from collections.abc
# won't work on py27
from collections import (OrderedDict, MutableMapping as DictMixin,
Callable)
from collections import (Callable, Iterable, Mapping, ValuesView,
MutableMapping as DictMixin)
__all__ = ['PY3', 'b', 'BytesIO', 'next', 'configparser', 'reload']
......@@ -73,8 +74,10 @@ else:
def decode_with(x, encoding):
return x
__all__ += ['cmp', 'operator_div', 'DictMixin', 'OrderedDict', 'decode',
'decode_iter', 'get_unbound_function', 'imap', 'izip', 'ifilter']
__all__ += ['cmp', 'operator_div',
'DictMixin', 'Iterable', 'Mapping', 'OrderedDict', 'ValuesView',
'decode', 'decode_iter', 'get_unbound_function',
'imap', 'izip', 'ifilter']
class DefaultOrderedDict(OrderedDict):
......
from __future__ import absolute_import, print_function, division
import collections
import logging
from six.moves import StringIO
......@@ -9,6 +8,7 @@ import theano
from theano import config
import theano.tensor as T
from theano.compile import Mode
from theano.compat import ValuesView
from .mode import get_mode
try:
......@@ -68,7 +68,7 @@ def flatten(l):
A flattened list of objects.
"""
if isinstance(l, (list, tuple, collections.ValuesView)):
if isinstance(l, (list, tuple, ValuesView)):
rval = []
for elem in l:
if isinstance(elem, (list, tuple)):
......
......@@ -5,10 +5,12 @@ import collections
import operator
import functools
from theano.compat import Mapping
class frozendict(collections.Mapping):
class frozendict(Mapping):
"""
An immutable wrapper around dictionaries that implements the complete :py:class:`collections.Mapping`
An immutable wrapper around dictionaries that implements the complete :py:class:`collections.abc.Mapping`
interface. It can be used as a drop-in replacement for dictionaries where immutability and ordering are desired.
"""
......
......@@ -22,7 +22,7 @@ import six
from six.moves import xrange
import theano
from theano.compat import imap, izip
from theano.compat import imap, izip, Callable
from theano import gof, printing
from theano.gof import (Op, utils, Variable, Constant, Type, Apply,
FunctionGraph)
......@@ -33,7 +33,6 @@ from theano.gradient import DisconnectedType
from theano.gradient import grad_undefined
from theano.printing import pprint
import collections
builtin_bool = bool
builtin_complex = complex
......@@ -1028,7 +1027,7 @@ class ScalarOp(Op):
def __init__(self, output_types_preference=None, name=None):
self.name = name
if output_types_preference is not None:
if not isinstance(output_types_preference, collections.Callable):
if not isinstance(output_types_preference, Callable):
raise TypeError(
"Expected a callable for the 'output_types_preference' argument to %s. (got: %s)" %
(self.__class__, output_types_preference))
......
......@@ -6,7 +6,10 @@ from __future__ import absolute_import, print_function, division
import logging
from six import reraise, integer_types
import sys
from fractions import gcd
try:
from math import gcd
except ImportError:
from fractions import gcd
import theano
......
from __future__ import absolute_import, print_function, division
import sys
from textwrap import dedent
import collections
import warnings
import logging
......@@ -22,6 +21,7 @@ from theano.tensor.basic import (addbroadcast, clip, get_scalar_constant_value,
from theano.tensor.elemwise import DimShuffle
from theano.tensor.type_other import NoneConst, SliceType, NoneTypeT, make_slice
from theano import config
from theano.compat import Iterable
from .inc_code import inc_code
......@@ -2154,7 +2154,7 @@ def check_and_reject_bool(args_el):
pass
if (not isinstance(args_el, theano.tensor.Variable) and
isinstance(args_el, collections.Iterable)):
isinstance(args_el, Iterable)):
for el in args_el:
check_and_reject_bool(el)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论