You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The error message for odd-length input to bytes.fromhex is cryptic #127740
Python 3.14.0a2+ (main, Dec 8 2024, 10:50:32) [GCC 14.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> bytes.fromhex('deadbee')
Traceback (most recent call last):
File "<python-input-0>", line 1, in <module>bytes.fromhex('deadbee')
~~~~~~~~~~~~~^^^^^^^^^^^ValueError: non-hexadecimal number found in fromhex() arg at position 7
>>> bytes.fromhex('deadbeef')
b'\xde\xad\xbe\xef'
I suggest: ValueError: fromhex() arg must be of even length.
Marking this one as a feature rather than a bug since changing exception messages may break CI (python/mypy#17849) and users may rely on exception messages.
We don't want to change error messages unnecessarily; however, if the error message is bad, it should get fixed. To misquote Spock, the needs of many people reading error messages outweigh the needs of the few who overspecify their tests.
Bad error messages are a major source of user frustration.
Reacted by Hugo van Kemenade, Srinivas Reddy Thatiparthy (తాటిపర్తి శ్రీనివాస్ రెడ్డి), Kirill Podoprigora and Oskar Skog
Reacted by Hugo van Kemenade and Kirill Podoprigora
I'm not against changing the error message but I honestly think we don't need to backport it to 3.12 and 3.13 (personally I wouldn't be against the backports but I learned the hard way that changing error messages in bug fix releases could cause un-necessary additional work =/).
Reacted by Peter Bierma, Srinivas Reddy Thatiparthy (తాటిపర్తి శ్రీనివాస్ రెడ్డి) and Kirill Podoprigora
Thanks for fixing this, like Raymond says, better error messages are very valuable
cfbolz chose not to backport the PR, which seems fine to me. After all, the worse error message was around for 18 years old. So closing the issue, but if someone feels strongly about backport, please mention so
Activity
srinivasreddy commentedon Dec 8, 2024
@Kodiologist are you working on it ?
Kodiologist commentedon Dec 8, 2024
Nope, it's up for grabs right now.
srinivasreddy commentedon Dec 8, 2024
Thanks 🙏. I am taking it then
picnixz commentedon Dec 8, 2024
Marking this one as a feature rather than a bug since changing exception messages may break CI (python/mypy#17849) and users may rely on exception messages.
rhettinger commentedon Dec 8, 2024
Users may, but users shouldn't ;-).
We don't want to change error messages unnecessarily; however, if the error message is bad, it should get fixed. To misquote Spock, the needs of many people reading error messages outweigh the needs of the few who overspecify their tests.
Bad error messages are a major source of user frustration.
picnixz commentedon Dec 8, 2024
I'm not against changing the error message but I honestly think we don't need to backport it to 3.12 and 3.13 (personally I wouldn't be against the backports but I learned the hard way that changing error messages in bug fix releases could cause un-necessary additional work =/).
pythongh-127740: For odd-length input to bytes.fromhex(...) change th…
pythongh-127740: Improve code, consolidate two variables into one
pythongh-127740: Improve error messages as suggested by @hauntsaninja
pythongh-127740: NULL at the end is mapped to 37
pythongh-127740: Reintroduce the space back
pythongh-127740: Check if we had a second digit
gh-127740: For odd-length input to bytes.fromhex(...) change the erro…
pythongh-127740: Add some more tests for earlier PR python#127756
Merge branch 'main' into pythongh-127740
gh-127740: Add some more tests for earlier PR #127756 (#127818)
hauntsaninja commentedon Dec 12, 2024
Thanks for fixing this, like Raymond says, better error messages are very valuable
cfbolz chose not to backport the PR, which seems fine to me. After all, the worse error message was around for 18 years old. So closing the issue, but if someone feels strongly about backport, please mention so
pythongh-127740: For odd-length input to bytes.fromhex(...) change th…
pythongh-127740: Add some more tests for earlier PR python#127756 (py…