From 2a0eedef04de6f29cd838c0fab3a89c1364f2d01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20C=C3=A9sar=20Su=C3=A1stegui?= Date: Mon, 30 Mar 2026 02:50:03 -0600 Subject: [PATCH] fix: guard against self.unit being None in Job.__repr__ When Job.interval == 1 and self.unit is None (the initial state), __repr__ attempted self.unit[:-1] which raised: TypeError: 'NoneType' object is not subscriptable Guard both format paths in __repr__ against self.unit being None by substituting '[unit not set]' as a safe placeholder. Fixes #646 --- schedule/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/schedule/__init__.py b/schedule/__init__.py index 8e12eeb7..4afd0602 100644 --- a/schedule/__init__.py +++ b/schedule/__init__.py @@ -300,9 +300,10 @@ def is_repr(j): call_repr = "[None]" if self.at_time is not None: + unit_str = (self.unit[:-1] if self.interval == 1 else self.unit) if self.unit else "[unit not set]" return "Every %s %s at %s do %s %s" % ( self.interval, - self.unit[:-1] if self.interval == 1 else self.unit, + unit_str, self.at_time, call_repr, timestats, @@ -317,7 +318,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 else self.unit) if self.unit else "[unit not set]", call_repr=call_repr, timestats=timestats, )