1、什么是PEP

PEP全称 Python Enhancement Proposals,Python增强提案。

Python核心开发者主要通过邮件列表讨论问题、提议、计划等,PEP通常是汇总了多方信息,经过了部分核心开发者review和认可,最终形成的正式文档,起到了对外公示的作用,通过阅读特定的PEP 文档来深入的了解Python的特定模块功能。

官网对PEP的介绍:

PEP stands for Python Enhancement Proposal. A PEP is a design document providing information to the Python community, or describing a new feature for Python or its processes or environment. The PEP should provide a concise technical specification of the feature and a rationale for the feature.

We intend PEPs to be the primary mechanisms for proposing major new features, for collecting community input on an issue, and for documenting the design decisions that have gone into Python. The PEP author is responsible for building consensus within the community and documenting dissenting opinions.

Because the PEPs are maintained as text files in a versioned repository, their revision history is the historical record of the feature proposal. This historical record is available by the normal git commands for retrieving older revisions, and can also be browsed on GitHub.

PEP代表Python增强方案。PEP是一种设计文档,为Python社区提供信息,或描述Python或其流程或环境的新功能。PEP应提供功能的简明技术规范和功能的基本原理。

我们希望PEP成为提出主要新功能、收集社区对某个问题的意见以及记录Python中的设计决策的主要机制。PEP作者负责在社区内建立共识,并记录不同意见。

由于PEP作为文本文件保存在版本化的存储库中,因此它们的修订历史记录是功能提案的历史记录。这个历史记录可以通过普通的git命令来检索旧的修订版,也可以在GitHub上浏览。

哈哈看完官网的介绍是不是还是云里雾里的,我个人理解PEP就是Python的官方的参考文档,当你对于Python的某个特性不太了解的时候都可以通过查看相应的PEP文档来了解其详细的功能,例如你想了解Python的编码规范可以阅读PEP 8文档

2、PEP 类型

官网将PEP类型分为三类:

There are three kinds of PEP:

  1. Standards Track PEP describes a new feature or implementation for Python. It may also describe an interoperability standard that will be supported outside the standard library for current Python versions before a subsequent PEP adds standard library support in a future version.
  2. An Informational PEP describes a Python design issue, or provides general guidelines or information to the Python community, but does not propose a new feature. Informational PEPs do not necessarily represent a Python community consensus or recommendation, so users and implementers are free to ignore Informational PEPs or follow their advice.
  3. Process PEP describes a process surrounding Python, or proposes a change to (or an event in) a process. Process PEPs are like Standards Track PEPs but apply to areas other than the Python language itself. They may propose an implementation, but not to Python’s codebase; they often require community consensus; unlike Informational PEPs, they are more than recommendations, and users are typically not free to ignore them. Examples include procedures, guidelines, changes to the decision-making process, and changes to the tools or environment used in Python development. Any meta-PEP is also considered a Process PEP.

Standards Track PEP 描述了Python的一个新特性或实现。它还可以描述一个互操作性标准,在后续PEP在未来版本中添加标准库支持之前,该标准将在当前Python版本的标准库之外得到支持。

Informational PEP  描述了Python设计问题,或为Python社区提供了一般指导方针或信息,但没有提出新功能。Informational PEPs 不一定代表Python社区的共识或建议,因此用户和实现者可以自由忽略 Informational PEPs或听从他们的建议。

Process PEP 描述了一个围绕Python的进程,或提出了对进程的更改(或中的事件)。Process PEPs 类似于Standards Track PEPs,但适用于Python语言本身以外的领域。他们可能会提出一个实现,但不会提出Python的代码库;它们往往需要社区达成共识;与Informational PEPs 不同,它们不仅仅是推荐,用户通常不能随意忽略它们。示例包括过程、指导方针、决策过程的更改以及Python开发中使用的工具或环境的更改。任何 meta-PEP 也被视为 Process PEP。

3、PEP工作流程

PEP工作流状态如下图所示:

  • Draft:草案
  • Active:有效提案
  • Accepted:已接受提案
  • Provisional:暂定提案
  • Deferred:延期提案
  • Rejected:被否决提案
  • Withdrawn:撤回提案
  • Final:最终提案
  • Superseded:被取代提案

​4、推荐阅读的PEP

PEP 0 的官网文档路径:https://peps.python.org/pep-0000/

其它的PEP 文档只要把域名中的pep-0000改成对应的PEP文档后面的数字就行,

例如PEP 8对应的文档路径就是:https://peps.python.org/pep-0008/

强烈推荐阅读的PEP文档如下:

PEP 0 – Index of Python Enhancement Proposals (PEPs)    Python增强提案索引

PEP 1 – PEP Purpose and Guidelines    PEP目的和指南

​​PEP 8 – Style Guide for Python Code    编码规范(必读)

PEP 20 – The Zen of Python    Python之禅(必读)

PEP 202 – List Comprehensions    列表生成式

PEP 234 – Iterators    迭代器

PEP 257 – Docstring Conventions    文档注释规范(必读)

PEP 274 – Dict Comprehensions    字典生成式

PEP 279 – The enumerate() built-in function    枚举  

​​​​​​PEP 282 – A Logging System    日志模块

PEP 285 – Adding a bool type    布尔值

PEP 289 – Generator Expressions    生成器表达式

PEP 318 – Decorators for Functions and Methods    装饰器

PEP 343 – The “with” Statement    with语句

PEP 405 – Python Virtual Environments    虚拟环境

PEP 484 – Type Hints    类型约束(必读)

PEP 3107 – Function Annotations    函数注释

5、PEP官方文档译文

PEP 3107 – Function Annotations    函数注释译文

PEP 484 – Type Hints    类型约束(必读)译文


reference:

学习Python,怎能不懂点PEP呢?

https://peps.python.org/pep-0000/

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐