Python Enhancement Proposals (PEPs)

repository·main·Indexed 26 days ago

https://github.com/python/peps

The formal mechanism for proposing new features, processes, or standards for the Python language. This repository includes the PEP rendering system (Sphinx extensions and themes), CPython platform support tiers (Tier 1, 2, and 3), and specific proposals such as PEP 11 regarding platform support and PEP 100 regarding Unicode implementation.

Tokens
139.7K
Snippets
205
Records
752
Agent score
90%

What's inside python-peps

  1. Overview of PyManager (Python Install Manager)

    main

    PyManager (user-facing name: Python Install Manager) is a proposed replacement installer tool distributed as an MSIX package via the Windows Store or python.org. It manages global commands and provides a unified interface for installing and managing CPython runtimes.

    Core Functionality:

    • It does not provide Python directly but provides global commands that locate or install the correct runtime.
    • It provides python.exe, python3.exe, py.exe, and pymanager.exe.
    • These commands are added to the user PATH at very low priority to avoid shadowing existing environments (like activated virtual environments).
  2. Overview of PEP 804: External Dependency Registry and Name Mapping

    main

    PEP 804 specifies a mechanism to map external dependency identifiers (introduced in PEP 725) to their corresponding names and identifiers in other packaging ecosystems (e.g., Linux distributions like Debian/Fedora, Conda, Homebrew, Nix, etc.).

    This allows packaging tools to:

    • Automatically map external dependencies to packages in other repositories.
    • Generate ecosystem-specific installation commands (e.g., apt install, dnf install, brew install) for users.
    • Provide accurate error messages that include the correct package names for the user's specific system package manager.
    • Enable dependency analysis tools to track cross-ecosystem requirements.
  3. Overview of PEP 817: Wheel Variants

    main

    PEP 817 proposes an extension to the Python wheel packaging format called Wheel Variants. This mechanism allows package maintainers to declare multiple build variants for the same package version, enabling installers to automatically select the most appropriate variant based on specific hardware (e.g., GPU acceleration like CUDA or ROCm) or software (e.g., specific dependency ABIs) characteristics.

    Key components of the proposal include:

    • Wheel Variant format: An evolution of the wheel format that distinguishes wheels by hardware or software attributes.
    • Variant provider plugin interface: An interface for installers to dynamically detect platform attributes and select the best-suited wheel.

    The goal is to allow standard installation commands (e.g., {tool} install <package>) to automatically resolve to the optimal hardware-specific build without requiring users to manually select package names or separate indexes.

  4. Overview of PEP 744: JIT Compilation

    main

    PEP 744 describes the introduction of an experimental 'just-in-time' (JIT) compiler into CPython. The JIT uses a 'copy-and-patch' technique to compile optimized micro-ops into machine code at runtime. This approach aims to reduce dispatch overhead, instruction decoding overhead, and memory traffic by moving data from heap-allocated Python frames into hardware registers.

    Key Details:

    • Status: Draft (Experimental)
    • Target Python Version: 3.13
    • Technique: Copy-and-patch compilation generated from a C-like Domain-Specific Language (DSL).
    • Current Usage: It is currently disabled by default and is not intended for production use until it reaches a non-experimental status.
  5. Understand PEP 538 Locale Coercion Behavior

    main

    PEP 538 introduces locale coercion to handle cases where the environment is set to an ASCII-based C locale (e.g., LANG=C), which can cause issues with UTF-8 characters in standard streams and extension modules like GNU readline.

    When locale coercion is active, Python ensures that LC_CTYPE is set to C.UTF-8 to handle UTF-8 characters consistently across the process and its subprocesses. This prevents errors like SyntaxError: 'utf-8' codec can't decode bytes... when interacting with command-line tools or interactive shells.

  6. Understand the Standard Metadata Extensions Namespace

    main

    Standard metadata extensions for Python software packages use the python namespace. These extensions are designed to provide additional information beyond the core packaging metadata.

    Currently defined standard extensions include:

    • python.details
    • python.project
    • python.integrator
    • python.exports
    • python.commands
    • python.constraints

    Note: PEP 459 has been withdrawn because it depended on PEP 426, which was also withdrawn. Metadata extensions are currently handled as additional files installed into metadata directories alongside the main METADATA file (similar to entry_points.txt).

  7. Rationale for PEP 723: Embedded Dependency Metadata

    main

    PEP 723 defines a standard for embedding dependency metadata directly within a single Python script file. This is designed for users writing scripts that are not intended for formal distribution (e.g., shared via Gists, email, or internal tools) but still require specific dependencies to run.

    Key design decisions include:

    • Allowing [tool] tables: Enables script runners to support custom configurations, such as injecting dependency resolution data or instructing scripts to run in specific containers.
    • Tool Behavior: Tools are permitted to modify their behavior based on whether the script contains embedded metadata, even when the script is not the sole input (e.g., a linter running on a directory).
    • Avoiding pyproject.toml: While pyproject.toml is standard for projects, it is considered too complex for simple, single-file scripts that are often shared informally.
    • Avoiding Import Inference: Automatically inferring requirements from import statements is avoided due to parsing difficulties, the inability to map module names to PyPI package names reliably, and security risks (e.g., dependency confusion attacks).
    • Avoiding Python Variable Metadata: Using special variables like __dependencies__ is avoided because it would require all consumers to implement a full Python parser that can handle multiple Python versions.
  8. Status of PEP 595: Improving bugs.python.org

    main

    PEP 595, which proposed improvements to the bugs.python.org (Roundup) tracker, has been Withdrawn.

    Following the acceptance of PEP 581, the Python project is proceeding with the migration of issue tracking to GitHub. This PEP is now considered informational regarding the historical debate between staying on Roundup versus migrating to GitHub Issues.

  9. Implementation logic for PEP 817 variants

    main

    PEP 817 discusses several architectural approaches for handling package variants (e.g., CPU vs GPU versions of libraries like PyTorch).

    Provider Plugins Approach

    Instead of hardcoding compatibility logic into package managers, this approach uses provider plugins. This allows:

    • Independent maintenance of variant properties by those with specific hardware knowledge.
    • Frequent updates without requiring package manager updates.
    • Decision-making by the package maintainer regarding which provider to use.

    Resolver Package Approach (Alternative)

    An alternative considered was using a main package as a "resolver" that directs to specific subpackages (e.g., torch directing to torch-cpu or torch-cu129). This was deemed problematic due to:

    • Risk of name squatting and users accidentally pinning to old variant projects.
    • Complexity in dependency resolution (the resolver would need to query all packages before performing resolution).
    • Loss of the one-to-one mapping between dependencies and installed packages.
  10. Understand the Docutils package structure

    main

    Docutils is organized into several key modules and packages that handle the document processing lifecycle:

    • docutils: Core package containing base classes like Component, SettingsSpec (runtime settings), and TransformSpec (transforms).
    • docutils.core: Provides the Publisher facade class and convenience functions.
    • docutils.frontend: Manages runtime settings, configuration files, and command-line argument processing.
    • docutils.io: Provides a uniform API for low-level input and output.
    • docutils.nodes: Contains the document tree element class library and Visitor pattern base classes.
    • docutils.statemachine: A finite state machine used for text filters and parsers (e.g., reStructuredText).
    • docutils.utils: Utility functions and the Reporter logger class.
    • docutils.parsers: Markup parsers. Use get_parser_class(parser_name) to retrieve a parser module. The base class is Parser.
    • docutils.readers: Context-aware input readers. Use get_reader_class(reader_name) to retrieve a reader module. The base class is Reader.
    • docutils.writers: Output format writers. Use get_writer_class(writer_name) to retrieve a writer module. The base class is Writer.
    • docutils.transforms: Tree transformation logic. Transformer manages and applies transforms, while Transform is the base class for specific transformations.
    • docutils.languages: Language-dependent strings and mappings. Use get_language(language_code) to retrieve the matching module.
  11. Understand the impact of PEP 817 on scientific and AI/ML workflows

    main

    PEP 817 (Wheel Variants) aims to solve packaging limitations in scientific computing and AI/ML by introducing hardware awareness to the wheel format. Currently, users often have to manually specify hardware-dependent variants (e.g., pip install jax[cuda13]) or manage separate package names for different architectures (e.g., xgboost-cpu).

    Key improvements addressed by this PEP include:

    • Automatic Hardware Selection: Enabling commands like pip install jax to automatically select the correct package matching the user's hardware.
    • Simplified Installation: Reducing the need for complex dispatching logic and separate requirements.txt files for CPU vs. GPU versions.
    • Reduced Binary Size: Moving away from "fat binaries" that bundle multiple GPU targets (SMs) into a single wheel.
    • Improved Reproducibility: Making it easier to deploy research code across heterogeneous computing clusters (CPU, GPUs, ASICs) without environment-specific manual procedures.