diff options
author | Simon Feltman <sfeltman@src.gnome.org> | 2013-09-28 00:26:28 -0700 |
---|---|---|
committer | Simon Feltman <sfeltman@src.gnome.org> | 2013-10-07 16:18:27 -0700 |
commit | 549f849ef8854352483657df3d7558688a4b0007 (patch) | |
tree | 13f9d2e7e679457b6955ce239e79a6aa4f6201f8 | |
parent | bc780ed17bc4cc62959c63c3f0142161a924679f (diff) | |
download | pygobject-549f849ef8854352483657df3d7558688a4b0007.tar.gz |
Refactor GLib.io_add_watch to make it more testable
Break the argument munging code into a separate function which
can be tested in isolation of adding an io watch.
Add additional failing test which specifies all args as keywords
which we eventually need to support for consistency with the
rest of PyGObject.
https://bugzilla.gnome.org/show_bug.cgi?id=640812
-rw-r--r-- | gi/overrides/GLib.py | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/gi/overrides/GLib.py b/gi/overrides/GLib.py index b2b22e7e..672957c6 100644 --- a/gi/overrides/GLib.py +++ b/gi/overrides/GLib.py @@ -662,15 +662,21 @@ def timeout_add_seconds(interval, function, *user_data, **kwargs): __all__.append('timeout_add_seconds') -# The real GLib API is io_add_watch(IOChannel, priority, condition, callback, -# user_data). This needs to take into account several historical APIs: +# The GI GLib API uses g_io_add_watch_full renamed to g_io_add_watch with +# a signature of (channel, priority, condition, func, user_data). +# Prior to PyGObject 3.8, this function was statically bound with an API closer to the +# non-full version with a signature of: (fd, condition, func, *user_data) +# We need to support this until we are okay with breaking API in a way which is +# not backwards compatible. +# +# This needs to take into account several historical APIs: # - calling with an fd as first argument # - calling with a Python file object as first argument (we keep this one as # it's really convenient and does not change the number of arguments) # - calling without a priority as second argument # and the usual "call without or multiple user_data", in which case the # callback gets the same user data arguments. -def io_add_watch(channel, priority_, condition, *cb_and_user_data, **kwargs): +def _io_add_watch_get_args(channel, priority_, condition, *cb_and_user_data, **kwargs): if not isinstance(priority_, int) or isinstance(priority_, GLib.IOCondition): warnings.warn('Calling io_add_watch without priority as second argument is deprecated', PyGIDeprecationWarning) @@ -709,8 +715,15 @@ def io_add_watch(channel, priority_, condition, *cb_and_user_data, **kwargs): func_fdtransform = func real_channel = channel - return GLib.io_add_watch(real_channel, priority_, condition, - func_fdtransform, user_data) + return real_channel, priority_, condition, func_fdtransform, user_data + +__all__.append('_io_add_watch_get_args') + + +def io_add_watch(*args, **kwargs): + """io_add_watch(channel, priority, condition, func, *user_data) -> event_source_id""" + channel, priority, condition, func, user_data = _io_add_watch_get_args(*args, **kwargs) + return GLib.io_add_watch(channel, priority, condition, func, user_data) __all__.append('io_add_watch') |