PEP 843: Export Statement for DRY Re-exports - #5078
Conversation
Documentation build overview
|
| * Restrict runtime attribute access to non-exported names, or change | ||
| ``__getattr__`` semantics. See `Why no runtime enforcement`_. | ||
| * Mark a freshly written ``def``, ``class``, or assignment as exported at | ||
| its definition site, the way :pep:`829`'s ``atpublic`` package does with |
There was a problem hiding this comment.
PEP 829 and atpublic are really orthogonal. The latter is a package that has decades long use in the real world. The connection is that with the next version (likely atpublic 8.0.0 with an alpha already released), you'll be able to pip install atpublic[install] to get the public() and private() decorators automatically installed into builtins at interpreter startup time.
There was a problem hiding this comment.
Thanks for the correction, I'll remove mention of PEP 829!
| PEP: 843 | ||
| Title: Export Statement for DRY Re-exports | ||
| Author: Neil Girdhar <mistersheik@gmail.com> | ||
| Discussions-To: https://discuss.python.org/t/108353 |
There was a problem hiding this comment.
Using the 842 thread is fine for the post-history, but you're going to want your own thread for this PEP. Mark this as "Pending" for now; you'll create the thread after merging.
There was a problem hiding this comment.
That makes perfect sense, thank you!
There was a problem hiding this comment.
Yes, discussion should be in another topic than 842, as that one is long enough already!
As there's no sponsor for this one yet, it should be in the Ideas category.
@ZeroIntensity Relatedly, as you're working on a new revision, you may want to lock the old thread (by flagging and asking mods) until you post the new topic. This is something Brett has done to manage his long PEP discussions.
| ``__all__`` and triggers an ``ExportWarning`` on access to anything left | ||
| out. |
There was a problem hiding this comment.
You should probably clarify that ExportWarning is specific to 842.
There was a problem hiding this comment.
I agree: the paragraph structure was confusing. I completely separated the commonalities from the PEP 842-specific points for clarity.
| wildcard equivalent to `Wildcard form`_ and no lazy equivalent to `Lazy | ||
| exports`_. This PEP takes only that one slice, deliberately leaving out |
There was a problem hiding this comment.
PEP 842 allows lazy imports, as it is in the grammar (though I haven't tested the implementation for it). I clarified that in my draft.
There was a problem hiding this comment.
Thanks for clarifying; I've corrected my exposition.
| peps/pep-0838.rst @AlexWaygood | ||
| peps/pep-0840.rst @jeremyhylton @gvanrossum | ||
| peps/pep-0842.rst @ZeroIntensity | ||
| peps/pep-0843.rst @NeilGirdhar |
There was a problem hiding this comment.
Our (GitHub's?) rule is that you need to be a member of the python organization on GitHub to be listed as a code owner. The core dev sponsor is listed here instead.
There was a problem hiding this comment.
Oh, of course! Removed, thanks!
| @@ -0,0 +1,623 @@ | |||
| PEP: 843 | |||
There was a problem hiding this comment.
For the record, you typically need a core dev sponsor before assigning a number. I'm open to sponsoring, but I want to see what happens with the new 842 revision first.
There was a problem hiding this comment.
Awesome!! No rush on my end. Happy to wait and see how the new PEP 842 revision goes before asking anyone to commit. Thanks for taking the time to look over my PEP so carefully.
There was a problem hiding this comment.
Yes, we can keep this open as a courtesy for a bit, but PEPs from non-core devs do need a sponsor.
There was a problem hiding this comment.
We normally only assign numbers when there's a sponsor. There's quite a bit of uncertainty whether this will get one, and some time until we'll know the answer.
Do we want to assign 843 already to this? Or use the usual 9999 placeholder for now?
| @@ -0,0 +1,623 @@ | |||
| PEP: 843 | |||
There was a problem hiding this comment.
Yes, we can keep this open as a courtesy for a bit, but PEPs from non-core devs do need a sponsor.
| in sync by hand every time the public layout changes. | ||
|
|
||
| The second is the reflexive-alias idiom, ``from x import y as y``. Type | ||
| checkers (like mypy even in strict mode) treat it as a signal that the |
There was a problem hiding this comment.
Why "even"? It's a documented part of the type system.
There was a problem hiding this comment.
I was trying to emphasize the universality of the rule, but it didn't come across.
| ========== | ||
|
|
||
| This section is grounded in existing, widely-used libraries rather than | ||
| a hypothetical ``spam`` module. |
There was a problem hiding this comment.
Yeah, this was a weak start. Grounded in affirmative statements instead.
| file: the list of imports (an implementation detail of how the | ||
| flattening is wired up) and the declaration of the public API (a promise | ||
| to users). The two live in separate statements at different places in | ||
| the file, and a reviewer must check them against each other by eye. |
There was a problem hiding this comment.
Or rely on a linter that warns when they're out of sync.
There was a problem hiding this comment.
Good point. I softened the wording. But often linters do the wrong thing and wipe out the import rather than adding to __all__, so linters aren't a perfect fix.
| ``atpublic`` works around this with a function-call form, | ||
| ``public(some_imported_name)``, but that reintroduces the double-write | ||
| this PEP removes: the name is written once in the import and again as an | ||
| argument to ``public()``. A statement-level ``export`` keyword avoids |
There was a problem hiding this comment.
It also doesn't work well with aliases
|
Please add anthe new PEP checklist to the top post, and start checking things off: https://github.com/python/peps/blob/main/.github/PULL_REQUEST_TEMPLATE/Add%20a%20new%20PEP.md |
Basic requirements (all PEP Types)
pep-NNNN.rst), PR title (PEP 123: <Title of PEP>) andPEPheaderuvx pepotron next(orpipx install pepotronthenpep next)AuthororSponsor, and formally confirmed their approvalAuthor,Status(Draft),TypeandCreatedheaders filled out correctlyPEP-Delegate,Topic,RequiresandReplacesheaders completed if appropriate.github/CODEOWNERSfor the PEPStandards Track requirements
Python-Versionset to valid (pre-beta) future Python version, if relevantDiscussions-ToandPost-History