> I have to say I agree with Neil here. I was trying to think about what
> other reasons an attribute might be unsettable, and did not quickly come up
> with that list.
I'm curious what list you came up with if it excluded the three cases I
suggested (no __dict__, __slots__, property). What other cases are
there?
You're giving me far too much credit -- I hadn't thought about it that much but "no __dict__" was all I cam up with quickly -- and I had no idea what other possibilities there were. (Once I was reminded of__slots__)
> And after reading your list, I tried to imagine what I’d tell my beginning
> students !
Tell them in what context?
Have you already covered properties? If so, then it should be fairly
obvious what to tell them:
"Class, what do you think will happen if you have a property with no
setter and you try to set its value?"
That's the easy part -- we cover that when we cover properties -- this whole thing is not an issue when you are working with your own code that you just added a property to. This issue Neil brought up is that if teh cause is p the chain of superclasses somewhere, you don't get much help from the error message.
Telling newbies that that means that it's either a property with no setter, or am object without a __dict__, or one with __slots__ defined is not really very helpful.
> But if the error message is indeed unique then yes:
>
> "can't set property 'f'"
>
> Would be far more clear message.
As I said, I don't object to the change in wording if it is easy enough to implement.
I think we're all on the same page here.
-CHB
-- Christopher Barker, PhD (Chris)
Python Language Consulting
- Teaching
- Scientific Software Development
- Desktop GUI and Web Development
- wxPython, numpy, scipy, Cython