From 9d2270a979b3d3ce107a2ea830b6bf7beecb1fdc Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Fri, 20 Mar 2020 17:48:03 -0500 Subject: runtime: Improve error message when setting read-only property Formerly, if you wrote SPI.frequency = 0 you would get the sightly erroneous error message AttributeError: 'SPI' object has no attribute 'frequency' In this case, a better message would read AttributeError: 'SPI' object cannot assign attribute 'frequency' This new message will both be used in the case where the attribute doesn't exist at all (and the object has no dynamic attributes; most instances of built in types behave this way), or if the attribute exists but is read-only. --- py/runtime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'py') diff --git a/py/runtime.c b/py/runtime.c index c1c311ae4..59dcbc7a1 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -1172,7 +1172,7 @@ void mp_store_attr(mp_obj_t base, qstr attr, mp_obj_t value) { mp_raise_AttributeError(translate("no such attribute")); } else { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_AttributeError, - translate("'%s' object has no attribute '%q'"), + translate("'%s' object cannot assign attribute '%q'"), mp_obj_get_type_str(base), attr)); } } -- cgit v1.2.3