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

keys in type dictionaries without using this locals() hack.
This commit is contained in:
Armin Rigo 2008-06-12 09:50:58 +00:00
parent 5cc774e232
commit ffae306784
1 changed files with 3 additions and 4 deletions

View 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.