[pygobject] Move PyGIDeprecationWarning to C for shared Python/C usage
- From: Simon Feltman <sfeltman src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Move PyGIDeprecationWarning to C for shared Python/C usage
- Date: Thu, 25 Jul 2013 20:00:50 +0000 (UTC)
commit 077aefed8566adcb99d7570f52fe09c74c2098e5
Author: Simon Feltman <sfeltman src gnome org>
Date: Sat Jul 6 13:34:53 2013 -0700
Move PyGIDeprecationWarning to C for shared Python/C usage
https://bugzilla.gnome.org/show_bug.cgi?id=688081
gi/__init__.py | 19 ++++---------------
gi/gimodule.c | 18 ++++++++++++++++++
gi/pygi.h | 2 ++
3 files changed, 24 insertions(+), 15 deletions(-)
---
diff --git a/gi/__init__.py b/gi/__init__.py
index e8c12db..0645d44 100644
--- a/gi/__init__.py
+++ b/gi/__init__.py
@@ -24,7 +24,9 @@ from __future__ import absolute_import
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
-from ._gi import _API, Repository
+from ._gi import _API
+from ._gi import Repository
+from ._gi import PyGIDeprecationWarning
# Force loading the GObject typelib so we have available the wrappers for
# base classes such as GInitiallyUnowned
@@ -32,6 +34,7 @@ import gi._gobject
gi # pyflakes
_API = _API # pyflakes
+PyGIDeprecationWarning = PyGIDeprecationWarning
import os
@@ -81,17 +84,3 @@ def require_version(namespace, version):
def get_required_version(namespace):
return _versions.get(namespace, None)
-
-
-# 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
-# behave the same as regular Python deprecations in stable releases.
-if version_info[1] % 2:
- _DeprecationWarningBase = RuntimeWarning
-else:
- _DeprecationWarningBase = DeprecationWarning
-
-
-class PyGIDeprecationWarning(_DeprecationWarningBase):
- pass
diff --git a/gi/gimodule.c b/gi/gimodule.c
index 5b6bc14..12dfb36 100644
--- a/gi/gimodule.c
+++ b/gi/gimodule.c
@@ -28,6 +28,8 @@
#include <pygobject.h>
#include <pyglib-python-compat.h>
+PyObject *PyGIDeprecationWarning;
+
static PyObject *
_wrap_pyg_enum_add (PyObject *self,
PyObject *args,
@@ -641,6 +643,22 @@ PYGLIB_MODULE_START(_gi, "_gi")
_pygi_ccallback_register_types (module);
_pygi_argument_init();
+ /* 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
+ * behave the same as regular Python deprecations in stable releases.
+ */
+#if PYGOBJECT_MINOR_VERSION % 2
+ PyGIDeprecationWarning = PyErr_NewException("gi.PyGIDeprecationWarning",
+ PyExc_RuntimeWarning, NULL);
+#else
+ PyGIDeprecationWarning = PyErr_NewException("gi.PyGIDeprecationWarning",
+ PyExc_DeprecationWarning, NULL);
+#endif
+
+ Py_INCREF(PyGIDeprecationWarning);
+ PyModule_AddObject(module, "PyGIDeprecationWarning", PyGIDeprecationWarning);
+
api = PYGLIB_CPointer_WrapPointer ( (void *) &CAPI, "gi._API");
if (api == NULL) {
return PYGLIB_MODULE_ERROR_RETURN;
diff --git a/gi/pygi.h b/gi/pygi.h
index f3f0c81..10da504 100644
--- a/gi/pygi.h
+++ b/gi/pygi.h
@@ -32,6 +32,8 @@
#include <girepository.h>
#include "pygi-cache.h"
+extern PyObject *PyGIDeprecationWarning;
+
typedef struct {
PyObject_HEAD
GIRepository *repository;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]