Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
30340e72
提交
30340e72
authored
5月 04, 2015
作者:
David Warde-Farley
提交者:
Arnaud Bergeron
6月 22, 2015
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Spruce up Py3k dev docs.
上级
b321af73
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
65 行增加
和
17 行删除
+65
-17
compat.txt
doc/developer/compat.txt
+65
-17
没有找到文件。
doc/developer/compat.txt
浏览文件 @
30340e72
...
...
@@ -12,37 +12,85 @@ Installation (2to3 and setup.py)
Python code compatibility
-------------------------------------
-------------------------
Ideally, Python 3-incompatible changes should be caught by the Travis build,
but here are some guidelines for the major things to be aware of.
* When catching an exception and giving a name to it, use the new-style
syntax:
Compatibility package (theano.compat)
.....................................
.. code-block:: python
except Exception as e:
...
Compatibility between 2.x and 3.x is implemented using six_, a Python
2 and 3 compatibility library by Benjamin Peterson. A copy of six_
library is included in theano.compat package, but it should not be
called directly. Instead, use symbols exposed at the package level.
* No tuple-unpacking in the argument list:
Correct:
.. code-block:: python
def f(a, (b, c)): # wrong
...
::
def f(a, others):
b, c = others # right
from theano.compat import b
* Always use ``print(...)`` as a function, and add
Incorrect:
.. code-block:: python
from __future__ import print_function
::
At the top of files that use ``print``, above all other imports.
from theano.compat.six import b
* If you mean to iterate over a range, use ``six.moves.xrange``. If you need
a range as a list, use ``list(range(...))``.
::
* If you mean to iterate over a zipped sequence, use ``theano.compat.izip``.
If you actually need it to be a list, use ``list(zip(...))``.
from six import b
* If you mean to iterate over the output of a ``map``, use
``theano.compat.imap``. If you actually need it to be a list, use
``list(map(...))``.
Strings, bytes and unicode
..........................
* If using ``reduce``, ``StringIO``, ``pickle``/``cPickle``, or ``copy_reg``,
use the one in ``six.moves`` (note that ``copy_reg`` is named ``copyreg``).
* For iterating over the items, keys, values of a list, use
``six.iteritems(...)``, ``six.iterkeys(...)``, ``six.itervalues(...)``. If
you wish to grab these as lists, wrap them in a ``list(...)`` call.
* Avoid ``itertools.{izip,ifilter,imap}``. Use the equivalently named functions
from ``theano.compat``.
* Don't use `__builtin__`. Rather, ``six.moves.builtins``.
* Rather than the three-argument version of ``raise``, use
``six.reraise(...)``.
* Don't call the ``.next()`` method of iterators. Use the builtin
``next(...)``.
* When type testing for ``str`` or ``int``/``long``, use ``six.string_types``
and ``six.integer_types``, respectively.
* Use the ``six.add_metaclass`` class decorator for adding metaclasses.
Compatibility package (theano.compat)
.....................................
Compatibility between 2.x and 3.x is implemented using six_, a Python
2 and 3 compatibility library by Benjamin Peterson. Additionally,
certain additional or modified functions are available in the ``theano.compat``
module.
Strings, bytes and unicode
..........................
``str`` and ``bytes`` are different types in Python 3. Mostly this doesn't
come up for Theano's purposes. ``str`` represents encoded text, i.e. character
encoding-aware; all Python 3 strings are internally stored as Unicode. When
converting from one or the other, you must `.encode(...)` bytes and
`.decode(...)` strings with a given character encoding (e.g. ``'ascii'``,
``'utf8'``, ``'latin1'``). Fortunately, these methods exist as no-ops
in Python 2.6 and 2.7.
C code compatibility
--------------------
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论