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


Groups > comp.lang.python > #18069

Re: confused about __new__

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!multikabel.net!newsfeed20.multikabel.net!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.026
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'interpreter': 0.05; 'disagree': 0.07; 'python': 0.08; 'sure,': 0.09; 'invoking': 0.16; 'singleton': 0.16; 'workaround': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; 'cc:no real name:2**0': 0.20; "haven't": 0.20; 'trying': 0.21; 'dec': 0.22; "doesn't": 0.22; 'header:In- Reply-To:1': 0.22; 'locking': 0.23; '\xa0if': 0.23; 'cc:2**0': 0.24; 'creating': 0.25; 'demonstrate': 0.25; 'guess': 0.26; 'classes': 0.26; 'message-id:@mail.gmail.com': 0.28; '27,': 0.29; 'cc:addr:python.org': 0.29; 'pm,': 0.29; 'class': 0.29; 'really,': 0.30; 'user.': 0.31; 'certainly': 0.32; 'pointing': 0.32; 'tue,': 0.32; "can't": 0.32; 'actually': 0.33; 'it.': 0.34; 'force': 0.34; 'richard': 0.34; 'received:74.125.82': 0.35; 'apply': 0.35; 'unless': 0.35; 'convenient': 0.37; 'received:74.125': 0.37; 'received:google.com': 0.37; 'think': 0.37; 'enough': 0.38; 'doing': 0.38; 'possible.': 0.39; 'should': 0.39; 'being': 0.39; "it's": 0.40; '2011': 0.61; 'ever': 0.65; 'protection': 0.67; 'doing.': 0.73; 'protecting': 0.73; 'claim': 0.76; 'messed': 0.84; 'to:addr:rich': 0.84; 'hostile': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=f78GBGgl2W/gg6iLlX+rf32oBfBagcVC8aoNbsNsSpQ=; b=cpGBsF+qFl65m/PYI4VwPKFRPHM760vhVe4H36Fct6haScqf30vA/TCx3+83rrK2Nh JF0xTpM7H/RBIFPzarDu/eFmODU9exsIXKu7sHJ65bnzRjwPXfXACJc+ugXd0jF9lqt0 Uem2CX/GhWhwsW2jUQpjqm8Q4B+FvtnLNs6TE=
MIME-Version 1.0
In-Reply-To <5wrKq.39032$mJ.10777@newsfe10.iad>
References <MPbKq.47607$cN1.25052@newsfe12.iad> <mailman.4125.1324964928.27778.python-list@python.org> <ErnKq.40489$2e7.4368@newsfe18.iad> <CALwzidm_jc883ShOSmRe7N+5mx6uyKp_eSGvGBJNQOFy46xozA@mail.gmail.com> <4EFA2B0E.2000506@noir.com> <mailman.4149.1325018086.27778.python-list@python.org> <5wrKq.39032$mJ.10777@newsfe10.iad>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Tue, 27 Dec 2011 15:43:29 -0700
Subject Re: confused about __new__
To K Richard Pixley <rich@noir.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4160.1325025847.27778.python-list@python.org> (permalink)
Lines 26
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1325025847 news.xs4all.nl 6867 [2001:888:2000:d::a6]:51324
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:18069

Show key headers only | View raw


On Tue, Dec 27, 2011 at 3:19 PM, K Richard Pixley <rich@noir.com> wrote:
> Are you trying to demonstrate that I haven't prevented you from
> instantiating Foo?  If so, then I will cede that point.  I certainly don't
> know enough about python internals just now to even claim to be capable of
> protecting a class from a hostile user.  My guess is that short of a
> privileged/unprivileged split, or castrating the interpreter and locking you
> into it, such a protection would not be possible.

Yes, that was the point.  I certainly don't think that anybody should
ever be creating class instances by directly invoking object.__new__
unless they really, really know what they are doing.  I was just
pointing out that I don't think it's actually possible to prevent
classes from being instantiated.

> My point was that I can indeed intercept common and convenient usage to
> create a lovely singleton semantic.  I can't force you to use it. (Nor do I
> have any motivation to so do.)

Sure, I don't disagree with that.  And the object.__new__ workaround
is a general point that doesn't apply only to singletons.  Any class
that customizes its instantiation process can be messed up by doing
that.

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


Thread

confused about __new__ "K. Richard Pixley" <rich@noir.com> - 2011-12-26 20:28 -0800
  Re: confused about __new__ Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-27 04:53 +0000
    Re: confused about __new__ K Richard Pixley <rich@noir.com> - 2011-12-26 21:27 -0800
  Re: confused about __new__ Fredrik Tolf <fredrik@dolda2000.com> - 2011-12-27 06:48 +0100
    Re: confused about __new__ K Richard Pixley <rich@noir.com> - 2011-12-27 09:41 -0800
      Re: confused about __new__ Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-27 11:28 -0700
      Re: confused about __new__ Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-27 13:34 -0700
        Re: confused about __new__ K Richard Pixley <rich@noir.com> - 2011-12-27 14:19 -0800
          Re: confused about __new__ Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-27 15:43 -0700
      Re: confused about __new__ K Richard Pixley <rich@noir.com> - 2011-12-27 12:31 -0800
  Re: confused about __new__ Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-27 00:28 -0700
  Re: confused about __new__ Lie Ryan <lie.1296@gmail.com> - 2011-12-27 18:47 +1100
  Re: confused about __new__ Fredrik Tolf <fredrik@dolda2000.com> - 2011-12-27 19:05 +0100

csiph-web