提交 919362bc authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Get rid of endless deprecation warnings with py3

上级 88782a76
...@@ -19,7 +19,7 @@ import theano ...@@ -19,7 +19,7 @@ import theano
from theano import config from theano import config
import theano.gof.cc import theano.gof.cc
from six import itervalues from six import itervalues, PY3
from theano.gof import graph from theano.gof import graph
from theano.gof import utils from theano.gof import utils
from theano.gof.cmodule import GCC_compiler from theano.gof.cmodule import GCC_compiler
...@@ -35,6 +35,17 @@ __docformat__ = "restructuredtext en" ...@@ -35,6 +35,17 @@ __docformat__ = "restructuredtext en"
_logger = logging.getLogger('theano.gof.op.Op') _logger = logging.getLogger('theano.gof.op.Op')
# Open file in "universal newline mode".
# In Python 2, this is done by calling open(..., 'U'), but this is
# deprected in Python 3 (where we would need to pass "newline=None",
# which is the default).
if PY3:
_open_u = open
else:
def _open_u(file):
return open(file, 'U')
class CLinkerObject(object): class CLinkerObject(object):
""" """
Standard elements of an Op or Type used with the CLinker. Standard elements of an Op or Type used with the CLinker.
...@@ -1297,7 +1308,7 @@ class COp(Op): ...@@ -1297,7 +1308,7 @@ class COp(Op):
self.func_codes = [] self.func_codes = []
for func_file in func_files: for func_file in func_files:
# U (universal) will convert all new lines format to \n. # U (universal) will convert all new lines format to \n.
with open(func_file, 'U') as f: with _open_u(func_file) as f:
self.func_codes.append(f.read()) self.func_codes.append(f.read())
# If both the old section markers and the new section markers are # If both the old section markers and the new section markers are
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论