naturaltime() supports timedelta.
It is not documented, but humanize.naturaltime() accepts timedelta. I used it for years until type annotations were added, and MyPy started to complain. timedelta is still accepted at runtime.
>>> import datetime, humanize
>>> humanize.naturaltime(datetime.timedelta(days=5, hours=3))
'5 days ago'
>>> humanize.naturaltime(datetime.timedelta(hours=123))
'5 days ago'
I expect one of two things:
- Document that
humanize.naturaltime() accepts timedelta, not only datetime | int and update type annotation.
- Make
humanize.naturaltime() rejecting timedelta (of course, after some deprecation period).
Option 1 is more compatible, but option 2 looks more logical.
naturaltime() and naturaldelta() accept not only int, but float too.
>>> humanize.naturaltime(23.5)
'23 seconds ago'
>>> humanize.naturaldelta(23.5)
'23 seconds'
It is expected, since timestamp in Python is float, but it should be documented, and annotations should be updated.
naturaltime(), naturaldelta() , naturaldate() and naturalday() accept arbitrary object without error.
>>> humanize.naturaltime([1, 2, 3])
'[1, 2, 3]'
>>> humanize.naturaldelta([1, 2, 3])
'[1, 2, 3]'
>>> humanize.naturaldate([1, 2, 3])
'[1, 2, 3]'
>>> humanize.naturalday([1, 2, 3])
'[1, 2, 3]'
It is unsafe, because allows programming errors to slip unnoticed. humanize.naturalsize() raises an error, as expected.
Humanize 4.2.1
naturaltime()supportstimedelta.It is not documented, but
humanize.naturaltime()acceptstimedelta. I used it for years until type annotations were added, and MyPy started to complain.timedeltais still accepted at runtime.I expect one of two things:
humanize.naturaltime()acceptstimedelta, not onlydatetime | intand update type annotation.humanize.naturaltime()rejectingtimedelta(of course, after some deprecation period).Option 1 is more compatible, but option 2 looks more logical.
naturaltime()andnaturaldelta()accept not onlyint, butfloattoo.It is expected, since timestamp in Python is
float, but it should be documented, and annotations should be updated.naturaltime(),naturaldelta(),naturaldate()andnaturalday()accept arbitrary object without error.It is unsafe, because allows programming errors to slip unnoticed.
humanize.naturalsize()raises an error, as expected.Humanize 4.2.1