Dev:2.4/Source/Python/Method Deprecation

提供: wiki
< Dev:2.4‎ | Source‎ | Python
2018年6月29日 (金) 02:45時点におけるYamyam (トーク | 投稿記録)による版 (1版 をインポートしました)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先: 案内検索

Useful ideas.... I've started using this in the Ipo and Curve modules for changes to the API. I think it's a good idea to also use the BLENDER_VERSION (in BLE_blender.h) to be sure the code gets flagged for deletion after deprecation. For example:

/* #####DEPRECATED###### */

#if BLENDER_VERSION < 243
static PyObject *Ipo_getNcurves( BPy_Ipo * self )
{

#if BLENDER_VERSION < 241 static int depcount = 2;
  if ( depcount ) {       
    printf ("Ipo.getNcurves() is deprecated by the len() operator.\n");       
    printf ("   This method will be removed after version 2.40.\n");       
    depcount--; 
  }
 // body of function here

#else 
  return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
    "replaced by \"len(ipo)\"" );
#endif
}

When the function is called, a deprecation warning is printed (two times max) until version 2.41, when a NotImplemented exception is thrown. After version 2.43, a compile error occurs which forces us to remove the old code.

-- KenHughes - 08 Jul 2005