remove gameOb.has_key(key) method from KX_GameObject and ListValue since python 3.x removes has_key from dictionaries.

Instead use __contains__, eg.
 if key in gameOb: ...
 
Mathutils returns from PyMath.cpp were incorrectly using wrapped Mathutils types. Wrapped types should only be used with a callback now.
This commit is contained in:
Campbell Barton 2009-08-25 13:54:56 +00:00
parent 855974dad9
commit 9521fa9456
6 changed files with 7 additions and 39 deletions

@ -300,7 +300,6 @@ PyMethodDef CListValue::Methods[] = {
/* Dict style access */
{"get", (PyCFunction)CListValue::sPyget,METH_VARARGS},
{"has_key", (PyCFunction)CListValue::sPyhas_key,METH_O},
/* Own cvalue funcs */
{"from_id", (PyCFunction)CListValue::sPyfrom_id,METH_O},
@ -594,14 +593,6 @@ PyObject* CListValue::Pyget(PyObject *args)
return def;
}
/* Matches python dict.has_key() */
PyObject* CListValue::Pyhas_key(PyObject* value)
{
if (PyUnicode_Check(value) && FindValue((const char *)_PyUnicode_AsString(value)))
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
PyObject* CListValue::Pyfrom_id(PyObject* value)
{

@ -74,7 +74,6 @@ public:
KX_PYMETHOD_O(CListValue,index);
KX_PYMETHOD_O(CListValue,count);
KX_PYMETHOD_VARARGS(CListValue,get);
KX_PYMETHOD_O(CListValue,has_key);
KX_PYMETHOD_O(CListValue,from_id);

@ -1398,7 +1398,6 @@ PyMethodDef KX_GameObject::Methods[] = {
KX_PYMETHODTABLE(KX_GameObject, sendMessage),
// dict style access for props
{"has_key",(PyCFunction) KX_GameObject::sPyhas_key, METH_O},
{"get",(PyCFunction) KX_GameObject::sPyget, METH_VARARGS},
// deprecated
@ -2919,14 +2918,6 @@ PyObject* KX_GameObject::Pyget(PyObject *args)
return def;
}
/* Matches python dict.has_key() */
PyObject* KX_GameObject::Pyhas_key(PyObject* value)
{
// the ONLY error case is invalid data, this is checked by the macro'd static function
// that calls this one. but make sure Seq_Contains doesnt add extra errors later on.
return PyBool_FromLong(Seq_Contains((PyObject *)this, value));
}
/* ---------------------------------------------------------------------
* Some stuff taken from the header
* --------------------------------------------------------------------- */

@ -844,7 +844,6 @@ public:
/* Dict access */
KX_PYMETHOD_VARARGS(KX_GameObject,get);
KX_PYMETHOD_O(KX_GameObject,has_key);
/* attributes */
static PyObject* pyattr_get_name(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);

@ -146,7 +146,7 @@ PyObject* PyObjectFrom(const MT_Quaternion &qrot)
{
/* NOTE, were re-ordering here for Mathutils compat */
float fvec[4]= {qrot[3], qrot[0], qrot[1], qrot[2]};
return newQuaternionObject(fvec, Py_WRAP, NULL);
return newQuaternionObject(fvec, Py_NEW, NULL);
}
#endif
@ -154,7 +154,7 @@ PyObject* PyObjectFrom(const MT_Tuple4 &vec)
{
#ifdef USE_MATHUTILS
float fvec[4]= {vec[0], vec[1], vec[2], vec[3]};
return newVectorObject(fvec, 4, Py_WRAP, NULL);
return newVectorObject(fvec, 4, Py_NEW, NULL);
#else
PyObject *list = PyList_New(4);
PyList_SET_ITEM(list, 0, PyFloat_FromDouble(vec[0]));
@ -169,7 +169,7 @@ PyObject* PyObjectFrom(const MT_Tuple3 &vec)
{
#ifdef USE_MATHUTILS
float fvec[3]= {vec[0], vec[1], vec[2]};
return newVectorObject(fvec, 3, Py_WRAP, NULL);
return newVectorObject(fvec, 3, Py_NEW, NULL);
#else
PyObject *list = PyList_New(3);
PyList_SET_ITEM(list, 0, PyFloat_FromDouble(vec[0]));
@ -183,7 +183,7 @@ PyObject* PyObjectFrom(const MT_Tuple2 &vec)
{
#ifdef USE_MATHUTILS
float fvec[2]= {vec[0], vec[1]};
return newVectorObject(fvec, 2, Py_WRAP, NULL);
return newVectorObject(fvec, 2, Py_NEW, NULL);
#else
PyObject *list = PyList_New(2);
PyList_SET_ITEM(list, 0, PyFloat_FromDouble(vec[0]));

@ -1023,12 +1023,6 @@ class CListValue(CPropValue):
Return the value matching key, or the default value if its not found.
@return: The key value or a default.
"""
def has_key(key):
"""
Return True if the key is found.
@rtype: boolean
@return: The key value or a default.
"""
def from_id(id):
"""
This is a funtion especially for the game engine to return a value with a spesific id.
@ -1582,7 +1576,7 @@ class KX_GameObject(SCA_IObject):
@ivar childrenRecursive: all children of this object including childrens children, (read-only).
@type childrenRecursive: L{CListValue} of L{KX_GameObject}'s
@group Deprecated: getPosition, setPosition, setWorldPosition, getOrientation, setOrientation, getState, setState, getParent, getVisible, getMass, getMesh, getChildren, getChildrenRecursive
@group Property Access: get, has_key, attrDict, getPropertyNames
@group Property Access: get, attrDict, getPropertyNames
"""
def endObject():
"""
@ -2054,12 +2048,6 @@ class KX_GameObject(SCA_IObject):
Return the value matching key, or the default value if its not found.
@return: The key value or a default.
"""
def has_key(key):
"""
Return True if the key is found.
@rtype: boolean
@return: The key value or a default.
"""
class KX_IpoActuator(SCA_IActuator):
@ -5745,7 +5733,7 @@ for name, val in locals().items():
# Store the mappings to new attributes in a list (because there
# could be collisions).
if not depAttrs.has_key(attrName):
if attrName not in depAttrs:
depAttrs[attrName] = {}
mapping = depAttrs[attrName]
@ -5770,7 +5758,7 @@ for name, val in locals().items():
# Another mapping, from a conversion tuple to lists of class
# names.
conversion = (func, newAttrName)
if not mapping.has_key(conversion):
if conversion not in mapping:
mapping[conversion] = []
mapping[conversion].append(name)
break