r/Python • • 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

44 comments sorted by

View all comments

Show parent comment

0

u/denehoffman Aug 02 '26

Lazy imports don’t actually solve a problem either, they’re a convenience to importing something later on in a program. The syntax doesn’t actually do anything you couldn’t do previously in Python, it just makes it easier to write. I personally like it. And pythonic can mean a lot of different things, but in terms of the Zen, and this was brought up when that PEP was discussed, adding a new keyword to do behavior that already exists is not quite Zen (there should be one—and preferably only one—obvious way to do it). You could even argue that the last line, “namespaces are one honking great idea”, means that namespaces are important and properly defining a module interface is equally important.

The PEP explicitly says you can opt out of that behavior. The problem it solves is also quite clear, `__all__` doesn’t apply to `__dir__`, and you shouldn’t implicitly export libraries through the wrong namespace (this is opinion of course, but I agree with it, it’s okay if you don’t!). And it’s hardly draconian, you admit it’s barely different from `__all__`! You can’t have it both ways. It’s just an exception-validated import scheme.

+1 for reminding me the word picayune exists, that’s a great one honestly!

I doubt this PEP will pass. Based on the discussion, the author seems to want to turn it into a warning message, which is somehow worse I think. So oh well, no big deal.