Skip to main content Brad's PyNotes

Posts on PEP

  1. PEP 448: Additional Unpacking Generalizations

    TL;DR

    PEP 448 extended Python’s unpacking operators (* and **) in Python 3.5, allowing multiple unpackings in function calls and enabling unpacking directly within list, tuple, set, and dictionary literals. This eliminates verbose workarounds and makes code more concise and readable.

  2. PEP 621: Storing Project Metadata in pyproject.toml

    TL;DR

    PEP 621 established a standardized [project] table in pyproject.toml for declaring Python project metadata. It provided a tool-agnostic, static format that replaced executable setup.py code and tool-specific setup.cfg files with declarative TOML that could be parsed without running code.

  3. PEP 3105: Make print a Function

    TL;DR

    PEP 3105 converted Python’s print statement into a built-in function in Python 3.0. This change provided consistency with the rest of Python’s syntax and allowed features like custom separators, file output redirection, and easy replacement with logging systems.

  4. PEP 257: Docstring Conventions for Self-Documenting Code

    TL;DR

    PEP 257 defines standardized conventions for Python docstrings, covering how to document modules, functions, classes, and methods using string literals that become the __doc__ attribute. The conventions emphasize triple double quotes, command-style phrasing, and consistent formatting.

  5. PEP 3134: Exception Chaining and Embedded Tracebacks

    TL;DR

    PEP 3134 introduced exception chaining in Python 3, allowing exceptions to preserve their context when new exceptions occur during error handling. The raise ... from syntax creates explicit chains, while Python automatically captures implicit chains, both appearing in tracebacks to simplify debugging.

  6. PEP 544: Protocols - Structural Subtyping (Static Duck Typing)

    TL;DR

    PEP 544 introduces Protocol classes that enable structural subtyping (static duck typing) - type checking based on what methods an object has rather than its inheritance hierarchy, making Python’s type system more flexible and duck-typing friendly.

  7. PEP 526: Variable Annotations - Type Hints for Variables

    TL;DR

    PEP 526 introduced variable annotations in Python 3.6, allowing type hints for variables using the syntax variable: type = value, extending PEP 484’s function annotations to all variables for better code documentation and static analysis.

  8. PEP 572: The Walrus Operator - Assignment Expressions in Python

    TL;DR

    PEP 572 introduced the walrus operator (:=) in Python 3.8, allowing assignment within expressions to reduce code duplication and improve readability.

    Interesting!

    The walrus operator gets its name from its resemblance to a walrus face - the colon represents the eyes and the equals sign represents the tusks!

  9. PEP 8: The Python Style Guide That Rules Them All

    TL;DR

    PEP 8 defines Python’s official coding style guide, emphasizing readability with 4-space indentation, descriptive naming conventions, and the principle that “code is read much more often than it is written.”