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


Groups > comp.lang.python > #84505

Re: __bases__ misleading error message

Path csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.009
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'subject:error': 0.03; 'interpreter': 0.05; 'attribute': 0.07; 'function,': 0.09; 'statements': 0.09; 'used.': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; 'jan': 0.12; 'itself.': 0.14; 'any.': 0.16; 'callable': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'func': 0.16; 'function"': 0.16; 'itself,': 0.16; 'objects.': 0.16; 'typeerror:': 0.16; "variable's": 0.16; 'wrote:': 0.18; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'error': 0.23; 'of.': 0.24; 'cc:2**0': 0.24; 'pass': 0.26; 'code:': 0.26; 'header:In-Reply-To:1': 0.27; 'record': 0.27; 'am,': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'along': 0.30; "i'm": 0.30; '"",': 0.31; '25,': 0.31; 'asks': 0.31; 'name;': 0.31; 'file': 0.32; 'class': 0.32; 'stuff': 0.32; '(most': 0.33; 'cases': 0.33; "can't": 0.35; 'knows': 0.35; 'something': 0.35; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'in.': 0.36; 'object,': 0.36; 'useful': 0.36; 'recent': 0.39; 'explain': 0.39; 'called': 0.40; 'how': 0.40; 'identify': 0.61; 'matter': 0.61; 'show': 0.63; 'name': 0.63; 'such': 0.63; 'more': 0.64; 'nobody': 0.68; 'to,': 0.72; 'hand': 0.80; 'as:': 0.81; '"not': 0.84; "'class'": 0.84; "'foo'": 0.84; '2015': 0.84; 'one;': 0.84; 'to:none': 0.92; 'hands': 0.96
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=5mvnfdi6pe22iGcrCuh98T1PUrdCIAgNJ78gg0CE0rY=; b=nfgtsHfLs7pkdfdLDP0/UAPcx/FRxbtv/BKjsccff9Od8a9fPiJLaFKUp94QOSP2Yh rngZnI+lquP3Np4wH0H1OiBr9WlezHczgYMy34lKh9QvJHIMTuGNdfsmvwpGmY+tdrUi 8oYbfZEf3NaBqsEScZeFNMifsLfySTuKt2elYUKvyvGv4VGbcGy/xtTKaSOdDZtWEsSv +96CteNJsozdDAPvT1gqSQmjF+Kpa9ByT19nZqbizr2CAqeCz76rRR2esSY7iQZ8Q+6O vU54dr3MYjJR6DDhRbmBVY8WEBcARS0zlj0C+XTQF7yaoP1TK+iJGABoig8v2paSBKoc tg3A==
MIME-Version 1.0
X-Received by 10.140.90.112 with SMTP id w103mr26252432qgd.65.1422138352010; Sat, 24 Jan 2015 14:25:52 -0800 (PST)
In-Reply-To <MPG.2f2e3651befa4c9989694@nntp.aioe.org>
References <1a194e0a0b738d205de54180fa7@nntp.aioe.org> <54c39366$0$13006$c3e8da3$5496439d@news.astraweb.com> <MPG.2f2e298c14dbed69989692@nntp.aioe.org> <mailman.18099.1422135976.18130.python-list@python.org> <MPG.2f2e3651befa4c9989694@nntp.aioe.org>
Date Sun, 25 Jan 2015 09:25:51 +1100
Subject Re: __bases__ misleading error message
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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>
Newsgroups comp.lang.python
Message-ID <mailman.18104.1422138354.18130.python-list@python.org> (permalink)
Lines 56
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1422138354 news.xs4all.nl 2852 [2001:888:2000:d::a6]:55555
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:84505

Show key headers only | View raw


On Sun, Jan 25, 2015 at 9:09 AM, Mario Figueiredo <marfig@gmail.com> wrote:
> Meaning the interpreter knows a variable's name. Which would allow it to
> produce an error message such as:
>
>     AttributeError: 'foo' object has no attribute '__bases__'
>
> For the following code:
>
>     class Sub:
>         pass
>
>     foo = Sub()
>     foo.__bases__

Let me explain by way of analogy. You have ten shoeboxes to store your
stuff in. I hand you a thing and say "Here, put this into shoebox #4".
Then someone else comes along and says, "I need the thing from shoebox
#4", so you give him that thing. Now, he hands that thing to someone
else and asks him which shoebox it came out of, just by looking at the
thing itself. How can he say? The thing doesn't have any way of
knowing what shoebox it came out of.

Python names reference objects. But once you get an object, there's no
way of knowing which name was used to get to it. There might be one
such name; there might be more than one; and there might not be any.
You can't identify an object by the name it's bound to, but you can
identify it by something that's always true of the object itself, like
its type.

There are a few cases where names are so useful that they get attached
to the objects themselves. The 'def' and 'class' statements create
objects and also record the names used. But you still can't identify
what name was used to reference something:

>>> def func(x): print("x = %s"%x)
...
>>> func(123)
x = 123
>>> show = func
>>> show(234)
x = 234
>>> func = "not a function"
>>> func(123)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'str' object is not callable
>>> show(123)
x = 123
>>> show
<function func at 0x7f36744a30d0>

No matter what name I use to reference the function, it's still called
"func". Nobody can ever know that I'm identifying it by the name
'show' now.

ChrisA

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


Thread

__bases__ misleading error message Mario Figueiredo <marfig@gmail.com> - 2015-01-24 10:16 +0000
  Re: __bases__ misleading error message Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-24 23:43 +1100
    Re: __bases__ misleading error message Mario Figueiredo <marfig@gmail.com> - 2015-01-24 22:14 +0100
      Re: __bases__ misleading error message Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-24 14:45 -0700
        Re: __bases__ misleading error message Mario Figueiredo <marfig@gmail.com> - 2015-01-24 23:09 +0100
          Re: __bases__ misleading error message Chris Angelico <rosuav@gmail.com> - 2015-01-25 09:25 +1100
            Re: __bases__ misleading error message Mario Figueiredo <marfig@gmail.com> - 2015-01-24 23:33 +0100
              Re: __bases__ misleading error message Chris Angelico <rosuav@gmail.com> - 2015-01-25 09:37 +1100
                Re: __bases__ misleading error message Mario Figueiredo <marfig@gmail.com> - 2015-01-24 23:59 +0100
      Re: __bases__ misleading error message Terry Reedy <tjreedy@udel.edu> - 2015-01-24 16:58 -0500
        Re: __bases__ misleading error message Mario Figueiredo <marfig@gmail.com> - 2015-01-24 23:02 +0100
          Re: __bases__ misleading error message Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-24 15:16 -0700
            Re: __bases__ misleading error message Mario Figueiredo <marfig@gmail.com> - 2015-01-24 23:36 +0100
      Re: __bases__ misleading error message Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-25 14:18 +1100
        Re: __bases__ misleading error message Mario Figueiredo <marfig@gmail.com> - 2015-01-25 12:07 +0100
          Re: __bases__ misleading error message Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-25 23:00 +1100
            Re: __bases__ misleading error message Mario Figueiredo <marfig@gmail.com> - 2015-01-25 13:49 +0100
              Re: __bases__ misleading error message Marko Rauhamaa <marko@pacujo.net> - 2015-01-25 14:53 +0200
            Re: __bases__ misleading error message Terry Reedy <tjreedy@udel.edu> - 2015-01-25 16:35 -0500
            Re: __bases__ misleading error message Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-25 19:21 -0700
    Re: __bases__ misleading error message Marco Buttu <marco.buttu@gmail.com> - 2015-01-24 23:09 +0100
    Re: __bases__ misleading error message Marco Buttu <marco.buttu@gmail.com> - 2015-01-24 15:12 +0100
  Re: __bases__ misleading error message Terry Reedy <tjreedy@udel.edu> - 2015-01-24 14:24 -0500
    Re: __bases__ misleading error message Mario Figueiredo <marfig@gmail.com> - 2015-01-24 22:03 +0100
    Re: __bases__ misleading error message Marco Buttu <marco.buttu@gmail.com> - 2015-01-24 22:51 +0100
      Re: __bases__ misleading error message Terry Reedy <tjreedy@udel.edu> - 2015-01-24 19:55 -0500
        Re: __bases__ misleading error message Marco Buttu <marco.buttu@gmail.com> - 2015-01-25 11:30 +0100
    Re: __bases__ misleading error message Marco Buttu <marco.buttu@gmail.com> - 2015-01-24 22:51 +0100

csiph-web