python Python PEPs ·

PEP 843 Proposes Python Export Statement for DRY Re-exports

previewengineer
announcement

PEP 843 proposes a new `export` statement for Python, designed to simplify the re-export of names in large libraries. This new syntax aims to resolve the maintainability issues of manually synchronizing `__all__` lists and the unintuitive reflexive-alias idiom (`from x import y as y`). By combining the import and `__all__` append operations, it promotes DRY code and enhances clarity for library developers. Currently a draft for Python 3.16, the proposal supports both explicit and wildcard exports, and integrates with conditional logic.

Notes (1)
  • Introduce new 'export' statement for re-exports

    The proposed `export` statement simplifies the process of re-exporting names from internal modules, specifically addressing the verbosity of duplicate `__all__` definitions and the awkwardness of the `from x import y as y` idiom. It integrates import and `__all__` population into a single, clearer syntax, promoting DRY principles in library design. The statement allows for both explicit and wildcard re-exports, and works with conditional logic to manage different exported names based on runtime conditions.

Read the original announcement →

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

Related releases