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


Groups > comp.lang.python > #110643

Re: __all__ attribute: bug and proposal

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Zachary Ware <zachary.ware+pylist@gmail.com>
Newsgroups comp.lang.python
Subject Re: __all__ attribute: bug and proposal
Date Mon, 27 Jun 2016 23:31:55 -0500
Lines 47
Sender zachary.ware@gmail.com
Message-ID <mailman.59.1467088338.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>
Reply-To python-list@python.org
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de R34DzRM1vWeNqcsphUGtugTYzEmcZAuvOYlMZ/xvcqaw==
Return-Path <zachary.ware@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'url:pypi': 0.03; '"""': 0.05; 'subject:bug': 0.05; '[0]': 0.07; 'builtin': 0.07; 'pypi': 0.07; '__all__': 0.09; 'inclusion': 0.09; 'anyway': 0.11; 'def': 0.13; '2016': 0.16; "chris'": 0.16; 'cleaner': 0.16; 'outdated': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'suggested,': 0.16; 'wrote:': 0.16; 'sender:addr:gmail.com': 0.18; 'library,': 0.18; 'language': 0.19; 'proposed': 0.20; 'to:name:python- list@python.org': 0.20; 'decorator': 0.22; 'written': 0.24; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'url:bugs': 0.24; 'installed': 0.26; '(which': 0.26; 'chris': 0.26; 'message- id:@mail.gmail.com': 0.27; '[2]': 0.27; "skip:' 10": 0.28; 'classes': 0.30; 'probably': 0.31; '[1]': 0.32; 'problem': 0.33; 'url:python': 0.33; 'skip:_ 30': 0.33; 'lists': 0.34; 'received:google.com': 0.35; 'primarily': 0.35; 'but': 0.36; 'url:org': 0.36; 'possible.': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'one,': 0.37; 'end': 0.39; 'to:addr:python.org': 0.40; 'called': 0.40; 'bring': 0.62; 'header:Reply-To:1': 0.67; 'reply-to:no real name:2**0': 0.71; '3.6': 0.84; 'decorator,': 0.84; 'reply-to:addr:python.org': 0.84; 'worried': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:sender:in-reply-to:references:from:date :message-id:subject:to; bh=l+0H2dam67+Usi4qJAIwQgEOveledY/0TFA46SIkfqo=; b=jnIS2qSnhv7Y6Xd1NpT5o35CjfEmNU+vcroxBMpeK+R4aCGPkE5Qa5ZtGrRiQTjBEE mjmreJUSolOOXiLNPkvrhXrVm7//0nw6HCV2nZQwNqv1sinEZ3+T4AoJTN9/aAan8kiH u/LF96HlWMHHtICHqhOrkObALHNIuO4LXels40TPS6rPVQzAU6Y6PYB+CYtVmC4kX9jY C4l3d6CJeWF7j3pGdvIyQowJlOcLtDQDu2qrfd6kmzfJ687M9oQ7de11pM0I8aGvWebd OEAtdbOx/mZmduzxHkLPwSuodLXZMD7OFpGjpsYpWvLMSu4dzicbWfJHYgKNufLuudae tItg==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:reply-to:sender:in-reply-to :references:from:date:message-id:subject:to; bh=l+0H2dam67+Usi4qJAIwQgEOveledY/0TFA46SIkfqo=; b=AzwyrFH71/boF0PAhb11I1/NN8HcJ6ncfW49iUccKhKa1giAaecwKlQGPOeSZ6V2Ns Awt40AJaus0V22IBfUPMJjJBJ/kAXXocfya98f37JG+fg4Vzo1lDTbm4PkW1KeJCjlK9 xdsqS6z7THrAa9i4R3DtNoc7Fw7TyeZlpCWBzAlTwB4iFCZuVl3HkCHsazBKqi30yAQS JIAWBJOPEsBiX8IHwwZmx1Zl1rqvfC15br6zWBe4iyQySy9Ayq8feGIWxyjZdRaTqo+E EPMoQ/YPw/tsNaGhy/niNftDrpeN3tdd2Nnmo9Pf6QGSxu/YNKUr/5Sed04hK0BlJgu6 iA2w==
X-Gm-Message-State ALyK8tKEO3vsRdKgUnLntBXQHBcqAzODUrKCOSdL5ak4wup7R7ukyldnh28v578+g0iwvsdnn+sc+LAv6M7dSA==
X-Received by 10.157.38.141 with SMTP id l13mr423478otb.193.1467088335348; Mon, 27 Jun 2016 21:32:15 -0700 (PDT)
In-Reply-To <CAPTjJmqLmg5tPhLnvpMOg_+NhYiNOZW_RG2yDbBiqD6MYqtxSg@mail.gmail.com>
X-Google-Sender-Auth kefyIeCkQ245Yg1fshryeA7DKoo
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 <CAKJDb-PTja9Wo6SdYGPvvxjDRDGiVWmkw-MhRC2ixNrZMB5Nxw@mail.gmail.com>
X-Mailman-Original-References <d5e97a5e-6f10-4e3f-ab24-113632f16f29@googlegroups.com> <CAPTjJmqLmg5tPhLnvpMOg_+NhYiNOZW_RG2yDbBiqD6MYqtxSg@mail.gmail.com>
Xref csiph.com comp.lang.python:110643

Show key headers only | View raw


On Mon, Jun 27, 2016 at 7:32 PM, Chris Angelico <rosuav@gmail.com> 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).

[0] https://pypi.python.org/pypi/atpublic
[1] https://bugs.python.org/issue26632
[2] https://bugs.python.org/issue26632#msg267305

--
Zach

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


Thread

#110609 
  #110611 
    #110613 
      #110614 
      #110637 
        #110639 
  #110622 
  #110624 
  #110631 
  #110632 
  #110633 
  #110635 
  #110643 
  #110711 

csiph-web