design question: no new attributes

Alan Isaac aisaac at american.edu
Tue Feb 27 20:48:47 EST 2007


OK, let me approach this from a new direction.
Suppose I define a class that behaves I think
as I stipulated::

class NothingNew:
    a = 0
    def __init__(self):
        self.b = 1
        self.initialized = True
    def __setattr__(self, attr, val):
        if not hasattr(self,'initialized') or hasattr(self, attr):
            self.__dict__[attr] = val
        else:
            raise ValueError

After adding some documentation,
what are the downsides?  (Assume a small
project where everyone knows this has been
done to the NothingNew class.) Anyone who wants the
behavior can keep it.  Anyone who wants to add
stuff to an object just has to delete its
"initialized" attribute.  Anyone who want other
behavior defined in this or a derived class can
just override __init__.  Does this address most
of the (oddly passionate) objections?

Thanks,
Alan Isaac





More information about the Python-list mailing list