[Python-ideas] Adding an "export" decorator in (e.g.) functools
Bill Winslow
bunslow at gmail.com
Fri May 9 09:12:01 CEST 2014
> But your given implementation seems to have a problem: how can
> you import that into another module?
And thus I am caught as not having actually tested this -- you are of
course correct. Having a statement at the bottom defining "__all__" as you
suggest would (partially) defeat the point, which is to make it easy for
the programmer to state what should be public, that is, it shouldn't be
necessary to muck with __all__. I'm trying to avoid the
magicness/arbitraryness of assignments to __all__.
I'll try and think up an alternative implementation that would work as
advertised when imported from another module. (Note that if the code itself
were copy and pasted, the function would work fine, yet importing it fails
-- something I have not yet encountered in Python. This also suggests one
trivial solution -- import a function that instead exec()'s the definition
above.) I suspect I might have to learn something about import internals to
come up with a (better-than-the-trivial) solution. (Copy and pasting code
is of course unacceptable as well.)
> Here's a simpler implementation:
That is of course the same as mine, except less error checking and also
assumes the global already exists (remember, one goal is to not have to
muck with __all__ in any way, not even declaring it above the function
definition). At least somebody else also had the same idea; hopefully I can
come up with an importable solution...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140509/3192e22d/attachment.html>
More information about the Python-ideas
mailing list