Inconsistencies between documentation/annotations and behavior
See original GitHub issuenaturaltime()
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()
acceptstimedelta
, not onlydatetime | int
and update type annotation. - Make
humanize.naturaltime()
rejectingtimedelta
(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
Issue Analytics
- State:
- Created a year ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
The inconsistency of documentation: a study of online C ...
Study of documentation issues. Previous work discover the documentation issues mainly through detecting the inconsistency between code and ...
Read more >Automatic consistency assurance for literature-based gene ...
In this work, we introduce a formalisation of biological database annotation inconsistencies, identifying four distinct types of inconsistency.
Read more >Understanding How Programmers Can Use Annotations on ...
We investigate sharing this documentation-specific information through annotations, which have advantages over developer forums as the information is ...
Read more >annotations - Spring @Transactional v Spring Security ...
Spring @Transactional v Spring Security @Secured inconsistent behaviour ... Spring documentation advises putting the @Transactional annotation on ...
Read more >GitHub - norahollenstein/inconsistency-detection
Inconsistencies are part of any manually annotated corpus. Automatically finding these inconsistencies and correcting them (even manually) can increase the ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
And the
naturaldelta()
+timedelta
fix has been released in 4.2.3. Thanks!@hugovk I posted details in the conversation for #15.