Commit 999679be authored by Martin Pitt's avatar Martin Pitt

Raise DeprecationWarning on deprecated callables

Check if a callable is marked as deprecated and raise a DeprecationWarning in
that case.

Notes:
 - Python hides DeprecationWarning by default, you need to enable them with -Wd
 - The deprecation message is currently not in the typelib (bug #694728)

https://bugzilla.gnome.org/show_bug.cgi?id=665084
parent 9f8258cf
......@@ -1462,6 +1462,20 @@ _pygi_callable_cache_new (GICallableInfo *callable_info, gboolean is_ccallback)
cache->name = g_base_info_get_name ((GIBaseInfo *)callable_info);
if (g_base_info_is_deprecated (callable_info)) {
const gchar *deprecated = g_base_info_get_attribute (callable_info, "deprecated");
gchar *warning;
if (deprecated != NULL)
warning = g_strdup_printf ("%s.%s is deprecated: %s",
g_base_info_get_namespace(callable_info), cache->name,
deprecated);
else
warning = g_strdup_printf ("%s.%s is deprecated",
g_base_info_get_namespace(callable_info), cache->name);
PyErr_WarnEx(PyExc_DeprecationWarning, warning, 0);
g_free (warning);;
}
if (type == GI_INFO_TYPE_FUNCTION) {
GIFunctionInfoFlags flags;
......
......@@ -12,6 +12,7 @@ import locale
import subprocess
import gc
import weakref
import warnings
from io import StringIO, BytesIO
import gi
......@@ -2907,3 +2908,12 @@ class TestSignatureArgs(unittest.TestCase):
def test_overridden_doc_is_not_clobbered(self):
self.assertEqual(GIMarshallingTests.OverridesObject.method.__doc__,
'Overridden doc string.')
class TestDeprecation(unittest.TestCase):
def test_method(self):
d = GLib.Date.new()
with warnings.catch_warnings(record=True) as warn:
warnings.simplefilter('always')
d.set_time(1)
self.assertTrue(issubclass(warn[0].category, DeprecationWarning))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment