Hi Phil, this patch to SIP adds a "/Deprecated/" annotation that can be used to mark functions that are deprecated. It causes a DeprecationWarning to be raised at runtime whenever the function is invoked.
Once a package correctly uses /Deprecated/, the users of the package can disable the warning (if they find it annoying) using the standard Python warning filter machinery (eg: it allows to disable warnings by matching the module name with a regexp). So I don't see a need to provide an alternative way to compile it on/off (eg: as SIP command line argument), nor at runtime. This will be used by an upcoming PyQt3Support release that will mark all PyQt3 classes and methods as deprecated, to allow developers to quickly identify spots where Qt3Support is still in use. The patch has been written by Lorenzo Berni (I'm submitting it on his behalf). -- Giovanni Bajo Develer S.r.l. http://www.develer.com
diff -ur sip-4.7.7/sipgen/gencode.c PyQt3Support/sip-4.7.7/sipgen/gencode.c --- sip-4.7.7/sipgen/gencode.c 2008-08-08 16:07:36.000000000 +0200 +++ PyQt3Support/sip-4.7.7/sipgen/gencode.c 2008-08-29 14:28:44.000000000 +0200 @@ -8813,6 +8813,9 @@ ); } + if (isDeprecatedCtor(ct)) + prcode(fp, " PyErr_WarnEx(PyExc_DeprecationWarning, \"Deprecated function or method used\", 1);\n"); + gc_ellipsis(&ct->pysig, fp); deleteTemps(&ct->pysig, fp); @@ -9078,6 +9081,9 @@ has_owner = TRUE; } + if (isDeprecated(od)) + prcode(fp, " PyErr_WarnEx(PyExc_DeprecationWarning, \"Deprecated function or method used\", 1);\n\n"); + /* Handle the trivial case. */ if (nrvals == 0) { diff -ur sip-4.7.7/sipgen/parser.c PyQt3Support/sip-4.7.7/sipgen/parser.c --- sip-4.7.7/sipgen/parser.c 2008-08-08 16:07:38.000000000 +0200 +++ PyQt3Support/sip-4.7.7/sipgen/parser.c 2008-08-29 14:31:45.000000000 +0200 @@ -6953,6 +6953,9 @@ getHooks(optflgs,&ct -> prehook,&ct -> posthook); + if (findOptFlag(optflgs, "Deprecated", bool_flag) != NULL) + setIsDeprecatedCtor(ct); + if (getReleaseGIL(optflgs)) setIsReleaseGILCtor(ct); else if (getHoldGIL(optflgs)) @@ -7196,6 +7199,9 @@ setIsNewThread(od); } + if (findOptFlag(optflgs, "Deprecated", bool_flag) != NULL) + setIsDeprecated(od); + getHooks(optflgs,&od -> prehook,&od -> posthook); if (getReleaseGIL(optflgs)) diff -ur sip-4.7.7/sipgen/sip.h PyQt3Support/sip-4.7.7/sipgen/sip.h --- sip-4.7.7/sipgen/sip.h 2008-08-08 16:07:36.000000000 +0200 +++ PyQt3Support/sip-4.7.7/sipgen/sip.h 2008-08-29 14:35:06.000000000 +0200 @@ -148,6 +148,7 @@ #define CTOR_CAST 0x00000400 /* The ctor is a cast. */ #define CTOR_HOLD_GIL 0x00000800 /* The ctor holds the GIL. */ #define CTOR_XFERRED 0x00001000 /* Ownership is transferred. */ +#define CTOR_DEPRECATED 0x00002000 /* Constructor is deprecated. */ #define isPublicCtor(c) ((c)->ctorflags & SECT_IS_PUBLIC) #define setIsPublicCtor(c) ((c)->ctorflags |= SECT_IS_PUBLIC) @@ -165,6 +166,8 @@ #define setIsHoldGILCtor(c) ((c)->ctorflags |= CTOR_HOLD_GIL) #define isResultTransferredCtor(c) ((c)->ctorflags & CTOR_XFERRED) #define setIsResultTransferredCtor(c) ((c)->ctorflags |= CTOR_XFERRED) +#define isDeprecatedCtor(c) ((c)->ctorflags & CTOR_DEPRECATED) +#define setIsDeprecatedCtor(c) ((c)->ctorflags |= CTOR_DEPRECATED) /* Handle member flags. */ @@ -223,6 +226,7 @@ #define OVER_THIS_XFERRED 0x00200000 /* Ownership of this is transferred. */ #define OVER_IS_GLOBAL 0x00400000 /* It is a global operator. */ #define OVER_IS_COMPLEMENTARY 0x00800000 /* It is a complementary operator. */ +#define OVER_IS_DEPRECATED 0x01000000 /* It is a deprecated function */ #define isPublic(o) ((o)->overflags & SECT_IS_PUBLIC) #define setIsPublic(o) ((o)->overflags |= SECT_IS_PUBLIC) @@ -269,6 +273,8 @@ #define setIsGlobal(o) ((o)->overflags |= OVER_IS_GLOBAL) #define isComplementary(o) ((o)->overflags & OVER_IS_COMPLEMENTARY) #define setIsComplementary(o) ((o)->overflags |= OVER_IS_COMPLEMENTARY) +#define isDeprecated(o) ((o)->overflags & OVER_IS_DEPRECATED) +#define setIsDeprecated(o) ((o)->overflags |= OVER_IS_DEPRECATED) /* Handle variable flags. */
_______________________________________________ PyQt mailing list PyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt