PEP 3139 – 清理 sys 和“interpreter”模块
- 作者:
- Benjamin Peterson <benjamin at python.org>
- 状态:
- 已拒绝
- 类型:
- 标准跟踪
- 创建日期:
- 2008年4月4日
- Python 版本:
- 3.0
拒绝通知
Guido 的 -0.5 投票终结了这份 PEP。请参阅 https://mail.python.org/pipermail/python-3000/2008-April/012977.html。
摘要
本 PEP 提议创建一个新的低级模块,用于 CPython 特定的解释器函数,目的是清理 sys 模块,并将通用的 Python 功能与实现细节分离开来。
基本原理
sys 模块当前包含可以分为两大类的函数和数据:
- 在所有 Python 实现中都可用的数据和函数,它们与 Python 虚拟机的一般运行有关。
- argv
- byteorder
- path, path_hooks, meta_path, path_importer_cache, and modules
- copyright, hexversion, version, and version_info
- displayhook, __displayhook__
- excepthook, __excepthook__, exc_info, and exc_clear
- exec_prefix and prefix
- executable
- exit
- flags, py3kwarning, dont_write_bytecode, and warn_options
- getfilesystemencoding
- get/setprofile
- get/settrace, call_tracing
- getwindowsversion
- maxint and maxunicode
- platform
- ps1 and ps2
- stdin, stderr, stdout, __stdin__, __stderr__, __stdout__
- tracebacklimit
- 影响 CPython 解释器的数据和函数。
- get/setrecursionlimit
- get/setcheckinterval
- _getframe and _current_frame
- getrefcount
- get/setdlopenflags
- settscdumps
- api_version
- winver
- dllhandle
- float_info
- _compact_freelists
- _clear_type_cache
- subversion
- builtin_module_names
- callstats
- intern
第二类项目随着时间的推移不断增加,导致 sys 模块变得混乱。Guido 甚至表示他自己都不认识其中的一些东西 [1]!
将这些项目移到另一个模块将向其他 Python 实现传递一个清晰的信息,说明哪些函数是必需的,哪些不是。
还有人提议将 types 模块的内容分发到标准库中 [2];interpreter 模块将为 frames 和 code objects 等内部类型提供一个极好的归宿。
规范
将添加一个名为“interpreter”(参见 命名)的新内置模块。
上面第二类项目的列表将按如下方式分拆到标准库中:
- interpreter 模块
- get/setrecursionlimit
- get/setcheckinterval
- _getframe and _current_frame
- get/setdlopenflags
- settscdumps
- api_version
- winver
- dllhandle
- float_info
- _clear_type_cache
- subversion
- builtin_module_names
- callstats
- intern
- gc 模块
- getrefcount
- _compact_freelists
过渡计划
一旦在 3.x 中实现,interpreter 模块将反向移植到 2.6。将向其替代的 sys 函数添加 Py3k 警告。
未解决的问题
什么应该被移动?
dont_write_bytecode
有人认为字节码的写入是一个实现细节,应该被移走 [3]。反驳意见是,所有当前完整的 Python 实现都会写入某种形式的字节码,因此能够禁用它是有价值的。此外,如果将其移走,有人希望将其放入 imp 模块。
移动到 imp 模块?
有人指出 dont_write_bytecode 或 builtin_module_names 可能很适合放入 imp 模块。
命名
作者为新模块提议的名称是“interpreter”。“pyvm”也曾被建议过 [4]。“cpython”这个名字也很受欢迎 [5]。
参考资料
版权
本文档已置于公共领域。
来源: https://github.com/python/peps/blob/main/peps/pep-3139.rst
最后修改: 2025-02-01 08:59:27 GMT