design question: no new attributes

Ben Finney bignose+hates-spam at benfinney.id.au
Mon Feb 26 18:57:13 EST 2007


"Alan Isaac" <aisaac at american.edu> writes:

> I have a class whose instances should only receive attribute
> assignments for attributes that were created at inititialization.
> If slots are not appropriate, what is the Pythonic design for this?

The Pythonic design is: don't expect to have such control over users
of your code. (I encountered this in trying to design an Enum class,
with enumeration members as attributes.)

Document, in the class doc string and anywhere else you feel
appropriate, the fact that attributes shouldn't be added, and let your
users deal with their own bugs if they ignore that.

-- 
 \            "No one ever went broke underestimating the taste of the |
  `\                            American public."  -- Henry L. Mencken |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list