[Python-ideas] Proposal for special name and qualname symbols
Barry Warsaw
barry at python.org
Wed Jun 8 19:28:29 EDT 2016
On Jun 08, 2016, at 10:57 PM, Michael Selik wrote:
>3. @public for constants (as per Barry's email)
>
>I don't know what that last one was referring to. Do you mind clarifying,
>Barry (or anyone else)?
Sure!
I propose that it's difficult to keep __all__ up to date. Witness the
plethora of bugs open on similar issues in the stdlib. Furthermore, the
definition of __all__ is usually far removed from the object it names. And
it's not obvious when looking at the object whether it is intended to be
exported or not.
@public solves these problems and I contend that its meaning is pretty
obvious, given that (unknown to me at the time) there have been at least two
other independent inventions of nearly exactly the same decorator.
My tracker issue proposing to add `public` to builtins is here:
http://bugs.python.org/issue26632
I gave a lightning talk at the Pycon 2016 language summit about it but it got
a rather frosty reception. ;) OTOH, other people like it, I've begun to use it
in my own code, and I like it too. Now you don't have to wait for Python to
catch up <wink>:
http://public.readthedocs.io/en/latest/
https://pypi.io/project/atpublic/
https://gitlab.com/warsaw/public
The issue in this context is that @public as a decorator only works for things
with an __name__, e.g. functions and classes. There have been different
proposals to make it work for constants, and my approach supports calling
public() with keyword arguments, e.g.
public(SEVEN=7)
public(a_bar=Bar())
Admittedly this is rather un-Pythonic since it not only modifies the module's
__all__ but it pokes a variable binding into the module globals. It's yucky
and I'd rather be able to do something like:
@public
SEVEN = 7
@public
a_bar = Bar()
Thus the relevance to this thread.
Cheers,
-Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160608/8a415977/attachment.sig>
More information about the Python-ideas
mailing list