summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-07-18 21:37:43 (GMT)
committerGitHub <noreply@github.com>2020-07-18 21:37:43 (GMT)
commit38d930f2ccbff6f93c4c54a7a6a1759266136504 (patch)
tree5480be9034b0bccf541d077b8979fb022bacaefc /Lib
parent668d321476d974c4f51476b33aaca870272523bf (diff)
downloadcpython-38d930f2ccbff6f93c4c54a7a6a1759266136504.zip
cpython-38d930f2ccbff6f93c4c54a7a6a1759266136504.tar.gz
cpython-38d930f2ccbff6f93c4c54a7a6a1759266136504.tar.bz2
bpo-41295: Reimplement the Carlo Verre "hackcheck" (GH-21528)
Walk down the MRO backwards to find the type that originally defined the final `tp_setattro`, then make sure we are not jumping over intermediate C-level bases with the Python-level call. Automerge-Triggered-By: @gvanrossum (cherry picked from commit c53b310e5926266ce267c44a168165cacd786d6e) Co-authored-by: scoder <stefan_ml@behnel.de>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_descr.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index c4d900a..18397a8 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -4315,6 +4315,42 @@ order (MRO) for bases """
else:
self.fail("Carlo Verre __delattr__ succeeded!")
+ def test_carloverre_multi_inherit_valid(self):
+ class A(type):
+ def __setattr__(cls, key, value):
+ type.__setattr__(cls, key, value)
+
+ class B:
+ pass
+
+ class C(B, A):
+ pass
+
+ obj = C('D', (object,), {})
+ try:
+ obj.test = True
+ except TypeError:
+ self.fail("setattr through direct base types should be legal")
+
+ def test_carloverre_multi_inherit_invalid(self):
+ class A(type):
+ def __setattr__(cls, key, value):
+ object.__setattr__(cls, key, value) # this should fail!
+
+ class B:
+ pass
+
+ class C(B, A):
+ pass
+
+ obj = C('D', (object,), {})
+ try:
+ obj.test = True
+ except TypeError:
+ pass
+ else:
+ self.fail("setattr through indirect base types should be rejected")
+
def test_weakref_segfault(self):
# Testing weakref segfault...
# SF 742911