TL;DR Python Enhancement Proposals (PEPs) are the official way to propose, discuss and document changes to Python. They cover everything from coding style, such as PEP 8, to major language features. Understanding PEPs helps developers follow Python decisions and write code that fits the language’s conventions.
Introduction to PEPs
Programming languages change through decisions, not magic. Python Enhancement Proposals (PEPs) are the main record of those decisions in Python. A PEP can describe a new feature, a process change, or guidance for the Python community.
What Are PEPs?
Python Enhancement Proposals (PEPs) are formal documents that outline new features, improvements, or processes for the Python programming language. They are authored by members of the Python community, including core developers and other contributors, and are intended to provide a clear and structured method for proposing significant changes to Python.
Key Characteristics of PEPs
- Formal Process: PEPs follow a structured format and review process to ensure that proposed changes are thoroughly vetted.
- Community-Driven: They are open to contributions from the entire Python community, fostering collaborative development.
- Documentation: PEPs serve as historical records of Python’s evolution, documenting the rationale behind major decisions and features.
The PEP Process
The PEP process is a well-defined pathway that ensures proposed changes are carefully considered and standardized before being integrated into Python. Here’s an overview of how the PEP process works:
- Idea Conception: A developer identifies a need or improvement for Python and formulates an initial idea.
- Drafting the PEP: The proposer writes a detailed PEP, adhering to the PEP 1 guidelines, which cover the purpose, scope, and structure of PEPs.
- Submission and Review: The PEP is submitted to the Python community, where it undergoes discussion and feedback from other developers.
- Approval: For a PEP to be accepted, it must receive approval from the Python Steering Council or relevant authority, depending on its nature.
- Implementation: Once approved, the proposed changes are implemented in Python, often accompanied by updates to documentation and tooling.
- Finalization: The PEP is updated to reflect its final status and integrated into Python’s official documentation.
Notable PEPs That Shaped Python
Several PEPs introduced features and guidelines that Python developers rely on today.
PEP 8: Style Guide for Python Code
Perhaps the most well-known PEP, PEP 8, provides comprehensive guidelines on writing clean and readable Python code. It covers aspects like indentation, naming conventions, line length, and more, promoting consistency across Python projects.
PEP 20: The Zen of Python
PEP 20, known as the “Zen of Python,” encapsulates Python’s philosophy through a collection of guiding principles. These aphorisms emphasize simplicity, readability, and explicitness.
PEP 484: Type Hints
Introduced in PEP 484, type hints add optional static typing to Python, enhancing code clarity and enabling better tooling support.
PEP 572: Assignment Expressions
PEP 572 introduced the “walrus operator” (:=), allowing assignment within expressions, which can lead to more concise and readable code.
PEP 621: Storing Project Metadata in pyproject.toml
PEP 621 specifies how to write a project’s core metadata in a pyproject.toml file for packaging-related tools to consume. This PEP aims to encourage users to specify core metadata statically for speed, ease of specification, unambiguity, and deterministic consumption by build back-ends. It provides a tool-agnostic way of specifying metadata, making it easier for users to transition between different build back-ends.
Example pyproject.toml:
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
[project]
name = "cat2cat"
authors = [
{name = "Maciej Nasinski", email = "nasinski.maciej@gmail.com"},
]
description = "Unifying an inconsistently coded categorical variable in a panel/longtitudal dataset."
readme = "README.md"
version = "0.1.6"
requires-python = ">=3.8"
keywords = ["panel", "categorical", "longtitudal", "inconsistent", "cat2cat"]
license = {text = "Apache License 2.0 | file LICENSE"}
classifiers = [
"Development Status :: 3 - Alpha",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = [
"numpy",
"pandas",
"scikit-learn",
"importlib-resources"
]
[project.optional-dependencies]
test = ["pytest", "pytest-cov", "mypy"]
docs = [
"Sphinx",
"myst-parser",
"sphinx-autoapi",
"sphinx-rtd-theme"
]
build = ["build"]
benchmark = ["snakeviz"]
styler = ["flake8", "black"]
all = ["cat2cat[test,docs,build,benchmark,styler]"]
[project.urls]
homepage = "https://github.com/Polkas/py-cat2cat"
documentation = "https://py-cat2cat.readthedocs.io/en/latest/"
repository = "https://github.com/Polkas/py-cat2cat"
changelog = "https://raw.githubusercontent.com/Polkas/py-cat2cat/main/CHANGELOG.md"
[tool.setuptools.packages.find]
where = ["src"]
[tool.setuptools.package-data]
"cat2cat.data" = ["*"]
[tool.mypy]
python_version = "3.8"
disallow_untyped_defs = true
ignore_missing_imports = trueHow to Engage with PEPs
Engaging with PEPs is a rewarding way to contribute to Python’s development and stay informed about its direction.
Reading and Understanding PEPs
- Browse Existing PEPs: Explore the PEP Index to read existing proposals and understand Python’s evolution.
- Stay Updated: Follow discussions and updates on Python’s mailing lists or forums to keep abreast of ongoing PEP developments.
Proposing a New PEP
- Identify a Need: Ensure that your proposal addresses a genuine need or improvement for Python.
- Draft Your PEP: Follow the PEP 1 guidelines for drafting, ensuring clarity and thoroughness.
- Seek Feedback: Share your draft with the community for initial feedback before formal submission.
- Iterate and Refine: Incorporate feedback and refine your proposal to address concerns and enhance its feasibility.
- Submit for Review: Once polished, submit your PEP to the Python Steering Council for consideration.
The Importance of PEPs in Python’s Success
PEPs are instrumental in maintaining Python’s growth, ensuring that enhancements are deliberate, well-documented, and community-approved. They provide a transparent process for introducing new features, which helps preserve Python’s core values while allowing it to adapt to modern programming needs.
Benefits of the PEP Process
- Consistency: PEPs ensure that changes align with Python’s philosophy and existing architecture.
- Community Involvement: They foster a collaborative environment where developers can contribute to Python’s direction.
- Documentation: PEPs serve as comprehensive records of why and how Python has evolved over time.
Conclusion
Python Enhancement Proposals (PEPs) are the record of how Python changes. From coding standards such as PEP 8 to type hints in PEP 484, they explain both the decision and the reasoning behind it. Reading PEPs is one of the best ways to understand where Python has been and where it may go next.