[issue27008] error message of ord is not intuitive

R. David Murray report at bugs.python.org
Thu May 12 08:46:13 EDT 2016


R. David Murray added the comment:

You are right, if it is too big a job to do it all at once, then we can fix them as we find them.  Do you want to propose a patch?

However, in this case I think there is arguably not a bug.  It looks as though the intent is that ord only support strings (see the documentation).  The fact that it supports bytes-like objects is redudant (ord(b'a') == b'a'[0]).  I'd call it a bug that it supports bytes-like objects, but we probably kept (and should keep it) it to make it easier to port python2 code to python3.

So, if any change were to be made here, it would probably be to change the error message if and only if the input is not in fact a string, and perhaps even recommend using the indexing syntax.

On the gripping hand, I've never been a fan of the fact that indexing a byte string gets you an integer :)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27008>
_______________________________________


More information about the Python-bugs-list mailing list