summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Grönholm <alex.gronholm@nextday.fi>2021-01-11 00:26:00 +0200
committerAlex Grönholm <alex.gronholm@nextday.fi>2021-01-11 00:35:45 +0200
commit5ef5aed559193b41187a7e3ee7862f823a9845df (patch)
treed632e598ecb941387c789d685406c1880e806ac5
parent8c552d474848d901f09a54ed8827997cf0b3edda (diff)
downloadapscheduler-5ef5aed559193b41187a7e3ee7862f823a9845df.tar.gz
Fixed inability to schedule wrapped functions
Closes #363.
-rw-r--r--apscheduler/util.py6
-rw-r--r--docs/versionhistory.rst2
-rw-r--r--setup.py3
-rw-r--r--tests/test_util.py30
4 files changed, 32 insertions, 9 deletions
diff --git a/apscheduler/util.py b/apscheduler/util.py
index 8b7b3f5..1e643bf 100644
--- a/apscheduler/util.py
+++ b/apscheduler/util.py
@@ -7,6 +7,7 @@ from calendar import timegm
from functools import partial
from inspect import isclass, ismethod
import re
+import sys
from pytz import timezone, utc, FixedOffset
import six
@@ -352,7 +353,10 @@ def check_callable_args(func, args, kwargs):
has_varargs = has_var_kwargs = False
try:
- sig = signature(func)
+ if sys.version_info >= (3, 5):
+ sig = signature(func, follow_wrapped=False)
+ else:
+ sig = signature(func)
except ValueError:
# signature() doesn't work against every kind of callable
return
diff --git a/docs/versionhistory.rst b/docs/versionhistory.rst
index 1d0e505..165639d 100644
--- a/docs/versionhistory.rst
+++ b/docs/versionhistory.rst
@@ -19,6 +19,8 @@ APScheduler, see the :doc:`migration section <migration>`.
* Fixed ``BlockingScheduler`` and ``BackgroundScheduler`` shutdown hanging after the user has
erroneously tried to start it twice
* Fixed memory leak when coroutine jobs raise exceptions (due to reference cycles in tracebacks)
+* Fixed inability to schedule wrapped functions with extra arguments when the wrapped function
+ cannot accept them but the wrapper can (original PR by Egor Malykh)
3.6.3
diff --git a/setup.py b/setup.py
index e0328dd..a33213f 100644
--- a/setup.py
+++ b/setup.py
@@ -44,7 +44,8 @@ setup(
'tzlocal ~= 2.0',
],
extras_require={
- ':python_version == "2.7"': ['futures', 'funcsigs'],
+ ':python_version == "2.7"': ['futures'],
+ ':python_version < "3.5"': ['funcsigs'],
'asyncio:python_version == "2.7"': ['trollius'],
'gevent': ['gevent'],
'mongodb': ['pymongo >= 3.0'],
diff --git a/tests/test_util.py b/tests/test_util.py
index 57a322a..7cadbc2 100644
--- a/tests/test_util.py
+++ b/tests/test_util.py
@@ -1,20 +1,22 @@
# coding: utf-8
import platform
+import sys
from datetime import date, datetime, timedelta, tzinfo
-from functools import partial
+from functools import partial, wraps
from types import ModuleType
import pytest
import pytz
import six
-import sys
from apscheduler.job import Job
-from apscheduler.util import (
- asint, asbool, astimezone, convert_to_datetime, datetime_to_utc_timestamp,
- utc_timestamp_to_datetime, timedelta_seconds, datetime_ceil, get_callable_name, obj_to_ref,
- ref_to_obj, maybe_ref, check_callable_args, datetime_repr, repr_escape)
-from tests.conftest import minpython, maxpython
+from apscheduler.util import (asbool, asint, astimezone, check_callable_args,
+ convert_to_datetime, datetime_ceil,
+ datetime_repr, datetime_to_utc_timestamp,
+ get_callable_name, maybe_ref, obj_to_ref,
+ ref_to_obj, repr_escape, timedelta_seconds,
+ utc_timestamp_to_datetime)
+from tests.conftest import maxpython, minpython
try:
from unittest.mock import Mock
@@ -351,3 +353,17 @@ class TestCheckCallableArgs(object):
exc = pytest.raises(ValueError, check_callable_args, func, [1], {})
assert str(exc.value) == ('The following keyword-only arguments have not been supplied in '
'kwargs: y')
+
+ def test_wrapped_func(self):
+ """
+ Test that a wrapped function can be scheduled even if it cannot accept the arguments given
+ in add_job() if the wrapper can.
+ """
+ def func():
+ pass
+
+ @wraps(func)
+ def wrapper(arg):
+ func()
+
+ check_callable_args(wrapper, (1,), {})