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 和 modules
- copyright、hexversion、version 和 version_info
- displayhook、__displayhook__
- excepthook、__excepthook__、exc_info 和 exc_clear
- exec_prefix 和 prefix
- executable
- exit
- flags、py3kwarning、dont_write_bytecode 和 warn_options
- getfilesystemencoding
- get/setprofile
- get/settrace、call_tracing
- getwindowsversion
- maxint 和 maxunicode
- platform
- ps1 和 ps2
- stdin、stderr、stdout、__stdin__、__stderr__、__stdout__
- tracebacklimit
- 影响 CPython 解释器的数据和函数。
- get/setrecursionlimit
- get/setcheckinterval
- _getframe 和 _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 模块将为 frame 和 code object 等内部类型提供一个极佳的存放位置。
规范
将添加一个名为“interpreter”(参见 命名)的新内置模块。
上面第二组项目将按如下方式拆分到 stdlib 中
- interpreter 模块
- get/setrecursionlimit
- get/setcheckinterval
- _getframe 和 _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
上次修改: 2023年9月9日 17:39:29 GMT