[pygobject] Add gi.PyGIWarning and use it instead of PyGIDeprecationWarning in case the version to import wasn't
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Add gi.PyGIWarning and use it instead of PyGIDeprecationWarning in case the version to import wasn't
- Date: Tue, 2 Jun 2015 08:08:52 +0000 (UTC)
commit 2048dc8d1d708abce7037f96483c6d776567d6b5
Author: Christoph Reiter <creiter src gnome org>
Date: Mon Mar 2 20:58:04 2015 +0100
Add gi.PyGIWarning and use it instead of PyGIDeprecationWarning in case the version to import wasn't
specified.
This makes the warning visible by default.
See commit ef3bff4e570363e4f383d4cdae9cecd4073b03d8 for more info on the warning.
https://bugzilla.gnome.org/show_bug.cgi?id=727379
gi/__init__.py | 2 ++
gi/gimodule.c | 6 ++++++
gi/importer.py | 3 ++-
tests/test_gi.py | 15 +++++++++++++++
4 files changed, 25 insertions(+), 1 deletions(-)
---
diff --git a/gi/__init__.py b/gi/__init__.py
index fe4abcf..caad569 100644
--- a/gi/__init__.py
+++ b/gi/__init__.py
@@ -44,9 +44,11 @@ from ._gi import _gobject
from ._gi import _API
from ._gi import Repository
from ._gi import PyGIDeprecationWarning
+from ._gi import PyGIWarning
_API = _API # pyflakes
PyGIDeprecationWarning = PyGIDeprecationWarning
+PyGIWarning = PyGIWarning
_versions = {}
_overridesdir = os.path.join(os.path.dirname(__file__), 'overrides')
diff --git a/gi/gimodule.c b/gi/gimodule.c
index 0a5bd87..74bf7cd 100644
--- a/gi/gimodule.c
+++ b/gi/gimodule.c
@@ -32,6 +32,7 @@
#include <pyglib-python-compat.h>
+PyObject *PyGIWarning;
PyObject *PyGIDeprecationWarning;
PyObject *_PyGIDefaultArgPlaceholder;
@@ -637,6 +638,8 @@ PYGLIB_MODULE_START(_gi, "_gi")
_pygi_boxed_register_types (module);
_pygi_ccallback_register_types (module);
+ PyGIWarning = PyErr_NewException ("gi.PyGIWarning", PyExc_Warning, NULL);
+
/* Use RuntimeWarning as the base class of PyGIDeprecationWarning
* for unstable (odd minor version) and use DeprecationWarning for
* stable (even minor version). This is so PyGObject deprecations
@@ -655,6 +658,9 @@ PYGLIB_MODULE_START(_gi, "_gi")
*/
_PyGIDefaultArgPlaceholder = PyObject_New(PyObject, &PyType_Type);
+ Py_INCREF (PyGIWarning);
+ PyModule_AddObject (module, "PyGIWarning", PyGIWarning);
+
Py_INCREF(PyGIDeprecationWarning);
PyModule_AddObject(module, "PyGIDeprecationWarning", PyGIDeprecationWarning);
diff --git a/gi/importer.py b/gi/importer.py
index c097b74..0acbc23 100644
--- a/gi/importer.py
+++ b/gi/importer.py
@@ -28,6 +28,7 @@ from contextlib import contextmanager
import gi
from ._gi import Repository
+from ._gi import PyGIWarning
from .module import get_introspection_module
from .overrides import load_overrides
@@ -119,7 +120,7 @@ def _check_require_version(namespace, stacklevel):
"Use gi.require_version('%(namespace)s', '%(version)s') before "
"import to ensure that the right version gets loaded."
% {"namespace": namespace, "version": version},
- ImportWarning, stacklevel=stacklevel)
+ PyGIWarning, stacklevel=stacklevel)
class DynamicImporter(object):
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 22a5738..f69a61c 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -17,6 +17,7 @@ from io import StringIO, BytesIO
import gi
import gi.overrides
+from gi import PyGIWarning
from gi import PyGIDeprecationWarning
from gi.repository import GObject, GLib, Gio
@@ -2773,6 +2774,20 @@ class TestProjectVersion(unittest.TestCase):
gi.check_version("3.3.5")
+class TestGIWarning(unittest.TestCase):
+
+ def test_warning(self):
+ ignored_by_default = (DeprecationWarning, PendingDeprecationWarning,
+ ImportWarning)
+
+ with warnings.catch_warnings(record=True) as warn:
+ warnings.simplefilter('always')
+ warnings.warn("test", PyGIWarning)
+ self.assertTrue(issubclass(warn[0].category, Warning))
+ # We don't want PyGIWarning get ignored by default
+ self.assertFalse(issubclass(warn[0].category, ignored_by_default))
+
+
class TestDeprecation(unittest.TestCase):
def test_method(self):
d = GLib.Date.new()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]