diff options
author | Benjamin Peterson <benjamin@python.org> | 2013-05-15 20:26:42 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2013-05-15 20:26:42 (GMT) |
commit | 312595ce3a75e91d53222e486dfdd6f3668422ca (patch) | |
tree | 6128e0533586fff8500ef53ed91232a43af8b7dc /Lib/test/test_super.py | |
parent | fe361dfab588b75b9714b31648b98b982e6d1eda (diff) | |
download | cpython-312595ce3a75e91d53222e486dfdd6f3668422ca.zip cpython-312595ce3a75e91d53222e486dfdd6f3668422ca.tar.gz cpython-312595ce3a75e91d53222e486dfdd6f3668422ca.tar.bz2 |
hide the __class__ closure from the class body (#12370)
Diffstat (limited to 'Lib/test/test_super.py')
-rw-r--r-- | Lib/test/test_super.py | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/Lib/test/test_super.py b/Lib/test/test_super.py index 1e272ee..d0ce40a 100644 --- a/Lib/test/test_super.py +++ b/Lib/test/test_super.py @@ -81,8 +81,7 @@ class TestSuper(unittest.TestCase): self.assertEqual(E().f(), 'AE') - @unittest.expectedFailure - def test___class___set(self): + def test_various___class___pathologies(self): # See issue #12370 class X(A): def f(self): @@ -91,6 +90,31 @@ class TestSuper(unittest.TestCase): x = X() self.assertEqual(x.f(), 'A') self.assertEqual(x.__class__, 413) + class X: + x = __class__ + def f(): + __class__ + self.assertIs(X.x, type(self)) + with self.assertRaises(NameError) as e: + exec("""class X: + __class__ + def f(): + __class__""", globals(), {}) + self.assertIs(type(e.exception), NameError) # Not UnboundLocalError + class X: + global __class__ + __class__ = 42 + def f(): + __class__ + self.assertEqual(globals()["__class__"], 42) + del globals()["__class__"] + self.assertNotIn("__class__", X.__dict__) + class X: + nonlocal __class__ + __class__ = 42 + def f(): + __class__ + self.assertEqual(__class__, 42) def test___class___instancemethod(self): # See issue #14857 |