The must-read Python’s PEPs
As Python developer, you should know what a PEP is. In case you don’t,
“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” (from PEP 1)
There are three kinds of PEP:
- A Standards Track PEP describes a new feature or implementation for Python
- 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
- A 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
All PEPs are stored in a github repository and the list is in the PEP 0
Now, the main question is: “What are the most important PEPs that a Python developer should be aware of?” I went through the long list and I chose the ones that I think are important to know.
The must know PEPs without witch you cannot be considered a Python programmer are:
- PEP 20 – The Zen of Python: that’s the first PEP you need to read and apply throughout your Python development
- PEP 8 – Style Guide for Python Code: this PEP defines the coding convention when writing Python. I expect everyone writing PEP8 compliant code
- PEP 257 – Docstring Conventions: conventions for Docstring in Python
- PEP 287 – reStructuredText Docstring Format: when plain text is not enough, reStructuredText is the answer for Docstring
The following PEPs don’t fall into any category but it’s good to know their existence anyway:
- PEP 7 – Style Guide for C Code: if you need to contribute to C implementation of Python, that’s the PEP for you
- PEP 404 – Python 2.8 Un-release Schedule: release not found! There will be never a 2.8 Python release. The last Python 2 release is 2.7. It’s time to move to Python 3!
- PEP 440 – Version Identification and Dependency Specification: this PEP describes a scheme for identifying versions of Python software distributions, and declaring dependencies on particular versions
The following PEPs instead will be split between Python versions (2 and 3) and they just represent an attempt to summarise the most relevant ones in order to pick peculiarities of the language itself. The version of python affected and some personal extra comments will be side noted.
Python 2
- PEP 201 – Lockstep Iteration (zip function) (2.0) - it’s very handy
- PEP 202 – List Comprehensions (2.0) - one of my favourites
- PEP 221 – Import As (2.0)
- PEP 234 – Iterators (2.1) - trust me, you will use them
- PEP 236 – Back to the __future__ (2.1) - do you want to use
print()
(from Python 3.X) in Python 2.X? That’s the module for you - PEP 255 – Simple Generators (yield) (2.2) - once you know it, you’ll love it
- PEP 279 – The enumerate() built-in function (2.3) - sometime it is very useful
- PEP 282 – A Logging System
(2.3) - please, don’t debug with
print()
- PEP 285 – Adding a bool type (2.3) - I don’t understand how you live without it!
- PEP 289 – Generator Expressions (2.4) - list comprehensions with generators
- PEP 308 – Conditional Expressions (2.4) - Python “ternary” expression:
X if C else Y
- PEP 318 – Decorators for Functions and Methods (2.4) - @decorators are methods which wrap functions and methods
- PEP 322 – Reverse Iteration (2.4)
- PEP 324 – subprocess - New process module (2.4)
- PEP 327 – Decimal Data Type (2.4) - floatintg point are just too inexact. Period.
- PEP 341 – Unifying try-except and try-finally - Do you know that
try
constructs allow anelse
statement? - PEP 342 – Coroutines via Enhanced Generators (2.5) - still need to get those!
- PEP 343 – The “with” Statement (2.5) - really? Don’t you know it? Shame on you!
- PEP 367 – New Super (2.6) - that’s important, read it!
Python 2 and 3
- PEP 274 – Dict Comprehensions
(originally 2.3, then 2.7 and 3.0) - the beauty of list comprehensions applied
to
Dict
- PEP 372 – Adding an ordered dictionary to collections (2.7, 3.1) - because order matters
- PEP 389 – argparse - New Command Line Parsing Module (2.7, 3.2) - please, stop using optparse right now!
Python 3
- PEP 380 – Syntax for Delegating to a Subgenerator (yield from) (3.3) - a generator to delegate part of its operations to another generator
- PEP 405 – Python Virtual Environments (3.3) - I’m really glad to see a tighter integration with virtual environments
- PEP 417 – Including mock in the Standard Library (3.3) - it’s one of the first modules I pip install when using Python 2.7
- PEP 435 – Adding an Enum type to the Python standard library (3.4)
- PEP 450 – Adding A Statistics Module To The Standard Library (3.4) - never used so far, but I recognise its importance
- PEP 483 - The Theory of Type Hints (3.5) - that’s just a theory for the next PEP
- PEP 484 - Type Hints (3.5) - they are used to easier static analysis and refactoring, potential runtime type checking, and (perhaps, in some contexts) code generation utilizing type information. Python will remain a dynamically typed language, and the authors have no desire to ever make type hints mandatory, even by convention
- PEP 485 – A Function for testing approximate equality (3.5) -
is_close
enough :) - PEP 492 – Coroutines with async and await syntax (3.5) - coroutines start being a proper concept in Python
- PEP 525 – Asynchronous Generators (3.6) - generators made asynchronous
- PEP 526 – Syntax for Variable Annotations (3.6) - it’s like PEP 484 but for variables
- PEP 530 – Asynchronous Comprehensions (3.6) - things are getting complicated eh… asynchronous versions of list, set, dict comprehensions and generator expressions
- PEP 3000 – Python 3000 (3000) - where 3v3rything begins!
- PEP 3101 – Advanced String Formatting (3.0) - stop using % for string formatting and embrace
.format()
method (included in Python 2.6 as well) - PEP 3105 – Make print a function (3.0) - I told you not to use
print
for debugging! Now all your Python 2.X needs a huge refactoring for working in Python 3.X. Joking apart, that’s the most common error when you try to run Python 2.X code using Python 3.X intepreter. - PEP 3107 – Function Annotations (3.0)
- PEP 3109 – Raising Exceptions in Python 3000 (3.0) - yep, in Python 3.X,
raise
changes a bit. It’s worth having a look - PEP 3110 – Catching Exceptions in Python 3000 (3.0) - see above
- PEP 3115 – Metaclasses in Python 3000 (3.0) - well, if you have ever used
__metaclass__
, Python 3.X don’t - PEP 3119 – Introducing Abstract Base Classes (3000) -
abc
, no I haven’t forgotten the alphabet :) - PEP 3120 – Using UTF-8 as the default source encoding (3.0) - this PEP removes a lot of headeaches we have in Python 2.X
- PEP 3129 – Class Decorators (3.0) - like PEP 318 but for classes
- PEP 3135 – New Super (3.0) - it’s PEP 367 for Python 3.X
- PEP 3148 – futures - execute computations asynchronously (3.2) - The
concurrent.futures
module provides a high-level interface for asynchronously executing callables - PEP 3156 – Asynchronous IO Support Rebooted: the “asyncio” Module (3.3) - this is it! the asyncio module
Have I missed anything? What’s your favourite PEP?
Comments