Detecting a new style class

Graham Ashton gashton at cmedltd.com
Wed Apr 24 05:19:43 EDT 2002


On Tue, 2002-04-23 at 19:21, Aahz wrote:
> In article <mailman.1019552082.8541.python-list at python.org>,
> Graham Ashton  <gashton at cmedltd.com> wrote:
> >
> >>>> class A(AbstractSingleton, object):
> >...   pass
> 
> Maybe you should tell us a bit more about what you're trying to do so
> that you needn't rely on crufty internal stuff to get the correct result.

Okay, good point. I'm using the Alex's Borg pattern in place of a
singleton, as shared state will do quite nicely. I'm also trying to
protect myself from getting caught out by new style classes (in other
words it doesn't work -- in general -- for classes derived from, for
example, dict).

So, until I need singletons that support subclasses of dict in all their
glory, I decided to do the "simplest thing that will possibly work" and
raise an exception if I forgot about the limitation (hence the need to
detect whether it's been inherited by a new style class).

An alternative question would be -- does anybody know how to do the Borg
so that it works for new style classes?

P.S. Thanks to those who replied to my earlier posts -- both solutions
work nicely.

-- 
Graham Ashton






More information about the Python-list mailing list