On Fri, Feb 11, 2022 at 08:00:54AM -0800, Christopher Barker wrote:

> 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?

There's dynamic attributes with __getattr__ and __getattribute__, and 
who knows what can be done with metaclass magic, but I'm impressed and 
kinda intimidated if they are what came to mind *before* objects without 
a dict :-)


> 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?"

If your class is experienced enough to have learned about classes and 
properties, they will surely guess some sort of exception will happen.


> 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.


-- 
Steve
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/47FMU4SUWVULMOBO7HRTXLUJE5LKQAIV/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to