diff --git a/pybindgen/cppmethod.py b/pybindgen/cppmethod.py index a0d053c..a918251 100644 --- a/pybindgen/cppmethod.py +++ b/pybindgen/cppmethod.py @@ -23,7 +23,7 @@ class CppMethod(ForwardWrapperBase): template_parameters=(), is_virtual=False, is_const=False, unblock_threads=None, is_pure_virtual=False, custom_template_method_name=None, visibility='public', - custom_name=None): + custom_name=None, deprecated=False): """ Create an object the generates code to wrap a C++ class method. @@ -60,6 +60,11 @@ class CppMethod(ForwardWrapperBase): @param visibility: visibility of the method within the C++ class @type visibility: a string (allowed values are 'public', 'protected', 'private') + + @param deprecated: deprecation state for this API: + - False: Not deprecated + - True: Deprecated + - "message": Deprecated, and deprecation warning contains the given message """ self.stack_where_defined = traceback.extract_stack() @@ -102,6 +107,7 @@ class CppMethod(ForwardWrapperBase): return_value, parameters, "return NULL;", "return NULL;", unblock_threads=unblock_threads) + self.deprecated = deprecated def set_helper_class(self, helper_class): "Set the C++ helper class, which is used for overriding virtual methods" @@ -393,9 +399,14 @@ class CppConstructor(ForwardWrapperBase): wrapper is used as the python class __init__ method. """ - def __init__(self, parameters, unblock_threads=None, visibility='public'): + def __init__(self, parameters, unblock_threads=None, visibility='public', deprecated=False): """ - parameters -- the constructor parameters + @param parameters: the constructor parameters + + @param deprecated: deprecation state for this API: + - False: Not deprecated + - True: Deprecated + - "message": Deprecated, and deprecation warning contains the given message """ self.stack_where_defined = traceback.extract_stack() if unblock_threads is None: @@ -408,6 +419,7 @@ class CppConstructor(ForwardWrapperBase): "return -1;", "return -1;", force_parse=ForwardWrapperBase.PARSE_TUPLE_AND_KEYWORDS, unblock_threads=unblock_threads) + self.deprecated = deprecated assert visibility in ['public', 'protected', 'private'] self.visibility = visibility self.wrapper_base_name = None diff --git a/pybindgen/function.py b/pybindgen/function.py index 3e0ed09..39a911a 100644 --- a/pybindgen/function.py +++ b/pybindgen/function.py @@ -18,13 +18,17 @@ class Function(ForwardWrapperBase): """ def __init__(self, function_name, return_value, parameters, docstring=None, unblock_threads=None, - template_parameters=(), custom_name=None): + template_parameters=(), custom_name=None, deprecated=False): """ @param function_name: name of the C function @param return_value: the function return value @type return_value: L{ReturnValue} @param parameters: the function parameters @type parameters: list of L{Parameter} + @param deprecated: deprecation state for this API: + - False: Not deprecated + - True: Deprecated + - "message": Deprecated, and deprecation warning contains the given message """ self.stack_where_defined = traceback.extract_stack() @@ -48,6 +52,7 @@ class Function(ForwardWrapperBase): parse_error_return="return NULL;", error_return="return NULL;", unblock_threads=unblock_threads) + self.deprecated = deprecated self._module = None assert isinstance(function_name, str) self.function_name = function_name diff --git a/pybindgen/typehandlers/base.py b/pybindgen/typehandlers/base.py index 801e714..690a380 100644 --- a/pybindgen/typehandlers/base.py +++ b/pybindgen/typehandlers/base.py @@ -718,6 +718,7 @@ class ForwardWrapperBase(object): self.unblock_threads = unblock_threads self.no_c_retval = no_c_retval self.overload_index = None + self.deprecated = False # The following 3 variables describe the C wrapper function # prototype; do not confuse with the python function/method! @@ -812,6 +813,13 @@ class ForwardWrapperBase(object): 'convert_python_to_c method of parameter %s not implemented' % (param.ctype,)) + if self.deprecated: + if isinstance(self.deprecated, basestring): + msg = self.deprecated + else: + msg = "Deprecated" + self.before_call.write_error_check( 'PyErr_WarnEx(PyExc_DeprecationWarning, "%s", 1)' % msg) + if self.unblock_threads: self.before_call.write_code( "\nif (PyEval_ThreadsInitialized ())\n"