Bugs item #1687163, was opened at 2007-03-23 17:51 Message generated for change (Comment added) made by collinwinter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1687163&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Python Interpreter Core Group: Python 3000 >Status: Closed >Resolution: Fixed Priority: 5 Private: No Submitted By: Raymond Hettinger (rhettinger) Assigned to: Collin Winter (collinwinter) Summary: Inconsistent Exceptions for Readonly Attributes Initial Comment: Attempting assignment to a readonly attribute raises an Attribute error for pure Python attributes but raises a TypeError for C readonly attributes. I think the AttributeError is the correct exception. >>> class A(object): ... _x = [] ... ... @property ... def x(self): ... return self._x ... >>> a = A() >>> a.x = None Traceback (most recent call last): a.x = None AttributeError: can't set attribute >>> def f(): ... yield None >>> g = f() >>> g.gi_frame = None Traceback (most recent call last): g.gi_frame = None TypeError: readonly attribute ---------------------------------------------------------------------- >Comment By: Collin Winter (collinwinter) Date: 2007-03-28 17:45 Message: Logged In: YES user_id=1344176 Originator: NO Fixed in r54602. ---------------------------------------------------------------------- Comment By: Raymond Hettinger (rhettinger) Date: 2007-03-26 16:18 Message: Logged In: YES user_id=80475 Originator: YES Collin, would you please apply this to the Py3K code. ---------------------------------------------------------------------- Comment By: Raymond Hettinger (rhettinger) Date: 2007-03-23 19:52 Message: Logged In: YES user_id=80475 Originator: YES Here's the one line change: Index: Python/structmember.c =================================================================== --- Python/structmember.c (revision 54557) +++ Python/structmember.c (working copy) @@ -160,7 +160,7 @@ if ((l->flags & READONLY) || l->type == T_STRING) { - PyErr_SetString(PyExc_TypeError, "readonly attribute"); + PyErr_SetString(PyExc_AttributeError, "readonly attribute"); Four of the tests will need to be updated: test_csv test_descr test_generators test_os ---------------------------------------------------------------------- Comment By: Raymond Hettinger (rhettinger) Date: 2007-03-23 18:16 Message: Logged In: YES user_id=80475 Originator: YES Readonly methods throw an AttributeError, but readonly members (anything defined in PyMemberDef with an RO or READONLY flag) raise a TypeError. ---------------------------------------------------------------------- Comment By: Jack Diederich (jackdied) Date: 2007-03-23 18:12 Message: Logged In: YES user_id=591932 Originator: NO I think this has something peculiar to frames, for instance: Python 2.5 (r25:51908, Sep 25 2006, 17:50:07) [GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> f = 'asdf' >>> f.strip = 42 Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'str' object attribute 'strip' is read-only >>> ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1687163&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com