summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2024-11-28 16:35:48 (GMT)
committerGitHub <noreply@github.com>2024-11-28 16:35:48 (GMT)
commit20657fbdb14d50ca4ec115da0cbef155871d8d33 (patch)
treea96b23cc66683e5a5c8817e9017055d81eb8df5a /Lib/test
parent49fee592a4fad17781bb4a78f95085d6edbb24d5 (diff)
downloadcpython-20657fbdb14d50ca4ec115da0cbef155871d8d33.zip
cpython-20657fbdb14d50ca4ec115da0cbef155871d8d33.tar.gz
cpython-20657fbdb14d50ca4ec115da0cbef155871d8d33.tar.bz2
gh-127190: Fix local_setattro() error handling (#127366)
Don't make the assumption that the 'name' argument is a string. Use repr() to format the 'name' argument instead.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_threading_local.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_threading_local.py b/Lib/test/test_threading_local.py
index f0b829a..3a58afd 100644
--- a/Lib/test/test_threading_local.py
+++ b/Lib/test/test_threading_local.py
@@ -208,6 +208,21 @@ class BaseLocalTest:
_testcapi.join_temporary_c_thread()
+ @support.cpython_only
+ def test_error(self):
+ class Loop(self._local):
+ attr = 1
+
+ # Trick the "if name == '__dict__':" test of __setattr__()
+ # to always be true
+ class NameCompareTrue:
+ def __eq__(self, other):
+ return True
+
+ loop = Loop()
+ with self.assertRaisesRegex(AttributeError, 'Loop.*read-only'):
+ loop.__setattr__(NameCompareTrue(), 2)
+
class ThreadLocalTest(unittest.TestCase, BaseLocalTest):
_local = _thread._local