Commit 81418f49 authored by Christoph Reiter's avatar Christoph Reiter 🐍

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
parents 125e6797 27293ec8
......@@ -48,22 +48,81 @@ Application = override(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:
("%s shouldn't be instantiated directly, "
"use %s instead." % (name, instead)),
PyGIWarning, stacklevel=2)
"%s shouldn't be instantiated directly." % (name,),
PyGIWarning, stacklevel=2)
def __init__(self, *args, **kwargs):
super(VolumeMonitor, self).__init__(*args, **kwargs)
return new_init
"Gio.VolumeMonitor shouldn't be instantiated directly, "
"use Gio.VolumeMonitor.get() instead.",
PyGIWarning, stacklevel=2)
class VolumeMonitor(Gio.VolumeMonitor):
__init__ = _warn_init(Gio.VolumeMonitor, "Gio.VolumeMonitor.get()")
VolumeMonitor = override(VolumeMonitor)
class DBusAnnotationInfo(Gio.DBusAnnotationInfo):
__init__ = _warn_init(Gio.DBusAnnotationInfo)
class DBusArgInfo(Gio.DBusArgInfo):
__init__ = _warn_init(Gio.DBusArgInfo)
class DBusMethodInfo(Gio.DBusMethodInfo):
__init__ = _warn_init(Gio.DBusMethodInfo)
class DBusSignalInfo(Gio.DBusSignalInfo):
__init__ = _warn_init(Gio.DBusSignalInfo)
class DBusInterfaceInfo(Gio.DBusInterfaceInfo):
__init__ = _warn_init(Gio.DBusInterfaceInfo)
class DBusNodeInfo(Gio.DBusNodeInfo):
__init__ = _warn_init(Gio.DBusNodeInfo)
class ActionMap(Gio.ActionMap):
def add_action_entries(self, entries, user_data=None):
......@@ -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():
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:
assert issubclass(warn[0].category, PyGIWarning)
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment