Commit 3a2bfc8b authored by Christoph Reiter's avatar Christoph Reiter 🐍 Committed by Simon Feltman

Raise TypeError if arguments are passed to Boxed.__init__

This is a partial revert of
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.
parent 90697704
......@@ -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'):
......@@ -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)
......@@ -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)
......@@ -34,6 +34,9 @@ class FontDescription(Pango.FontDescription):
return Pango.FontDescription.__new__(cls)
def __init__(self, *args, **kwargs):
return super(FontDescription, self).__init__()
FontDescription = override(FontDescription)
......@@ -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;
......@@ -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()
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