mirror of
https://github.com/python/cpython.git
synced 2024-11-25 10:54:51 +08:00
Make readonly members defined in C throw an AttributeError on modification. This brings them into sync with Python-level attributes. Fixes bug #1687163.
This commit is contained in:
parent
d84da1b67a
commit
42dae6a89b
@ -53,8 +53,8 @@ class Test_Csv(unittest.TestCase):
|
||||
self.assertEqual(obj.dialect.skipinitialspace, False)
|
||||
self.assertEqual(obj.dialect.strict, False)
|
||||
# Try deleting or changing attributes (they are read-only)
|
||||
self.assertRaises(TypeError, delattr, obj.dialect, 'delimiter')
|
||||
self.assertRaises(TypeError, setattr, obj.dialect, 'delimiter', ':')
|
||||
self.assertRaises(AttributeError, delattr, obj.dialect, 'delimiter')
|
||||
self.assertRaises(AttributeError, setattr, obj.dialect, 'delimiter', ':')
|
||||
self.assertRaises(AttributeError, delattr, obj.dialect, 'quoting')
|
||||
self.assertRaises(AttributeError, setattr, obj.dialect,
|
||||
'quoting', None)
|
||||
|
@ -1857,13 +1857,13 @@ def properties():
|
||||
for attr in "__doc__", "fget", "fset", "fdel":
|
||||
try:
|
||||
setattr(raw, attr, 42)
|
||||
except TypeError as msg:
|
||||
except AttributeError as msg:
|
||||
if str(msg).find('readonly') < 0:
|
||||
raise TestFailed("when setting readonly attr %r on a "
|
||||
"property, got unexpected TypeError "
|
||||
"property, got unexpected AttributeError "
|
||||
"msg %r" % (attr, str(msg)))
|
||||
else:
|
||||
raise TestFailed("expected TypeError from trying to set "
|
||||
raise TestFailed("expected AttributeError from trying to set "
|
||||
"readonly %r attr on a property" % attr)
|
||||
|
||||
class D(object):
|
||||
|
@ -400,7 +400,7 @@ And more, added later.
|
||||
>>> i.gi_running = 42
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
TypeError: readonly attribute
|
||||
AttributeError: readonly attribute
|
||||
>>> def g():
|
||||
... yield me.gi_running
|
||||
>>> me = g()
|
||||
|
@ -143,7 +143,7 @@ class StatAttributeTests(unittest.TestCase):
|
||||
try:
|
||||
result.st_mode = 1
|
||||
self.fail("No exception thrown")
|
||||
except TypeError:
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
try:
|
||||
@ -201,7 +201,7 @@ class StatAttributeTests(unittest.TestCase):
|
||||
try:
|
||||
result.f_bfree = 1
|
||||
self.fail("No exception thrown")
|
||||
except TypeError:
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
try:
|
||||
|
@ -164,7 +164,7 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v)
|
||||
|
||||
if ((l->flags & READONLY) || l->type == T_STRING)
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "readonly attribute");
|
||||
PyErr_SetString(PyExc_AttributeError, "readonly attribute");
|
||||
return -1;
|
||||
}
|
||||
if ((l->flags & WRITE_RESTRICTED) && PyEval_GetRestricted()) {
|
||||
|
Loading…
Reference in New Issue
Block a user