mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
use a invalid name for the __class__ closure for super() (closes #12370)
This prevents the assignment of __class__ in the class body from breaking super. (Although a determined person could do locals()["@__class__"] = 4)
This commit is contained in:
parent
019d0f27a3
commit
f5ff22329b
5 changed files with 26 additions and 10 deletions
|
|
@ -81,6 +81,16 @@ class TestSuper(unittest.TestCase):
|
|||
|
||||
self.assertEqual(E().f(), 'AE')
|
||||
|
||||
def test___class___set(self):
|
||||
# See issue #12370
|
||||
class X(A):
|
||||
def f(self):
|
||||
return super().f()
|
||||
__class__ = 413
|
||||
x = X()
|
||||
self.assertEqual(x.f(), 'A')
|
||||
self.assertEqual(x.__class__, 413)
|
||||
|
||||
|
||||
def test_main():
|
||||
support.run_unittest(TestSuper)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue