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


Groups > comp.lang.python > #110614

Re: __all__ attribute: bug and proposal

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: __all__ attribute: bug and proposal
Date Tue, 28 Jun 2016 08:41:16 +1000
Lines 43
Message-ID <mailman.45.1467067285.2358.python-list@python.org> (permalink)
References <d5e97a5e-6f10-4e3f-ab24-113632f16f29@googlegroups.com> <CAPTjJmoyWedd6oFURX+URsxEo6hCcnGGxBs3DTDUnODrxWgzJQ@mail.gmail.com> <mailman.44.1467063171.2358.python-list@python.org> <c0d61bbb-1e76-42af-88d3-3c64224b4a3f@googlegroups.com> <CAPTjJmq=N2tGPTU6rDcNcY7HJPvPqWRApg4kEr_+NSGvz2sFpQ@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de us8b+9jK1Ul1LyaNEfUPGgvXpDE+1z9l0eBSwGkLnX9Q==
Return-Path <rosuav@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; 'subject:bug': 0.05; 'objects,': 0.07; 'cc:addr:python-list': 0.09; '__all__': 0.09; 'integers': 0.09; 'pavel': 0.09; 'types:': 0.09; 'x),': 0.09; 'def': 0.13; 'importing': 0.15; '2016': 0.16; 'enough.': 0.16; 'example?': 0.16; 'false:': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'sure.': 0.16; 'vary.': 0.16; 'wrote:': 0.16; 'attribute': 0.18; "shouldn't": 0.18; '>>>': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; '"",': 0.22; 'names.': 0.22; 'am,': 0.23; 'import': 0.24; '(most': 0.24; 'header:In-Reply-To:1': 0.24; 'module': 0.25; 'message- id:@mail.gmail.com': 0.27; 'traceback': 0.33; "i'll": 0.33; "skip:' 20": 0.34; 'tue,': 0.34; 'file': 0.34; 'received:google.com': 0.35; 'so,': 0.35; 'skip:c 30': 0.35; 'text': 0.35; 'unit': 0.35; 'but': 0.36; 'too': 0.36; 'should': 0.36; 'skip:{ 10': 0.36; 'subject:: ': 0.37; 'names': 0.38; 'skip:o 20': 0.38; 'test': 0.39; 'provide': 0.61; 'matter': 0.63; 'wall': 0.63; 'results': 0.66; '(your': 0.84; 'chrisa': 0.84; 'to:none': 0.91; 'canonical': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:cc; bh=PiB6PyYWNCO8fVKX6bZUVP5h4uBpT0uvLhoa4FFEMR0=; b=Wp7iK6lctoCqBDfPEH/LMVWdKNTWRwAwxqiBVkOGCB+dZB+vu76uOh1ajYnjSvk6ZQ qY5NpIClQ0KK2XTFwhW00zkRCKsakv133G3BneM3Sn+m2EdhkY49Bj7a8VfpVRg+3gBR +FKhRpjrU/ECCDkHU8ADXQXOoRfX4Hm9WgJT9S/06gbQDhFwwKsWPNpMVhI3gSFcbHmh ja3vlEifpBHWcymy2r6mTQkVMh3RDJ+6hb+mglBqnLRivUKCTpCCodlpw6qbfUw0G8UP ye0O3uj4RkI3541Azvj0iFVJ7BGejhAUJWt03zbnFzp00V2f9TgT8A54linRd6vfMqab EBnA==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:cc; bh=PiB6PyYWNCO8fVKX6bZUVP5h4uBpT0uvLhoa4FFEMR0=; b=hKXmNAokWClvqHpT4FhPa6z3g5WoeXxeohTOOPzYADkIbIoOZGA6e4+4X5l6kxqbvd LKz29IpMEwAq43baekXDlUWmtMJDU7uMYmhQRhZ/JQGQW5IdEuinuWUuCRZyCf8/u68M qDhPWr3IaWGZFvaz0IiR2Debz+61sQNaLD6w6EOyOwPd3uVQ0P7T3YaNDGWuM8WlZfsR s5Ec7ARfctO+ZmQpOk9Y3k6xwR4qxSy/FjuHFoPdeZUB94EDDPDQm9K2HY86rjdj97ZO KIDAZZXQjqi8+bRcas/wBmON7OpPjorH4hLx1GpjurqQJaOmYnGsrpVbCUxQhRp9/mY1 VX4g==
X-Gm-Message-State ALyK8tLduaEmF1b3VNc8aUC1C9+KIZ+FQu1yHQqC1dNdep3Wl+/hPEUzGPq1uDAwtM/1WrD0HWB3ahBXC53zhQ==
X-Received by 10.194.70.41 with SMTP id j9mr2895801wju.30.1467067277307; Mon, 27 Jun 2016 15:41:17 -0700 (PDT)
In-Reply-To <c0d61bbb-1e76-42af-88d3-3c64224b4a3f@googlegroups.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 <CAPTjJmq=N2tGPTU6rDcNcY7HJPvPqWRApg4kEr_+NSGvz2sFpQ@mail.gmail.com>
X-Mailman-Original-References <d5e97a5e-6f10-4e3f-ab24-113632f16f29@googlegroups.com> <CAPTjJmoyWedd6oFURX+URsxEo6hCcnGGxBs3DTDUnODrxWgzJQ@mail.gmail.com> <mailman.44.1467063171.2358.python-list@python.org> <c0d61bbb-1e76-42af-88d3-3c64224b4a3f@googlegroups.com>
Xref csiph.com comp.lang.python:110614

Show key headers only | View raw


On Tue, Jun 28, 2016 at 8:29 AM, Pavel S <pavel@schon.cz> wrote:
>> but what about integers or strings?
>
> Can you provide example?

Sure. I'll spare you the wall of text that is os.__all__, but here's the types:

>>> import os
>>> {type(getattr(os, x)).__name__ for x in os.__all__}
{'bool', 'module', 'function', 'str', '_Environ', 'NoneType', 'type',
'int', 'dict', 'builtin_function_or_method'}
>>> collections.Counter(hasattr(getattr(os, x), "__name__") for x in os.__all__)
Counter({True: 184, False: 122})

So, roughly 60% of them even have canonical names. And you don't
always want the canonical name, anyway:

>>> os.path.__name__
'posixpath'

(Your results may vary. Specifically. os.path.__name__ will be
'ntpath' if you're on Windows.)

> No matter if __all__ uses names or objects, I think it should be validated not only when importing '*', but always.
>
> Frankly, do you always unit-test if __all__ works?

Frankly, I don't unit test enough. But if you have __all__, it
shouldn't be too hard, nor too unobvious, to test it.

>>> def test_all():
...   exec("from os import *")
...
>>> test_all()
>>> os.__all__.append("asdf")
>>> test_all()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in test_all
  File "<string>", line 1, in <module>
AttributeError: module 'os' has no attribute 'asdf'

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next 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