[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22768] branches/blender2.5/blender/source /gameengine: remove gameOb.has_key(key) method from KX_GameObject and ListValue since python 3. x removes has_key from dictionaries.

Campbell Barton ideasman42 at gmail.com
Tue Aug 25 15:54:56 CEST 2009


Revision: 22768
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22768
Author:   campbellbarton
Date:     2009-08-25 15:54:56 +0200 (Tue, 25 Aug 2009)

Log Message:
-----------
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.

Modified Paths:
--------------
    branches/blender2.5/blender/source/gameengine/Expressions/ListValue.cpp
    branches/blender2.5/blender/source/gameengine/Expressions/ListValue.h
    branches/blender2.5/blender/source/gameengine/Ketsji/KX_GameObject.cpp
    branches/blender2.5/blender/source/gameengine/Ketsji/KX_GameObject.h
    branches/blender2.5/blender/source/gameengine/Ketsji/KX_PyMath.cpp
    branches/blender2.5/blender/source/gameengine/PyDoc/GameTypes.py

Modified: branches/blender2.5/blender/source/gameengine/Expressions/ListValue.cpp
===================================================================
--- branches/blender2.5/blender/source/gameengine/Expressions/ListValue.cpp	2009-08-25 13:43:21 UTC (rev 22767)
+++ branches/blender2.5/blender/source/gameengine/Expressions/ListValue.cpp	2009-08-25 13:54:56 UTC (rev 22768)
@@ -300,7 +300,6 @@
 	
 	/* 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 @@
 	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)
 {

Modified: branches/blender2.5/blender/source/gameengine/Expressions/ListValue.h
===================================================================
--- branches/blender2.5/blender/source/gameengine/Expressions/ListValue.h	2009-08-25 13:43:21 UTC (rev 22767)
+++ branches/blender2.5/blender/source/gameengine/Expressions/ListValue.h	2009-08-25 13:54:56 UTC (rev 22768)
@@ -74,7 +74,6 @@
 	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);
 
 	

Modified: branches/blender2.5/blender/source/gameengine/Ketsji/KX_GameObject.cpp
===================================================================
--- branches/blender2.5/blender/source/gameengine/Ketsji/KX_GameObject.cpp	2009-08-25 13:43:21 UTC (rev 22767)
+++ branches/blender2.5/blender/source/gameengine/Ketsji/KX_GameObject.cpp	2009-08-25 13:54:56 UTC (rev 22768)
@@ -1398,7 +1398,6 @@
 	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 @@
 	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
  * --------------------------------------------------------------------- */

Modified: branches/blender2.5/blender/source/gameengine/Ketsji/KX_GameObject.h
===================================================================
--- branches/blender2.5/blender/source/gameengine/Ketsji/KX_GameObject.h	2009-08-25 13:43:21 UTC (rev 22767)
+++ branches/blender2.5/blender/source/gameengine/Ketsji/KX_GameObject.h	2009-08-25 13:54:56 UTC (rev 22768)
@@ -844,7 +844,6 @@
 	
 	/* 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);

Modified: branches/blender2.5/blender/source/gameengine/Ketsji/KX_PyMath.cpp
===================================================================
--- branches/blender2.5/blender/source/gameengine/Ketsji/KX_PyMath.cpp	2009-08-25 13:43:21 UTC (rev 22767)
+++ branches/blender2.5/blender/source/gameengine/Ketsji/KX_PyMath.cpp	2009-08-25 13:54:56 UTC (rev 22768)
@@ -146,7 +146,7 @@
 {
 	/* 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 @@
 {
 #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 @@
 {
 #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 @@
 {
 #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]));

Modified: branches/blender2.5/blender/source/gameengine/PyDoc/GameTypes.py
===================================================================
--- branches/blender2.5/blender/source/gameengine/PyDoc/GameTypes.py	2009-08-25 13:43:21 UTC (rev 22767)
+++ branches/blender2.5/blender/source/gameengine/PyDoc/GameTypes.py	2009-08-25 13:54:56 UTC (rev 22768)
@@ -1023,12 +1023,6 @@
 		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 @@
 	@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 @@
 		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 @@
 			
 			# 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 @@
 					# 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





More information about the Bf-blender-cvs mailing list