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)
__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):
"""
......
......@@ -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)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment