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