aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib_pypy/_structseq.py7
-rw-r--r--pypy/module/sys/test/test_sysmodule.py10
2 files changed, 15 insertions, 2 deletions
diff --git a/lib_pypy/_structseq.py b/lib_pypy/_structseq.py
index 8ac47ddd84..3a817fef95 100644
--- a/lib_pypy/_structseq.py
+++ b/lib_pypy/_structseq.py
@@ -104,8 +104,11 @@ def structseq_reduce(self):
return type(self), (tuple(self), self.__dict__)
def structseq_setattr(self, attr, value):
- raise AttributeError("%r object has no attribute %r" % (
- self.__class__.__name__, attr))
+ if attr not in type(self).__dict__:
+ raise AttributeError("%r object has no attribute %r" % (
+ self.__class__.__name__, attr))
+ else:
+ raise TypeError("readonly attribute")
def structseq_repr(self):
fields = {}
diff --git a/pypy/module/sys/test/test_sysmodule.py b/pypy/module/sys/test/test_sysmodule.py
index cf0812ae93..2a8d70f710 100644
--- a/pypy/module/sys/test/test_sysmodule.py
+++ b/pypy/module/sys/test/test_sysmodule.py
@@ -141,6 +141,16 @@ class AppTestAppSysTests:
exc = raises(SystemExit, sys.exit, (1, 2, 3))
assert exc.value.code == (1, 2, 3)
+ def test_sys_flags(self):
+ import sys
+ # sanity check
+ assert sys.flags.optimize is not None
+ # make sure the flags are read-only
+ exc = raises(TypeError, 'sys.flags.optimize = 3')
+ assert 'readonly' in str(exc.value)
+ raises(AttributeError, 'sys.flags.not_a_sys_flag = 2')
+
+
class AppTestSysModulePortedFromCPython: