[Python-checkins] CVS: python/dist/src/Objects descrobject.c,1.1.2.13,1.1.2.14
Tim Peters
tim@digicool.com
Mon, 9 Jul 2001 16:56:20 -0400
[Guido]
> ...
> Note that the presence of a __set__ method doesn't mean that the
> attribute can actually be assigned to: this is also used to make
> attributes deliberately read-only, by making the __set__ method always
> raise an exception. (Q: should it raise AttributeError or TypeError?
> Traditionally, this has raised TypeError!)
I always thought AttributeError was to an instance dict as NameError is to a
global dict: "ain't got no such name". So I vote for TypeError.
AttributeError is more appropriate when trying to fetch an attribute that
doesn't exist.
A twist: suppose Spam.i can only take on string values. Should
Spam.i = 42
then raise TypeError or AttributeError? Obviously TypeError. Trying to do
Spam.readonly = 12
is the same thing, in that Spam.readonly can only take on no new values
<wink>.