PEP 843: Export Statement for DRY Re-exports

This is awesome, thanks Neil!

I have some suggestions that I think could make it even better:

  1. As far as I can tell, this PEP currently does not disallow

    def f():
        from spam export ham
    

    But this would be desugared into an __all__ within the scope of f, which isn’t useful and only confusing. But even if this would have updated the module-level __all__, such dynamic exports would be problematic for static typing.
    So I propose we only allow export statements to be used at the module-level, for example by having it then raise a SyntaxError like in PEP 842.

  2. There’s nothing in PEP 843 that mentions or disallows using export in an if typing.TYPE_CHECKING: guard. I can imagine that being very useful for type-check-only utilities in stubs packages (notably _typeshed), where an export exists in the stubs but not at runtime. So I think it would help to to mention that this is an intended use-case.

5 Likes