On Tue, Dec 27, 2011 at 3:19 PM, K Richard Pixley <r...@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. -- http://mail.python.org/mailman/listinfo/python-list