[pygobject] Fix GLib.Source sub-classing with initializer args
- From: Simon Feltman <sfeltman src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Fix GLib.Source sub-classing with initializer args
- Date: Wed, 11 Sep 2013 12:11:37 +0000 (UTC)
commit 59a2964141e963d2961e55d4b84a777927b4f21b
Author: Simon Feltman <sfeltman src gnome org>
Date: Wed Sep 11 05:05:33 2013 -0700
Fix GLib.Source sub-classing with initializer args
Add variable args and keyword args to the GLib.Source.__new__
method to support sub-classes which want to implement __init__.
https://bugzilla.gnome.org/show_bug.cgi?id=707904
gi/overrides/GLib.py | 2 +-
tests/test_source.py | 11 +++++++++++
2 files changed, 12 insertions(+), 1 deletions(-)
---
diff --git a/gi/overrides/GLib.py b/gi/overrides/GLib.py
index 0a4cdb6..f4b1ef5 100644
--- a/gi/overrides/GLib.py
+++ b/gi/overrides/GLib.py
@@ -536,7 +536,7 @@ __all__.append('MainContext')
class Source(GLib.Source):
- def __new__(cls):
+ def __new__(cls, *args, **kwargs):
# use our custom pyg_source_new() here as g_source_new() is not
# bindable
source = source_new()
diff --git a/tests/test_source.py b/tests/test_source.py
index 5b3b51b..d0e28e4 100644
--- a/tests/test_source.py
+++ b/tests/test_source.py
@@ -214,6 +214,17 @@ class TestSource(unittest.TestCase):
del source
self.assertTrue(self.finalized)
+ def test_extra_init_args(self):
+ class SourceWithInitArgs(GLib.Source):
+ def __init__(self, arg, kwarg=None):
+ super(SourceWithInitArgs, self).__init__()
+ self.arg = arg
+ self.kwarg = kwarg
+
+ source = SourceWithInitArgs(1, kwarg=2)
+ self.assertEqual(source.arg, 1)
+ self.assertEqual(source.kwarg, 2)
+
class TestUserData(unittest.TestCase):
def test_idle_no_data(self):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]