Detecting a new style class

Steve Holden sholden at holdenweb.com
Wed Apr 24 08:14:56 EDT 2002


"Graham Ashton" <gashton at cmedltd.com> wrote ...
> 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.
>

You could do worse than read Alex's conference paper from Python10:

    http://www.python10.org/p10-papers/13/index.htm

in which he shows how Borg came about, and how it can be carried forward
into the brave new world of type/class unification.

regards
 Steve
--

home: http://www.holdenweb.com/
Python Web Programming:
http://pydish.holdenweb.com/pwp/








More information about the Python-list mailing list