Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #110711

Re: __all__ attribute: bug and proposal

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Ethan Furman <ethan@stoneleaf.us>
Newsgroups comp.lang.python
Subject Re: __all__ attribute: bug and proposal
Date Tue, 28 Jun 2016 08:29:14 -0700
Lines 54
Message-ID <mailman.86.1467127758.2358.python-list@python.org> (permalink)
References <d5e97a5e-6f10-4e3f-ab24-113632f16f29@googlegroups.com> <CAPTjJmqLmg5tPhLnvpMOg_+NhYiNOZW_RG2yDbBiqD6MYqtxSg@mail.gmail.com> <CAKJDb-PTja9Wo6SdYGPvvxjDRDGiVWmkw-MhRC2ixNrZMB5Nxw@mail.gmail.com> <577297CA.7000209@stoneleaf.us>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de QyclURRFf/KeMmEbT/Sc8Aj95UkV1NpW2X0gO4y0gMPA==
Return-Path <ethan@stoneleaf.us>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '"""': 0.05; 'subject:bug': 0.05; 'builtin': 0.07; 'pypi': 0.07; 'api': 0.09; '__all__': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'inclusion': 0.09; 'message- id:@stoneleaf.us': 0.09; 'anyway': 0.11; 'def': 0.13; '2016': 0.16; 'agree.': 0.16; "chris'": 0.16; 'cleaner': 0.16; 'confusion': 0.16; 'outdated': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'suggested,': 0.16; 'wrote:': 0.16; 'else,': 0.18; 'library,': 0.18; 'language': 0.19; 'proposed': 0.20; 'decorator': 0.22; 'import': 0.24; 'written': 0.24; 'header :In-Reply-To:1': 0.24; 'mon,': 0.24; 'header:User-Agent:1': 0.26; 'installed': 0.26; '(which': 0.26; 'chris': 0.26; 'defining': 0.27; 'module.': 0.27; "skip:' 10": 0.28; '~ethan~': 0.29; 'classes': 0.30; 'probably': 0.31; 'problem': 0.33; 'skip:_ 30': 0.33; 'lets': 0.33; 'languages': 0.34; 'lists': 0.34; 'primarily': 0.35; 'something': 0.35; 'but': 0.36; 'possible.': 0.36; 'to:addr :python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'being': 0.37; 'one,': 0.37; 'mean': 0.38; 'end': 0.39; 'to:addr:python.org': 0.40; 'called': 0.40; 'bring': 0.62; 'charset:windows-1252': 0.62; '3.6': 0.84; 'decorator,': 0.84; 'worried': 0.84; 'do:': 0.91; 'ware': 0.91
User-Agent Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.2.0
In-Reply-To <CAKJDb-PTja9Wo6SdYGPvvxjDRDGiVWmkw-MhRC2ixNrZMB5Nxw@mail.gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <577297CA.7000209@stoneleaf.us>
X-Mailman-Original-References <d5e97a5e-6f10-4e3f-ab24-113632f16f29@googlegroups.com> <CAPTjJmqLmg5tPhLnvpMOg_+NhYiNOZW_RG2yDbBiqD6MYqtxSg@mail.gmail.com> <CAKJDb-PTja9Wo6SdYGPvvxjDRDGiVWmkw-MhRC2ixNrZMB5Nxw@mail.gmail.com>
Xref csiph.com comp.lang.python:110711

Show key headers only | View raw


On 06/27/2016 09:31 PM, Zachary Ware wrote:
> On Mon, Jun 27, 2016 at 7:32 PM, Chris Angelico wrote:

>> If you're primarily worried about classes and functions, here's a neat
>> trick you can use:
>>
>> __all__ = []
>> def all(thing):
>>      __all__.append(thing.__name__)
>>      return thing
>
> Barry Warsaw has written a nice decorator called 'public' that can be
> installed from PyPI as 'atpublic'[0].  It was proposed for inclusion
> as a builtin in 3.6 [1], but a less-than-enthusiastic response at the
> 2016 Language Summit has put that off indefinitely.  I, for one, would
> like to see it happen anyway [2], and public support may make it
> possible.
>
> The '@public' decorator works like so:
>
> """
> # spam.py
>
> @public
> def spam():
>      return ' '.join(['spam']*10)
>
> @public
> def eggs():
>      return 'bacon'
>
> public(HAM=4)
> assert HAM == 4
>
> assert sorted(__all__) == sorted(['spam', 'eggs', 'HAM'])
> """
>
> This strikes me as being a cleaner approach than what the OP
> suggested, easier to use than Chris' simple decorator, and a nice way
> to bring an end to outdated __all__ lists (which is a problem
> currently plaguing the standard library, and probably many other
> libraries).

I agree.  But lets all do:

   from atpublic import public as api

as using 'public' for the name is bound to lead to confusion with other 
languages that use public to mean something else, and __all__ is really 
defining the public _API_ of that module.

--
~Ethan~

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

__all__ attribute: bug and proposal Pavel S <pavel@schon.cz> - 2016-06-27 13:56 -0700
  Re: __all__ attribute: bug and proposal Chris Angelico <rosuav@gmail.com> - 2016-06-28 07:32 +1000
    Re: __all__ attribute: bug and proposal Pavel S <pavel@schon.cz> - 2016-06-27 15:29 -0700
      Re: __all__ attribute: bug and proposal Chris Angelico <rosuav@gmail.com> - 2016-06-28 08:41 +1000
      Re: __all__ attribute: bug and proposal Terry Reedy <tjreedy@udel.edu> - 2016-06-27 22:46 -0400
        Re: __all__ attribute: bug and proposal Steven D'Aprano <steve@pearwood.info> - 2016-06-28 13:24 +1000
  Re: __all__ attribute: bug and proposal Random832 <random832@fastmail.com> - 2016-06-27 20:25 -0400
  Re: __all__ attribute: bug and proposal Chris Angelico <rosuav@gmail.com> - 2016-06-28 10:32 +1000
  Re: __all__ attribute: bug and proposal MRAB <python@mrabarnett.plus.com> - 2016-06-28 02:55 +0100
  Re: __all__ attribute: bug and proposal Steven D'Aprano <steve@pearwood.info> - 2016-06-28 11:56 +1000
  Re: __all__ attribute: bug and proposal Chris Angelico <rosuav@gmail.com> - 2016-06-28 12:20 +1000
  Re: __all__ attribute: bug and proposal Random832 <random832@fastmail.com> - 2016-06-27 22:27 -0400
  Re: __all__ attribute: bug and proposal Zachary Ware <zachary.ware+pylist@gmail.com> - 2016-06-27 23:31 -0500
  Re: __all__ attribute: bug and proposal Ethan Furman <ethan@stoneleaf.us> - 2016-06-28 08:29 -0700

csiph-web