[pygobject] Use a custom deprecation warning to make them visible by default
- From: Martin Pitt <martinpitt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Use a custom deprecation warning to make them visible by default
- Date: Fri, 26 Oct 2012 08:53:33 +0000 (UTC)
commit f976d05b04f26e733d19988e68989e340eb3a29e
Author: Martin Pitt <martinpitt gnome org>
Date: Fri Oct 26 10:39:28 2012 +0200
Use a custom deprecation warning to make them visible by default
DeprecationWarning is not shown by default, and is thus rather useless for
developers. Use a custom PyGIDeprecationWarning class and derive it from
RuntimeWarning to make it visible.
gi/__init__.py | 5 +++++
gi/overrides/GLib.py | 5 +++--
gi/overrides/Gtk.py | 5 +++--
gi/overrides/__init__.py | 4 ++--
gi/pygtkcompat.py | 4 ++--
tests/Makefile.am | 2 +-
tests/test_glib.py | 5 +++--
tests/test_gobject.py | 3 ++-
tests/test_iochannel.py | 5 +++--
tests/test_source.py | 3 ++-
10 files changed, 26 insertions(+), 15 deletions(-)
---
diff --git a/gi/__init__.py b/gi/__init__.py
index 6ebff8e..d4cdcaa 100644
--- a/gi/__init__.py
+++ b/gi/__init__.py
@@ -81,3 +81,8 @@ def require_version(namespace, version):
def get_required_version(namespace):
return _versions.get(namespace, None)
+
+# note, DeprecationWarning would be more suitable as a base, but this
+# unhelpfully isn't shown by default and thus useless
+class PyGIDeprecationWarning(RuntimeWarning):
+ pass
diff --git a/gi/overrides/GLib.py b/gi/overrides/GLib.py
index 65c7e8e..794f3e6 100644
--- a/gi/overrides/GLib.py
+++ b/gi/overrides/GLib.py
@@ -26,6 +26,7 @@ from ..module import get_introspection_module
from .._gi import (variant_new_tuple, variant_type_from_string, source_new,
source_set_callback, io_channel_read)
from ..overrides import override, deprecated
+from gi import PyGIDeprecationWarning
GLib = get_introspection_module('GLib')
@@ -606,7 +607,7 @@ __all__.append('timeout_add_seconds')
def io_add_watch(channel, priority, condition, callback=_unspecified, user_data=_unspecified):
if not isinstance(priority, int) or isinstance(priority, GLib.IOCondition):
warnings.warn('Calling io_add_watch without priority as second argument is deprecated',
- DeprecationWarning)
+ PyGIDeprecationWarning)
# shift the arguments around
user_data = callback
callback = condition
@@ -623,7 +624,7 @@ def io_add_watch(channel, priority, condition, callback=_unspecified, user_data=
# backwards compatibility: Allow calling with fd
if isinstance(channel, int):
warnings.warn('Calling io_add_watch with a file descriptor is deprecated; call it with a GLib.IOChannel object',
- DeprecationWarning)
+ PyGIDeprecationWarning)
func_fdtransform = lambda _, cond, data: func(channel, cond, data)
real_channel = GLib.IOChannel.unix_new(channel)
else:
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index 1856a4a..78bbd36 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -23,6 +23,7 @@ import sys
from gi.repository import GObject
from ..overrides import override
from ..module import get_introspection_module
+from gi import PyGIDeprecationWarning
if sys.version_info >= (3, 0):
_basestring = str
@@ -442,7 +443,7 @@ class Dialog(Gtk.Dialog, Container):
if hasattr(Gtk.DialogFlags, "NO_SEPARATOR") and (flags & Gtk.DialogFlags.NO_SEPARATOR):
self.set_has_separator(False)
import warnings
- warnings.warn("Gtk.DialogFlags.NO_SEPARATOR has been depricated since Gtk+-3.0", DeprecationWarning)
+ warnings.warn("Gtk.DialogFlags.NO_SEPARATOR has been depricated since Gtk+-3.0", PyGIDeprecationWarning)
if buttons is not None:
self.add_buttons(*buttons)
@@ -493,7 +494,7 @@ class MessageDialog(Gtk.MessageDialog, Dialog):
# type keyword is used for backwards compat with PyGTK
if 'type' in kwds:
import warnings
- warnings.warn("The use of the keyword type as a parameter of the Gtk.MessageDialog constructor has been depricated. Please use message_type instead.", DeprecationWarning)
+ warnings.warn("The use of the keyword type as a parameter of the Gtk.MessageDialog constructor has been depricated. Please use message_type instead.", PyGIDeprecationWarning)
message_type = kwds.pop('type')
Gtk.MessageDialog.__init__(self,
diff --git a/gi/overrides/__init__.py b/gi/overrides/__init__.py
index 6f922f0..3570c95 100644
--- a/gi/overrides/__init__.py
+++ b/gi/overrides/__init__.py
@@ -1,7 +1,7 @@
import types
import warnings
-from gi import _gobject
+from gi import _gobject, PyGIDeprecationWarning
# support overrides in different directories than our gi module
from pkgutil import extend_path
@@ -76,7 +76,7 @@ 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)
+ PyGIDeprecationWarning, stacklevel=2)
return fn(*args, **kwargs)
wrapped.__name__ = fn.__name__
wrapped.__doc__ = fn.__doc__
diff --git a/gi/pygtkcompat.py b/gi/pygtkcompat.py
index 2c81d3f..7b37599 100644
--- a/gi/pygtkcompat.py
+++ b/gi/pygtkcompat.py
@@ -202,7 +202,7 @@ def enable_gtk(version='2.0'):
def set_tool_item_type(menuaction, gtype):
warnings.warn('set_tool_item_type() is not supported',
- DeprecationWarning, stacklevel=2)
+ gi.PyGIDeprecationWarning, stacklevel=2)
Gtk.Action.set_tool_item_type = classmethod(set_tool_item_type)
# Alignment
@@ -314,7 +314,7 @@ def enable_gtk(version='2.0'):
def install_child_property(container, flag, pspec):
warnings.warn('install_child_property() is not supported',
- DeprecationWarning, stacklevel=2)
+ gi.PyGIDeprecationWarning, stacklevel=2)
Gtk.Container.install_child_property = classmethod(install_child_property)
def new_text():
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0cc60e7..82fd792 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -131,7 +131,7 @@ check-local: $(LTLIBRARIES:.la=.so) $(test_typelibs) gschemas.compiled
if type pep8 >/dev/null 2>&1; then pep8 --ignore=E501,E123,E124 --repeat --show-source $(top_srcdir); else echo "skipped, pep8 not installed"; fi; \
fi
export `$(DBUS_LAUNCH)` && \
- $(RUN_TESTS_ENV_VARS) $(EXEC_NAME) $(PYTHON) -Wd -Werror::PendingDeprecationWarning -Werror::DeprecationWarning $(srcdir)/runtests.py; rc=$$?; \
+ $(RUN_TESTS_ENV_VARS) $(EXEC_NAME) $(PYTHON) -Wd -Werror::PendingDeprecationWarning -Werror::DeprecationWarning -Werror::RuntimeWarning $(srcdir)/runtests.py; rc=$$?; \
kill $$DBUS_SESSION_BUS_PID; \
exit $$rc
diff --git a/tests/test_glib.py b/tests/test_glib.py
index f2f28aa..b1e3fc4 100644
--- a/tests/test_glib.py
+++ b/tests/test_glib.py
@@ -6,6 +6,7 @@ import os.path
import warnings
from gi.repository import GLib
+from gi import PyGIDeprecationWarning
from compathelper import _unicode, _bytes
@@ -115,7 +116,7 @@ https://my.org/q?x=1&y=2
with warnings.catch_warnings(record=True) as warn:
warnings.simplefilter('always')
GLib.io_add_watch(r, GLib.IOCondition.IN, cb)
- self.assertTrue(issubclass(warn[0].category, DeprecationWarning))
+ self.assertTrue(issubclass(warn[0].category, PyGIDeprecationWarning))
ml = GLib.MainLoop()
GLib.timeout_add(10, lambda: os.write(w, b'a') and False)
@@ -138,7 +139,7 @@ https://my.org/q?x=1&y=2
with warnings.catch_warnings(record=True) as warn:
warnings.simplefilter('always')
GLib.io_add_watch(r, GLib.IOCondition.IN, cb, 'moo')
- self.assertTrue(issubclass(warn[0].category, DeprecationWarning))
+ self.assertTrue(issubclass(warn[0].category, PyGIDeprecationWarning))
ml = GLib.MainLoop()
GLib.timeout_add(10, lambda: os.write(w, b'a') and False)
diff --git a/tests/test_gobject.py b/tests/test_gobject.py
index 19d1cf4..e580049 100644
--- a/tests/test_gobject.py
+++ b/tests/test_gobject.py
@@ -5,6 +5,7 @@ import unittest
import warnings
from gi.repository import GObject
+from gi import PyGIDeprecationWarning
import sys
import testhelper
@@ -31,7 +32,7 @@ class TestGObjectAPI(unittest.TestCase):
context = GObject.MainContext()
self.assertFalse(context.pending())
- self.assertTrue(issubclass(w[0].category, DeprecationWarning))
+ self.assertTrue(issubclass(w[0].category, PyGIDeprecationWarning))
self.assertTrue('GLib.markup_escape_text' in str(w[0]), str(w[0]))
self.assertLess(GObject.PRIORITY_HIGH, GObject.PRIORITY_DEFAULT)
diff --git a/tests/test_iochannel.py b/tests/test_iochannel.py
index e0eca2a..c2db860 100644
--- a/tests/test_iochannel.py
+++ b/tests/test_iochannel.py
@@ -9,6 +9,7 @@ import shutil
import warnings
from gi.repository import GLib
+from gi import PyGIDeprecationWarning
class IOChannel(unittest.TestCase):
@@ -218,7 +219,7 @@ second line
with warnings.catch_warnings(record=True) as warn:
warnings.simplefilter('always')
ch.add_watch(GLib.IOCondition.IN, cb)
- self.assertTrue(issubclass(warn[0].category, DeprecationWarning))
+ self.assertTrue(issubclass(warn[0].category, PyGIDeprecationWarning))
ml = GLib.MainLoop()
@@ -250,7 +251,7 @@ second line
with warnings.catch_warnings(record=True) as warn:
warnings.simplefilter('always')
id = ch.add_watch(GLib.IOCondition.IN, cb, 'hello', GLib.PRIORITY_HIGH)
- self.assertTrue(issubclass(warn[0].category, DeprecationWarning))
+ self.assertTrue(issubclass(warn[0].category, PyGIDeprecationWarning))
self.assertEqual(ml.get_context().find_source_by_id(id).priority,
GLib.PRIORITY_HIGH)
diff --git a/tests/test_source.py b/tests/test_source.py
index 5f0b16c..ba9ea37 100644
--- a/tests/test_source.py
+++ b/tests/test_source.py
@@ -4,6 +4,7 @@ import unittest
import warnings
from gi.repository import GLib, GObject
+from gi import PyGIDeprecationWarning
class Idle(GLib.Idle):
@@ -162,7 +163,7 @@ class TestSource(unittest.TestCase):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
time = s.get_current_time()
- self.assertTrue(issubclass(w[0].category, DeprecationWarning))
+ self.assertTrue(issubclass(w[0].category, PyGIDeprecationWarning))
self.assertTrue(isinstance(time, float))
# plausibility check, and check magnitude of result
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]