After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 665084 - Issue DeprecationWarning when using deprecated APIs
Issue DeprecationWarning when using deprecated APIs
Status: RESOLVED OBSOLETE
Product: pygobject
Classification: Bindings
Component: general
Git master
Other Linux
: Normal minor
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on: 694728 743514
Blocks:
 
 
Reported: 2011-11-28 20:36 UTC by Rodney Dawes
Modified: 2018-01-10 20:13 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Raise DeprecationWarning on deprecated callables (2.48 KB, patch)
2013-02-26 09:18 UTC, Martin Pitt
committed Details | Review

Description Rodney Dawes 2011-11-28 20:36:06 UTC
When using APIs through gi.repository, any API which is flagged as deprecated, should have a DeprecationWarning issued when it is used.
Comment 1 Simon Feltman 2013-02-25 22:35:53 UTC
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
Comment 2 Martin Pitt 2013-02-26 08:25:38 UTC
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">
Comment 3 Martin Pitt 2013-02-26 08:48:44 UTC
Argh, it seems g-ir-compiler doesn't put those fields into typelibs. I filed bug 694728 about this.
Comment 4 Martin Pitt 2013-02-26 09:18:20 UTC
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.
Comment 5 Simon Feltman 2013-02-26 09:38:12 UTC
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
Comment 6 Simon Feltman 2013-04-20 06:50:52 UTC
Martin, it looks like this went in, can we close this?
Comment 7 Martin Pitt 2013-04-22 05:30:36 UTC
Simon, the fix went in for methods, but I believe we still need it for functions and constants.
Comment 8 Christoph Reiter (lazka) 2014-08-25 09:19:50 UTC
The method one could be improved, they are all missing the class name:

>>> DeprecationWarning: Gtk.set_homogeneous is deprecated
>>>  t.set_homogeneous(False)
Comment 9 Christoph Reiter (lazka) 2015-01-25 09:40:15 UTC
(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.
Comment 10 GNOME Infrastructure Team 2018-01-10 20:13:15 UTC
-- 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.