Bug: GameObject setdefault() doesn't exist

Hello BlenderArtists.
I appeal to anyone who has experience with the concept for the KX_GameObject type.
As you know, the object properties are now dictionary properties, not object attributes, however the GameObject isn’t behaving exactly like a dictionary - you can’t use this example;


import bge

def my_test(cont):
    own = cont.owner
    
    test_dict = {}

    variable_1 = test_dict.setdefault('test_variable', 1)
    variable_2 = own.setdefault('test_variable', 1)


which is annoying. Is this a bug, or is there an intended reason?

It has get(): http://www.blender.org/documentation/blender_python_api_2_62_3/bge.types.html#bge.types.KX_GameObject.get

You can use ob.attrDict to get the attribute dictionary.
http://www.blender.org/documentation/blender_python_api_2_62_3/bge.types.html#bge.types.KX_GameObject.attrDict

Yes it has get, but not setdefault so you can’t set a value of a key if the key doesn’t exist, and setdefault is a standard dictionary method, so beleive it should be a part of objects methods

KX_GameObject behaves like a dictionary for attribute access, it doesn’t make it a dictionary. I assume getitem and setitem are simply an alias for ob.attrDict.getitem and ob.attrDict.setitem.

You should be able to use setdefault and all the other dictionary methods on ob.attrDict.

Just a test with 2.62:

attrDict does not contain the properties added via GUI.
Entries added to attrDict are available via getPropertyNames()