diff options
author | 2021-03-02 08:17:15 +0200 | |
---|---|---|
committer | 2021-03-02 08:17:15 +0200 | |
commit | fff0a53f1f5e1a087c05f5de9655fb8b90601a34 (patch) | |
tree | 538f4056b15fc62a599ae7bd29ffd8de1401df76 | |
parent | document branch (diff) | |
download | pypy-fff0a53f1f5e1a087c05f5de9655fb8b90601a34.tar.gz pypy-fff0a53f1f5e1a087c05f5de9655fb8b90601a34.tar.bz2 pypy-fff0a53f1f5e1a087c05f5de9655fb8b90601a34.zip |
fix structseq attribute setter error message
-rw-r--r-- | lib_pypy/_structseq.py | 7 | ||||
-rw-r--r-- | pypy/module/sys/test/test_sysmodule.py | 10 |
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: |