[pygobject] Raise TypeError if arguments are passed to Boxed.__init__
- From: Simon Feltman <sfeltman src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Raise TypeError if arguments are passed to Boxed.__init__
- Date: Tue, 15 Apr 2014 02:16:31 +0000 (UTC)
commit 3a2bfc8bf01fcae386355bc3652780e198e54d49
Author: Christoph Reiter <reiter christoph gmail com>
Date: Mon Apr 14 23:33:52 2014 +0200
Raise TypeError if arguments are passed to Boxed.__init__
This is a partial revert of
https://git.gnome.org/browse/pygobject/commit/?id=2f2069c9efcd8
which removed a type check in __new__. This adds it back
into __init__. Overrides which define __new__ now have to
filter out any arguments in __init__ and not the other way
around, which is a bit less surprising in the common case.
https://bugzilla.gnome.org/show_bug.cgi?id=727810
gi/overrides/GLib.py | 6 ++++++
gi/overrides/Gtk.py | 6 ++++++
gi/overrides/Pango.py | 3 +++
gi/pygi-boxed.c | 6 ++++++
tests/test_gi.py | 4 ++++
5 files changed, 25 insertions(+), 0 deletions(-)
---
diff --git a/gi/overrides/GLib.py b/gi/overrides/GLib.py
index c541004..0e8f694 100644
--- a/gi/overrides/GLib.py
+++ b/gi/overrides/GLib.py
@@ -547,6 +547,9 @@ class Source(GLib.Source):
setattr(source, '__pygi_custom_source', True)
return source
+ def __init__(self, *args, **kwargs):
+ return super(Source, self).__init__()
+
def __del__(self):
if hasattr(self, '__pygi_custom_source'):
self.unref()
@@ -710,6 +713,9 @@ class IOChannel(GLib.IOChannel):
return GLib.IOChannel.win32_new_fd(hwnd)
raise TypeError('either a valid file descriptor, file name, or window handle must be supplied')
+ def __init__(self, *args, **kwargs):
+ return super(IOChannel, self).__init__()
+
def read(self, max_count=-1):
return io_channel_read(self, max_count)
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index ff9aea1..df55c2d 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -1115,6 +1115,9 @@ class TreePath(Gtk.TreePath):
except TypeError:
raise TypeError("could not parse subscript '%s' as a tree path" % path)
+ def __init__(self, *args, **kwargs):
+ super(TreePath, self).__init__()
+
def __str__(self):
return self.to_string()
@@ -1466,6 +1469,9 @@ class IconSet(Gtk.IconSet):
iconset = Gtk.IconSet.__new__(cls)
return iconset
+ def __init__(self, *args, **kwargs):
+ return super(IconSet, self).__init__()
+
IconSet = override(IconSet)
__all__.append('IconSet')
diff --git a/gi/overrides/Pango.py b/gi/overrides/Pango.py
index 0f7c484..365e47b 100644
--- a/gi/overrides/Pango.py
+++ b/gi/overrides/Pango.py
@@ -34,6 +34,9 @@ class FontDescription(Pango.FontDescription):
else:
return Pango.FontDescription.__new__(cls)
+ def __init__(self, *args, **kwargs):
+ return super(FontDescription, self).__init__()
+
FontDescription = override(FontDescription)
__all__.append('FontDescription')
diff --git a/gi/pygi-boxed.c b/gi/pygi-boxed.c
index 06324fd..c52858b 100644
--- a/gi/pygi-boxed.c
+++ b/gi/pygi-boxed.c
@@ -123,6 +123,12 @@ _boxed_init (PyObject *self,
PyObject *args,
PyObject *kwargs)
{
+ static char *kwlist[] = { NULL };
+
+ if (!PyArg_ParseTupleAndKeywords (args, kwargs, "", kwlist)) {
+ return -1;
+ }
+
/* Don't call PyGBoxed's init, which raises an exception. */
return 0;
}
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 5f6e481..9846440 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -1852,6 +1852,10 @@ class TestStructure(unittest.TestCase):
self.assertEqual(struct.long_, 42)
self.assertEqual(struct.string_, 'hello')
+ def test_union_init(self):
+ self.assertRaises(TypeError, GIMarshallingTests.Union, 42)
+ self.assertRaises(TypeError, GIMarshallingTests.Union, f=42)
+
def test_union(self):
union = GIMarshallingTests.Union()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]