This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author barry
Recipients barry, ethan.furman, martin.panter
Date 2016-03-24.22:52:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <20160324185228.1e949c63@subdivisions.wooz.org>
In-reply-to <1458858662.74.0.965745902297.issue26632@psf.upfronthosting.co.za>
Content
On Mar 24, 2016, at 10:31 PM, Martin Panter wrote:

>FWIW I already invented this :) as written in Issue 22247. Although I think I
>only used it once or twice in my own personal librarie(s). So it’s a nice
>sign that we came up with the same @public name and usage.

Cool!  Consider that bikeshed painted then. :)

>I’m not a fan of hacks depending on the calling frame, and I prefer APIs that
>“only do one thing”. So I am okay with accepting an object and work off its
>__name__ and __module__, but not okay with also accepting a string and
>guessing what module it was defined in.

Yes, but it makes it less convenient to add non-"APIs" to __all__, although I
guess you can just append it at the point of use:

__all__.append('CONST1')
CONST1 = 3

Not as pretty, and now you have two ways of doing it.

Here's another thought:

What if we gave all modules an __all__ automatically, and that was an object
that acted like a list but also had an @public decorator.

import sys

class All(list):
    def public(self, api):
        sys.modules[api.__module__].__all__.append(api.__name__)

__all__ = All()

@__all__.public
def foo():
    pass

@__all__.public
class Bar:
    pass

__all__.append('CONST')
CONST = 1

print(__all__)
History
Date User Action Args
2016-03-24 22:52:32barrysetrecipients: + barry, ethan.furman, martin.panter
2016-03-24 22:52:32barrylinkissue26632 messages
2016-03-24 22:52:31barrycreate