changeset 47636:f6aea808b357 legacy-trunk

Sounds obvious, but I didn't even realize that you can put non-string keys in type dictionaries without using this locals() hack.
author Armin Rigo <arigo@tunes.org>
date Thu, 12 Jun 2008 09:50:58 +0000
parents b45a95390620
children 44019e37ac92
files Lib/test/crashers/loosing_mro_ref.py
diffstat 1 files changed, 3 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/Lib/test/crashers/loosing_mro_ref.py	Wed Jun 11 20:28:06 2008 +0000
+++ b/Lib/test/crashers/loosing_mro_ref.py	Thu Jun 12 09:50:58 2008 +0000
@@ -27,10 +27,9 @@
 class Base2(object):
     mykey = 'from Base2'
 
-class X(Base):
-    # you can't add a non-string key to X.__dict__, but it can be
-    # there from the beginning :-)
-    locals()[MyKey()] = 5
+# you can't add a non-string key to X.__dict__, but it can be
+# there from the beginning :-)
+X = type('X', (Base,), {MyKey(): 5})
 
 print X.mykey
 # I get a segfault, or a slightly wrong assertion error in a debug build.