PEP 843 Proposes Python Export Statement for DRY Re-exports
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.
https://peps.python.org/pep-0843/
Related releases
- Pydantic AI v2.34.0 Introduces LangChain Migration and GLM-5.3 Model Support Pydantic AI Releases ·
- CPython Now Officially Supports RISC-V as a Tier 3 Platform Python Insider ·
- Django Shares Mechanics of Code of Conduct Governance and Contributor Covenant 3.0 Adoption Django Weblog ·
- Python Documentation Now Available in Russian Python Insider ·
- pydantic-ai v2.33.0 Enhances Anthropic SDK Compatibility, Resolves Runtime Issues Pydantic AI Releases ·
- Pydantic-AI v2.32.2 Delivers Critical Bug Fixes Pydantic AI Releases ·