Commit 8802bcd
committed
Fix best_prefix() to preserve unit family; closes #95
Bit-family instances (Bit, Kib, Mib, kb, Mb, etc.) now always return
a Bit-family result from best_prefix(). Previously the conversion
method name was built with a hardcoded 'B' suffix, so e.g.
Bit(30950093).best_prefix() returned MiB instead of Mib.
Changes:
- Replace 'type(self) is Byte' exact-type check with isinstance(self, Byte),
removing the pylint unidiomatic-typecheck suppression
- At _index == 0 (below the first prefix threshold), Bit-family inputs
now return Bit.from_other(self) rather than Byte, preserving family
consistency down to the floor
- Conversion method name now uses 'b' suffix for Bit-family and 'B'
suffix for Byte-family inputs
- Updated best_prefix() docstring with revised index-0 rule and a
versionchanged:: 2.0.0 note
- Updated test_bit_round_up to document the new family-preserving
behaviour (Bit(16).best_prefix() -> Bit, not Byte)1 parent 490b8e5 commit 8802bcd
2 files changed
Lines changed: 32 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
379 | 379 | | |
380 | 380 | | |
381 | 381 | | |
382 | | - | |
| 382 | + | |
383 | 383 | | |
384 | 384 | | |
385 | 385 | | |
| |||
430 | 430 | | |
431 | 431 | | |
432 | 432 | | |
433 | | - | |
| 433 | + | |
| 434 | + | |
434 | 435 | | |
435 | 436 | | |
436 | 437 | | |
| |||
444 | 445 | | |
445 | 446 | | |
446 | 447 | | |
447 | | - | |
| 448 | + | |
448 | 449 | | |
449 | 450 | | |
450 | 451 | | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
451 | 462 | | |
452 | 463 | | |
453 | 464 | | |
454 | 465 | | |
455 | 466 | | |
456 | 467 | | |
457 | 468 | | |
458 | | - | |
| 469 | + | |
459 | 470 | | |
460 | 471 | | |
461 | 472 | | |
| |||
491 | 502 | | |
492 | 503 | | |
493 | 504 | | |
494 | | - | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
495 | 509 | | |
496 | 510 | | |
497 | 511 | | |
| |||
500 | 514 | | |
501 | 515 | | |
502 | 516 | | |
503 | | - | |
504 | | - | |
505 | | - | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
506 | 523 | | |
507 | 524 | | |
508 | 525 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
46 | 51 | | |
47 | 52 | | |
48 | | - | |
49 | | - | |
| 53 | + | |
50 | 54 | | |
51 | 55 | | |
52 | 56 | | |
| |||
0 commit comments