summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Reiter <reiter.christoph@gmail.com>2019-01-19 15:31:46 +0000
committerChristoph Reiter <reiter.christoph@gmail.com>2019-01-19 15:31:46 +0000
commit81418f49b66c413797fe26c05536d346ac25cf18 (patch)
tree6a749af0851792c418feebf28bc62b01b4f22024
parent125e679722f4628ce20baacb179a3675ca0c0863 (diff)
parent27293ec8f7e9c11ed609afc1bf3e87cc602739cb (diff)
downloadpygobject-81418f49b66c413797fe26c05536d346ac25cf18.tar.gz
Merge branch 'warn-init-dbus-boxed-info-types' into 'master'
gio overrides: emit a warning when creating various dbus types without a constructor. Fixes #15 Closes #15 See merge request GNOME/pygobject!107
-rw-r--r--gi/overrides/Gio.py77
-rw-r--r--tests/test_overrides_gio.py15
2 files changed, 83 insertions, 9 deletions
diff --git a/gi/overrides/Gio.py b/gi/overrides/Gio.py
index 5c19ef27..eafbae52 100644
--- a/gi/overrides/Gio.py
+++ b/gi/overrides/Gio.py
@@ -48,22 +48,81 @@ Application = override(Application)
__all__.append('Application')
-class VolumeMonitor(Gio.VolumeMonitor):
+def _warn_init(cls, instead=None):
+
+ def new_init(self, *args, **kwargs):
+ super(cls, self).__init__(*args, **kwargs)
+ name = cls.__module__.rsplit(".", 1)[-1] + "." + cls.__name__
+ if instead:
+ warnings.warn(
+ ("%s shouldn't be instantiated directly, "
+ "use %s instead." % (name, instead)),
+ PyGIWarning, stacklevel=2)
+ else:
+ warnings.warn(
+ "%s shouldn't be instantiated directly." % (name,),
+ PyGIWarning, stacklevel=2)
- def __init__(self, *args, **kwargs):
- super(VolumeMonitor, self).__init__(*args, **kwargs)
+ return new_init
- # https://bugzilla.gnome.org/show_bug.cgi?id=744690
- warnings.warn(
- "Gio.VolumeMonitor shouldn't be instantiated directly, "
- "use Gio.VolumeMonitor.get() instead.",
- PyGIWarning, stacklevel=2)
+
+@override
+class VolumeMonitor(Gio.VolumeMonitor):
+ # https://bugzilla.gnome.org/show_bug.cgi?id=744690
+ __init__ = _warn_init(Gio.VolumeMonitor, "Gio.VolumeMonitor.get()")
-VolumeMonitor = override(VolumeMonitor)
__all__.append('VolumeMonitor')
+@override
+class DBusAnnotationInfo(Gio.DBusAnnotationInfo):
+ __init__ = _warn_init(Gio.DBusAnnotationInfo)
+
+
+__all__.append('DBusAnnotationInfo')
+
+
+@override
+class DBusArgInfo(Gio.DBusArgInfo):
+ __init__ = _warn_init(Gio.DBusArgInfo)
+
+
+__all__.append('DBusArgInfo')
+
+
+@override
+class DBusMethodInfo(Gio.DBusMethodInfo):
+ __init__ = _warn_init(Gio.DBusMethodInfo)
+
+
+__all__.append('DBusMethodInfo')
+
+
+@override
+class DBusSignalInfo(Gio.DBusSignalInfo):
+ __init__ = _warn_init(Gio.DBusSignalInfo)
+
+
+__all__.append('DBusSignalInfo')
+
+
+@override
+class DBusInterfaceInfo(Gio.DBusInterfaceInfo):
+ __init__ = _warn_init(Gio.DBusInterfaceInfo)
+
+
+__all__.append('DBusInterfaceInfo')
+
+
+@override
+class DBusNodeInfo(Gio.DBusNodeInfo):
+ __init__ = _warn_init(Gio.DBusNodeInfo)
+
+
+__all__.append('DBusNodeInfo')
+
+
class ActionMap(Gio.ActionMap):
def add_action_entries(self, entries, user_data=None):
"""
diff --git a/tests/test_overrides_gio.py b/tests/test_overrides_gio.py
index b6516f9b..8612d51e 100644
--- a/tests/test_overrides_gio.py
+++ b/tests/test_overrides_gio.py
@@ -2,10 +2,12 @@ from __future__ import absolute_import
import random
import platform
+import warnings
import pytest
from gi.repository import Gio, GObject
+from gi import PyGIWarning
from gi._compat import cmp
@@ -344,3 +346,16 @@ def test_action_map_add_action_entries():
actionmap.activate_action("simple")
assert test_data[0] == 'test back'
+
+
+def test_types_init_warn():
+ types = [
+ Gio.DBusAnnotationInfo, Gio.DBusArgInfo, Gio.DBusMethodInfo,
+ Gio.DBusSignalInfo, Gio.DBusInterfaceInfo, Gio.DBusNodeInfo,
+ ]
+
+ for t in types:
+ with warnings.catch_warnings(record=True) as warn:
+ warnings.simplefilter('always')
+ t()
+ assert issubclass(warn[0].category, PyGIWarning)