predicate classes

Neel Krishnaswami neelk at brick.cswv.com
Wed Dec 1 18:08:28 EST 1999


Mark C Favas <mark at chem.uwa.edu.au> wrote:
>neelk at brick.cswv.com (Neel Krishnaswami) writes:
>
>>Here's a quick, rather kludged-together example:
>
> [...]
>
>Ummm, not for me - with 1.5.2 from CVS I get: [...]

Er, it looks like I made a booboo. Try this instead;

  class Foo:
      x = 4
  
  class Bar:
      def __init__(self):
  	  self.__class__.predicate = 1
  	  self.__class__.__bases__ = (Foo,)
      def __setattr__(self, name, value):
  	  if name == 'predicate':
  	      self.__class__.predicate = value
  	      if value:
  		  self.__class__.__bases__ = (Foo,)
  	      else:
  		  self.__class__.__bases__ = ()

This works in my 1.5.2. The error appears to be that when __bases__ is
defined as a class initialization statement it gets stuffed into the
class __dict__ without updating the __bases__ attribute. (At least
that's what a cursory examination of classobject.c suggests.)  Funky.


Neel




More information about the Python-list mailing list