]> granicus.if.org Git - python/commitdiff
Sounds obvious, but I didn't even realize that you can put non-string
authorArmin Rigo <arigo@tunes.org>
Thu, 12 Jun 2008 09:50:58 +0000 (09:50 +0000)
committerArmin Rigo <arigo@tunes.org>
Thu, 12 Jun 2008 09:50:58 +0000 (09:50 +0000)
keys in type dictionaries without using this locals() hack.

Lib/test/crashers/loosing_mro_ref.py

index f0b8047d8d1972f0514fad39bbab75fbe2eda4eb..b5fa93b53d4b9ec907cb23b23aecfcd6d08da7cb 100644 (file)
@@ -27,10 +27,9 @@ class Base(object):
 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.