Kaydet (Commit) ffae3067 authored tarafından Armin Rigo's avatar Armin Rigo

Sounds obvious, but I didn't even realize that you can put non-string

keys in type dictionaries without using this locals() hack.
üst 5cc774e2
...@@ -27,10 +27,9 @@ class Base(object): ...@@ -27,10 +27,9 @@ class Base(object):
class Base2(object): class Base2(object):
mykey = 'from Base2' mykey = 'from Base2'
class X(Base): # you can't add a non-string key to X.__dict__, but it can be
# you can't add a non-string key to X.__dict__, but it can be # there from the beginning :-)
# there from the beginning :-) X = type('X', (Base,), {MyKey(): 5})
locals()[MyKey()] = 5
print X.mykey print X.mykey
# I get a segfault, or a slightly wrong assertion error in a debug build. # I get a segfault, or a slightly wrong assertion error in a debug build.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment