Skip to content

Commit

Permalink
Do not crash repr on partially constructed job (#569)
Browse files Browse the repository at this point in the history
  • Loading branch information
CPickens42 authored Apr 9, 2023
1 parent a3ecd35 commit 3863eff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 7 additions & 3 deletions schedule/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,13 @@ def is_repr(j):
job_func_name = self.job_func.__name__
else:
job_func_name = repr(self.job_func)
args = [repr(x) if is_repr(x) else str(x) for x in self.job_func.args]
kwargs = ["%s=%s" % (k, repr(v)) for k, v in self.job_func.keywords.items()]
call_repr = job_func_name + "(" + ", ".join(args + kwargs) + ")"

if self.job_func is not None:
args = [repr(x) if is_repr(x) else str(x) for x in self.job_func.args]
kwargs = ["%s=%s" % (k, repr(v)) for k, v in self.job_func.keywords.items()]
call_repr = job_func_name + "(" + ", ".join(args + kwargs) + ")"
else:
call_repr = "[None]"

if self.at_time is not None:
return "Every %s %s at %s do %s %s" % (
Expand Down
4 changes: 4 additions & 0 deletions test_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,10 @@ def job_fun():
)
)

# Ensure Job.__repr__ does not throw exception on a partially-composed Job
s3 = repr(schedule.every(10))
assert s3 == "Every 10 None do [None] (last run: [never], next run: [never])"

def test_to_string_lambda_job_func(self):
assert len(str(every().minute.do(lambda: 1))) > 1
assert len(str(every().day.at("10:30").do(lambda: 1))) > 1
Expand Down

0 comments on commit 3863eff

Please sign in to comment.