
This error message is the same for types with __slots__, and probably it is indeed a bit too terse. -- Ivan On 27 July 2017 at 18:26, Chris Barker <chris.barker@noaa.gov> wrote:
Since we are talking about namedtuple and implementation, I just noticed:
In [22]: Point = namedtuple('Point', ['x', 'y']) In [23]: p = Point(2,3)
In [24]: p.x = 5 ------------------------------------------------------------ --------------- AttributeError Traceback (most recent call last) <ipython-input-24-328d3fab3e30> in <module>() ----> 1 p.x = 5 AttributeError: can't set attribute
OK -- that makes sense. but then, if you try:
In [25]: p.z = 5 ------------------------------------------------------------ --------------- AttributeError Traceback (most recent call last) <ipython-input-25-625ed954d865> in <module>() ----> 1 p.z = 5 AttributeError: 'Point' object has no attribute 'z'
I think this should be a different message -- key here is that you can't set a new attribute, not that one doesn't exist. Maybe:
"AttributeError: can't set new attribute"
-CHB
--
Christopher Barker, Ph.D. Oceanographer
Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/