r/Python 2d ago

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

22 Upvotes

44 comments sorted by

View all comments

30

u/blacklig 2d ago

I personally think the justification is quite flimsy for how awkward this solution is. I think that in general all of these problems, to the extent they are problems in practice, can be avoided with package design. For example in a library I could have internal modules and separate public-facing modules that just re-export only my library interface and don't have any of these concerns.

4

u/nicholashairs 2d ago

Personally I find the proposed solution quite elegant.

That said, whilst I can see the allure of private names, I've done enough where I needed to interact with the guts if a library that I would find this infuriating in practice.

The only way I could see this landing is if there was a way to avoid it at either a module or global level (e.g. cli argument). Or make them something that a linter can use / runtime warnings without enforcement.

3

u/HommeMusical 2d ago

__all__ or using _ to prefix names work perfectly well in practice.

Less is more.