| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
fractional(0) returned "0/1" because the whole-number branch was gated on `whole_number` being truthy, which excludes 0. Every other integer (1, 2, -2, and so on) already returns a bare number, so 0 was the odd one out. The branch really just needs to check that no fractional part remains (numerator == 0), which holds for any whole number including 0. When the numerator is 0 the fraction is always 0/1, so the denominator == 1 check was redundant and is dropped. Adds test cases for 0, 0.0 and "0". Co-authored-by: eeshsaxena <eeshsaxena@gmail.com>
There was a problem hiding this comment.
Verified locally on the PR branch (Python 3.13, editable install):
Behavior matrix — release 4.16.0 vs this branch:
| input | release | branch |
|---|---|---|
| fractional(0) | "0/1" | "0" |
| fractional(0.0) | "0/1" | "0" |
| fractional("0") | "0/1" | "0" |
| fractional(1.5) | "1 1/2" | unchanged |
| fractional(2.25) | "2 1/4" | unchanged |
| fractional(1.0) / (3) | "1" / "3" | unchanged |
pytest tests/test_number.py -k fractional — 23/23 green, including the three new parametrized zero cases.
The root cause is real: the old guard if whole_number and not numerator and denominator == 1 treated whole_number=0 as falsy, so an all-zero input fell through to the fraction formatter and rendered as 0/1. The new condition if not numerator covers every integer-valued input including zero, and non-zero cases are provably untouched by the matrix above.
Small and correct. Approving.
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Bug
fractional(0) returns "0/1", while every other whole number returns a bare number:
Cause
The whole-number branch is gated on whole_number being truthy:
whole_number is 0 (falsy) for the value 0, so it falls through to the if not whole_number: branch and is rendered as numerator/denominator = 0/1.
Fix
The branch only needs to check that no fractional part remains, i.e. numerator == 0, which is true for any whole number including 0. When the numerator is 0 the fraction is always 0/1, so the denominator == 1 check was redundant and is dropped.
Verified against all existing test_fractional cases (no changes) plus new cases for 0, 0.0 and "0".