summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Grönholm <alex.gronholm@nextday.fi>2015-01-06 17:43:02 +0200
committerAlex Grönholm <alex.gronholm@nextday.fi>2015-01-06 17:45:04 +0200
commit7b057d6298f4d63ae71a9ba4aaf03f35ebcf85e3 (patch)
tree1fe512daebfc8c0f033f84801049e1f8eaa03ea6
parentdb67d65af6a4df2e73d0941eb1d04522df1c3d50 (diff)
downloadapscheduler-7b057d6298f4d63ae71a9ba4aaf03f35ebcf85e3.tar.gz
Fixed ValueError when the target callable has a default keyword argument that wasn't overridden (fixes #79)
-rw-r--r--apscheduler/util.py5
-rw-r--r--docs/versionhistory.rst6
-rw-r--r--tests/test_util.py6
3 files changed, 15 insertions, 2 deletions
diff --git a/apscheduler/util.py b/apscheduler/util.py
index 988f942..063a6c1 100644
--- a/apscheduler/util.py
+++ b/apscheduler/util.py
@@ -343,16 +343,17 @@ def check_callable_args(func, args, kwargs):
return # getargspec() doesn't work certain callables
argspec_args = argspec.args if not ismethod(func) else argspec.args[1:]
+ arg_defaults = dict(zip(reversed(argspec_args), argspec.defaults or ()))
has_varargs = bool(argspec.varargs)
has_var_kwargs = bool(argspec.keywords)
- for arg, default in six.moves.zip_longest(argspec_args, argspec.defaults or (), fillvalue=undefined):
+ for arg in argspec_args:
if arg in unmatched_kwargs and unmatched_args:
pos_kwargs_conflicts.append(arg)
elif unmatched_args:
del unmatched_args[0]
elif arg in unmatched_kwargs:
unmatched_kwargs.remove(arg)
- elif default is undefined:
+ elif arg not in arg_defaults:
unsatisfied_args.append(arg)
# Make sure there are no conflicts between args and kwargs
diff --git a/docs/versionhistory.rst b/docs/versionhistory.rst
index 5d79ee3..819e329 100644
--- a/docs/versionhistory.rst
+++ b/docs/versionhistory.rst
@@ -5,6 +5,12 @@ To find out how to migrate your application from a previous version of
APScheduler, see the :doc:`migration section <migration>`.
+3.0.2
+-----
+
+* Fixed ValueError when the target callable has a default keyword argument that wasn't overridden
+
+
3.0.1
-----
diff --git a/tests/test_util.py b/tests/test_util.py
index a416297..6908bc3 100644
--- a/tests/test_util.py
+++ b/tests/test_util.py
@@ -257,6 +257,12 @@ class TestCheckCallableArgs(object):
exc = pytest.raises(ValueError, check_callable_args, lambda x, y, z: None, [1], {'y': 0})
assert str(exc.value) == 'The following arguments have not been supplied: z'
+ def test_default_args(self, use_signature):
+ """Tests that default values for arguments are properly taken into account."""
+
+ exc = pytest.raises(ValueError, check_callable_args, lambda x, y, z=1: None, [1], {})
+ assert str(exc.value) == 'The following arguments have not been supplied: y'
+
def test_conflicting_callable_args(self, use_signature):
"""
Tests that attempting to schedule a job where the combination of args and kwargs are in conflict raises an