From c7cd3790168d26cae5fc6df61aa3f35d122b655c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannes=20H=C3=B6ke?= Date: Wed, 14 Dec 2016 06:30:18 +0100 Subject: [PATCH] jobqueue.py: move the check for job.interval types into Job.__init__ --- telegram/ext/jobqueue.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/telegram/ext/jobqueue.py b/telegram/ext/jobqueue.py index f15191191..4065e4d31 100644 --- a/telegram/ext/jobqueue.py +++ b/telegram/ext/jobqueue.py @@ -79,17 +79,9 @@ class JobQueue(object): job.job_queue = self if next_t is None: - interval = job.interval + next_t = job.interval - if isinstance(interval, Number): - next_t = interval - elif isinstance(interval, datetime.timedelta): - next_t = interval.total_seconds() - else: - raise ValueError("The interval argument should be of type datetime.timedelta," - " int or float") - - elif isinstance(next_t, datetime.datetime): + if isinstance(next_t, datetime.datetime): next_t = next_t - datetime.datetime.now() elif isinstance(next_t, datetime.time): @@ -274,6 +266,10 @@ class Job(object): if interval is None and repeat: raise ValueError("You must either set an interval or set 'repeat' to 'False'") + if not (isinstance(interval, Number) or isinstance(interval, datetime.timedelta)): + raise ValueError("The 'interval' argument must be of type 'datetime.timedelta'," + " 'int' or 'float'") + self.days = days self.name = callback.__name__ self._remove = Event()