[pygobject] Mark GLib API that is exposed in GObject as deprecated
- From: Martin Pitt <martinpitt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Mark GLib API that is exposed in GObject as deprecated
- Date: Wed, 24 Oct 2012 05:18:19 +0000 (UTC)
commit 483c86267f2623eaa88d6a9e685c96ec3ba4f121
Author: Martin Pitt <martinpitt gnome org>
Date: Tue Oct 23 08:56:19 2012 +0200
Mark GLib API that is exposed in GObject as deprecated
A lot of API in GObject really belongs into GLib and is just there for
historical/backwards compatible reasons. Mark these methods as deprecated so
that at some point we can drop them.
gi/overrides/GObject.py | 3 ++-
gi/overrides/__init__.py | 13 +++++++++++++
tests/test_gobject.py | 24 ++++++++++++++----------
3 files changed, 29 insertions(+), 11 deletions(-)
---
diff --git a/gi/overrides/GObject.py b/gi/overrides/GObject.py
index e65de7e..3bc2189 100644
--- a/gi/overrides/GObject.py
+++ b/gi/overrides/GObject.py
@@ -19,6 +19,7 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
# USA
+import gi.overrides
from gi.repository import GLib
__all__ = []
@@ -30,7 +31,7 @@ for name in ['markup_escape_text', 'get_application_name',
'filename_display_name', 'uri_list_extract_uris',
'MainLoop', 'MainContext', 'main_context_default',
'source_remove', 'Source', 'Idle', 'Timeout', 'PollFD']:
- globals()[name] = getattr(GLib, name)
+ globals()[name] = gi.overrides.deprecated(getattr(GLib, name), 'GLib.' + name)
__all__.append(name)
# constants are also deprecated, but cannot mark them as such
diff --git a/gi/overrides/__init__.py b/gi/overrides/__init__.py
index 0e4c489..6f922f0 100644
--- a/gi/overrides/__init__.py
+++ b/gi/overrides/__init__.py
@@ -1,4 +1,5 @@
import types
+import warnings
from gi import _gobject
@@ -69,3 +70,15 @@ def override(type_):
else:
registry.register(type_)
return type_
+
+
+def deprecated(fn, replacement):
+ '''Decorator for marking methods and classes as deprecated'''
+ def wrapped(*args, **kwargs):
+ warnings.warn('%s is deprecated; use %s instead' % (fn.__name__, replacement),
+ DeprecationWarning, stacklevel=2)
+ return fn(*args, **kwargs)
+ wrapped.__name__ = fn.__name__
+ wrapped.__doc__ = fn.__doc__
+ wrapped.__dict__.update(fn.__dict__)
+ return wrapped
diff --git a/tests/test_gobject.py b/tests/test_gobject.py
index 82bdff9..0c23e30 100644
--- a/tests/test_gobject.py
+++ b/tests/test_gobject.py
@@ -2,6 +2,7 @@
import gc
import unittest
+import warnings
from gi.repository import GObject
import sys
@@ -16,19 +17,22 @@ class TestGObjectAPI(unittest.TestCase):
'gi._gobject._gobject')
def testCompatAPI(self):
- # GObject formerly exposed a lot of GLib's functions
- self.assertEqual(GObject.markup_escape_text('foo'), 'foo')
+ with warnings.catch_warnings(record=True) as w:
+ warnings.simplefilter('always')
+ # GObject formerly exposed a lot of GLib's functions
+ self.assertEqual(GObject.markup_escape_text('foo'), 'foo')
- def testMainContextAPI(self):
- # backwards compatible alias API
- ml = GObject.MainLoop()
- self.assertFalse(ml.is_running())
+ ml = GObject.MainLoop()
+ self.assertFalse(ml.is_running())
- context = GObject.main_context_default()
- self.assertTrue(context.pending() in [False, True])
+ context = GObject.main_context_default()
+ self.assertTrue(context.pending() in [False, True])
- context = GObject.MainContext()
- self.assertFalse(context.pending())
+ context = GObject.MainContext()
+ self.assertFalse(context.pending())
+
+ self.assertTrue(issubclass(w[0].category, DeprecationWarning))
+ self.assertTrue('GLib.markup_escape_text' in str(w[0]), str(w[0]))
self.assertLess(GObject.PRIORITY_HIGH, GObject.PRIORITY_DEFAULT)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]