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


Groups > comp.lang.python > #18069

Re: confused about __new__

References (2 earlier) <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 2011-12-27 15:43 -0700
Subject Re: confused about __new__
Newsgroups comp.lang.python
Message-ID <mailman.4160.1325025847.27778.python-list@python.org> (permalink)

Show all headers | 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