r/Python • u/poppy_92 • Jul 31 '26
News PEP 842: Module Exports
https://peps.python.org/pep-0842/
Not the author, but this seems interesting, specially for library authors. Thoughts?
Discussion here - https://discuss.python.org/t/pep-842-module-exports/108353
24
Upvotes
View all comments
Show parent comment
2
u/denehoffman Aug 01 '26 edited Aug 01 '26
Every time Python programmers talk about language guarantees, it’s always stuff like “the linter will handle it” and “the type checker will handle it” and then it slowly becomes “well you’ll get an error at runtime”. I’m sure there’s a way I could manually write behavior like this with enough hacky code, but the fact that lots of other languages have privatization should be an indication that it’s not intrinsically evil. It also ensures that users who have been using these private functions and types submit actual feature requests to promote those things to documented features rather than keeping them as little secret hacks for cool kids who read the source code.
Edit: it looks like in the current design, you aren’t prevented from accessing these module attributes. If you’ve ever really want to, you can add them to the export dict manually. The point is to make it an intentional thing you have to do to break the API rather than a thing a new user could do simply by importing something that is importable.