@@ -151,7 +151,8 @@ def naturaldelta(
151151 _ngettext ("%d microsecond" , "%d microseconds" , delta .microseconds )
152152 % delta .microseconds
153153 )
154- elif min_unit == Unit .MILLISECONDS or (
154+
155+ if min_unit == Unit .MILLISECONDS or (
155156 min_unit == Unit .MICROSECONDS and 1000 <= delta .microseconds < 1_000_000
156157 ):
157158 milliseconds = delta .microseconds / 1000
@@ -160,47 +161,59 @@ def naturaldelta(
160161 % milliseconds
161162 )
162163 return _ ("a moment" )
163- elif seconds == 1 :
164+
165+ if seconds == 1 :
164166 return _ ("a second" )
165- elif seconds < 60 :
167+
168+ if seconds < 60 :
166169 return _ngettext ("%d second" , "%d seconds" , seconds ) % seconds
167- elif 60 <= seconds < 120 :
170+
171+ if 60 <= seconds < 120 :
168172 return _ ("a minute" )
169- elif 120 <= seconds < 3600 :
173+
174+ if 120 <= seconds < 3600 :
170175 minutes = seconds // 60
171176 return _ngettext ("%d minute" , "%d minutes" , minutes ) % minutes
172- elif 3600 <= seconds < 3600 * 2 :
177+
178+ if 3600 <= seconds < 3600 * 2 :
173179 return _ ("an hour" )
174- elif 3600 < seconds :
180+
181+ if 3600 < seconds :
175182 hours = seconds // 3600
176183 return _ngettext ("%d hour" , "%d hours" , hours ) % hours
184+
177185 elif years == 0 :
178186 if days == 1 :
179187 return _ ("a day" )
188+
180189 if not use_months :
181190 return _ngettext ("%d day" , "%d days" , days ) % days
182- else :
183- if not num_months :
184- return _ngettext ("%d day" , "%d days" , days ) % days
185- elif num_months == 1 :
186- return _ ("a month" )
187- else :
188- return _ngettext ("%d month" , "%d months" , num_months ) % num_months
191+
192+ if not num_months :
193+ return _ngettext ("%d day" , "%d days" , days ) % days
194+
195+ if num_months == 1 :
196+ return _ ("a month" )
197+
198+ return _ngettext ("%d month" , "%d months" , num_months ) % num_months
199+
189200 elif years == 1 :
190201 if not num_months and not days :
191202 return _ ("a year" )
192- elif not num_months :
203+
204+ if not num_months :
193205 return _ngettext ("1 year, %d day" , "1 year, %d days" , days ) % days
194- elif use_months :
206+
207+ if use_months :
195208 if num_months == 1 :
196209 return _ ("1 year, 1 month" )
197- else :
198- return (
199- _ngettext ("1 year, %d month" , "1 year, %d months" , num_months )
200- % num_months
201- )
202- else :
203- return _ngettext ("1 year, %d day" , "1 year, %d days" , days ) % days
210+
211+ return (
212+ _ngettext ("1 year, %d month" , "1 year, %d months" , num_months )
213+ % num_months
214+ )
215+
216+ return _ngettext ("1 year, %d day" , "1 year, %d days" , days ) % days
204217
205218 return _ngettext ("%d year" , "%d years" , years ).replace ("%d" , "%s" ) % intcomma (years )
206219
@@ -265,12 +278,16 @@ def naturalday(value: dt.date | dt.datetime, format: str = "%b %d") -> str:
265278 # Date arguments out of range
266279 return str (value )
267280 delta = value - dt .date .today ()
281+
268282 if delta .days == 0 :
269283 return _ ("today" )
270- elif delta .days == 1 :
284+
285+ if delta .days == 1 :
271286 return _ ("tomorrow" )
272- elif delta .days == - 1 :
287+
288+ if delta .days == - 1 :
273289 return _ ("yesterday" )
290+
274291 return value .strftime (format )
275292
276293
@@ -323,10 +340,11 @@ def _quotient_and_remainder(
323340 """
324341 if unit == minimum_unit :
325342 return value / divisor , 0
326- elif unit in suppress :
343+
344+ if unit in suppress :
327345 return 0 , value
328- else :
329- return divmod (value , divisor )
346+
347+ return divmod (value , divisor )
330348
331349
332350def _carry (
@@ -361,10 +379,11 @@ def _carry(
361379 """
362380 if unit == min_unit :
363381 return value1 + value2 / ratio , 0
364- elif unit in suppress :
382+
383+ if unit in suppress :
365384 return 0 , value2 + value1 * ratio
366- else :
367- return value1 , value2
385+
386+ return value1 , value2
368387
369388
370389def _suitable_minimum_unit (min_unit : Unit , suppress : typing .Iterable [Unit ]) -> Unit :
@@ -405,16 +424,16 @@ def _suppress_lower_units(min_unit: Unit, suppress: typing.Iterable[Unit]) -> se
405424 ['MICROSECONDS', 'MILLISECONDS', 'DAYS']
406425 """
407426 suppress = set (suppress )
408- for u in Unit :
409- if u == min_unit :
427+ for unit in Unit :
428+ if unit == min_unit :
410429 break
411- suppress .add (u )
430+ suppress .add (unit )
412431
413432 return suppress
414433
415434
416435def precisedelta (
417- value : dt .timedelta | int ,
436+ value : dt .timedelta | int | None ,
418437 minimum_unit : str = "seconds" ,
419438 suppress : typing .Iterable [str ] = (),
420439 format : str = "%0.2f" ,
0 commit comments