django.utils.http.int_to_base36 raises ValueError instead of TypeError for invalid input
|Reported by:||aaugustin||Owned by:||aaugustin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
This behavior seems wrong to me, and unfortunately, it's tested.
Keeping it in Python 3 is needlessly complicated. Python 3 will rightly raise a TypeError for invalid comparisons. Catching it and re-raising a less appropriate ValueError seems just wrong to me.
>>> 0 <= '' <= 2**31 - 1 False
>>> 0 <= '' <= 2**31 - 1 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unorderable types: int() <= str()
I'm attaching a patch that adds Python 3 compatibility (we can't use sys.maxint any longer) and improves the handling of invalid inputs under Python 2.
Change History (6)
Changed 21 months ago by aaugustin
comment:1 Changed 21 months ago by claudep
- Has patch set
- Triage Stage changed from Unreviewed to Accepted