From 4d36dc0f69cc9c724d93c774ec9420ba8b2bd24f Mon Sep 17 00:00:00 2001 From: Hiren Date: Sat, 28 Feb 2026 20:39:00 -0500 Subject: [PATCH] fix: guard self.unit against None in __repr__ Added None check before slicing self.unit to prevent crash when self.unit is None and self.interval == 1. Fixes #646 --- schedule/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/schedule/__init__.py b/schedule/__init__.py index 8e12eeb7..7d8b745b 100644 --- a/schedule/__init__.py +++ b/schedule/__init__.py @@ -302,7 +302,7 @@ def is_repr(j): if self.at_time is not None: return "Every %s %s at %s do %s %s" % ( self.interval, - self.unit[:-1] if self.interval == 1 else self.unit, + self.unit[:-1] if self.interval == 1 and self.unit else self.unit, self.at_time, call_repr, timestats, @@ -317,7 +317,7 @@ def is_repr(j): return fmt % dict( interval=self.interval, latest=self.latest, - unit=(self.unit[:-1] if self.interval == 1 else self.unit), + unit=(self.unit[:-1] if self.interval == 1 and self.unit else self.unit), call_repr=call_repr, timestats=timestats, )