GNOME Bugzilla – Bug 665084
Issue DeprecationWarning when using deprecated APIs
Last modified: 2018-01-10 20:13:15 UTC
When using APIs through gi.repository, any API which is flagged as deprecated, should have a DeprecationWarning issued when it is used.
For future reference it looks like there is a g_base_info_is_deprecated which we can use for this. However, there is no help text or information related to the deprecation which is unfortunate. The best we can do is a somewhat non-descriptive deprecation warning: DeprecationWarning: foo is deprecated
g_base_info_get_attribute ()(In reply to comment #1) > For future reference it looks like there is a g_base_info_is_deprecated which > we can use for this. However, there is no help text or information related to > the deprecation which is unfortunate. The best we can do is a somewhat > non-descriptive deprecation warning: We could use g_base_info_get_attribute () to retrieve the values of "deprecated" and "deprecated-version"? That information is in the gir at least, for example in GLib: <method name="set_time" c:identifier="g_date_set_time" deprecated="Use g_date_set_time_t() instead." deprecated-version="2.10">
Argh, it seems g-ir-compiler doesn't put those fields into typelibs. I filed bug 694728 about this.
Created attachment 237416 [details] [review] Raise DeprecationWarning on deprecated callables This patch adds deprecations for callables. We'll need similar code for enums, constants, etc. but I'd appreciate a review about this first.
Review of attachment 237416 [details] [review]: Looks good. Seems like the right place for this because caches are only generated when calling a function and should only occur once. A few minor style nitpicks. ::: gi/pygi-cache.c @@ +1468,3 @@ + if (deprecated != NULL) + warning = g_strdup_printf ("%s.%s is deprecated: %s", + g_base_info_get_namespace(callable_info), cache->name, space after function name and before parentheses ? @@ +1472,3 @@ + else + warning = g_strdup_printf ("%s.%s is deprecated", + warning = g_strdup_printf ("%s.%s is deprecated: %s", and here @@ +1473,3 @@ + warning = g_strdup_printf ("%s.%s is deprecated", + g_base_info_get_namespace(callable_info), cache->name); + warning = g_strdup_printf ("%s.%s is deprecated: %s", etc @@ +1474,3 @@ + g_base_info_get_namespace(callable_info), cache->name); + PyErr_WarnEx(PyExc_DeprecationWarning, warning, 0); + g_base_info_get_namespace(callable_info), cache->name, double semicolon
Martin, it looks like this went in, can we close this?
Simon, the fix went in for methods, but I believe we still need it for functions and constants.
The method one could be improved, they are all missing the class name: >>> DeprecationWarning: Gtk.set_homogeneous is deprecated >>> t.set_homogeneous(False)
(In reply to comment #8) > The method one could be improved, they are all missing the class name: > > >>> DeprecationWarning: Gtk.set_homogeneous is deprecated > >>> t.set_homogeneous(False) I've filed bug 743468 for this.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/pygobject/issues/22.