question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inconsistencies between documentation/annotations and behavior

See original GitHub issue

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:

  1. Document that humanize.naturaltime() accepts timedelta, not only datetime | int and update type annotation.
  2. 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

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
hugovkcommented, Jun 30, 2022

And the naturaldelta() + timedelta fix has been released in 4.2.3. Thanks!

0reactions
sodulcommented, Jul 11, 2022

@hugovk I posted details in the conversation for #15.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found