naturalsize() truncates non-integer byte counts below the base ("1 Bytes")

Aperta Adatta ai principianti
#459 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

  • #507 di @ekanshul — chiusa senza merge

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

Parti dall’implementazione di naturalsize() e dai relativi test; l’issue indica la conversione int() e il controllo del singolare come comportamento rilevante. Confronta il percorso di formattazione per i valori superiori alla base con quello per i valori inferiori, quindi aggiungi test per quantità frazionarie di byte, incluso gnu=True. Il lavoro è completato quando gli input frazionari mantengono la parte decimale, mentre gli input interi conservano l’output attuale.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

On current main:

>>> import humanize
>>> humanize.naturalsize(1.5)
'1 Bytes'
>>> humanize.naturalsize(1.9)
'1 Bytes'
>>> humanize.naturalsize(1500)
'1.5 kB'

From 1 kB upwards the fraction is kept using format, but below the base the value is truncated with int(). The singular check also compares the untruncated value with 1, so 1.5 is shown as "1 Bytes".

In #239 you mentioned that "1.1 Bytes" would be better than "1 Bytes" for non-integer input, and that tests for non-integer input were missing.

Proposal:

  • Format non-integer values below the base with format, like larger units (e.g. "1.5 Bytes", and "1.5B" with gnu=True).
  • Keep integer input unchanged ("300 Bytes", "1 Byte").
  • Add tests for non-integer input.

Would you be happy with this? If so, we'd like to send a PR.

Lingua principale
Python
Stelle
768
Fork
243
Merge medio
4g 12h
PR unite (30g)
19

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di python-humanize/humanize

Tutte le issue di python-humanize/humanize

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.