summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Reiter <creiter@src.gnome.org>2015-03-02 20:58:04 +0100
committerChristoph Reiter <creiter@src.gnome.org>2015-06-02 10:03:07 +0200
commit2048dc8d1d708abce7037f96483c6d776567d6b5 (patch)
treec5f050733b3686e4f5c3b498720157077cf29ee3
parent7a3bb6971f22accd25e987496d377e1879f6e1ba (diff)
downloadpygobject-2048dc8d1d708abce7037f96483c6d776567d6b5.tar.gz
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
-rw-r--r--gi/__init__.py2
-rw-r--r--gi/gimodule.c6
-rw-r--r--gi/importer.py3
-rw-r--r--tests/test_gi.py15
4 files changed, 25 insertions, 1 deletions
diff --git a/gi/__init__.py b/gi/__init__.py
index fe4abcfb..caad5694 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 0a5bd876..74bf7cd0 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 c097b74f..0acbc23e 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 22a5738a..f69a61cc 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()