This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: error message of ord is not intuitive
Type: Stage: resolved
Components: Versions: Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: r.david.murray, serhiy.storchaka, xiang.zhang
Priority: normal Keywords:

Created on 2016-05-12 08:04 by xiang.zhang, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (9)
msg265376 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2016-05-12 08:04
The error message of ``ord`` is not that right. It says 'ord() expected string of length 1'. I don't think in Py3.x string can refer to both bytes and unicodes.
msg265377 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-05-12 08:18
This not the only place where "string" means unicode string or bytes string. I don't think this is large issue.
msg265378 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2016-05-12 08:23
If you think it's OK, it's fine. Please close this thread.
msg265380 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2016-05-12 08:35
BTW, what do you think about the second TypeError in ``ord``. Shouldn't it be ValueError?
msg265382 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-05-12 08:53
In any case it doesn't make much sense to change just one separate docstring. If you want to avoid misleading and support consistent wording, you should examine all occurrences of the word "string" in the documentation, docstrings, error messages and comments -- does it mean Unicode string, bytes-like object that supports the buffer protocol (including memoryview), bytes-like object that supports str-like interface (including bytes, bytearray, but excluding memoryview), either Unicode or bytes string? I tried to do this but abandoned the work on half-way. This is too large work.

> BTW, what do you think about the second TypeError in ``ord``. Shouldn't it be ValueError?

It could be ValueError. But for compatibility it should stay TypeError. This is not wrong if we consider strings of size 1 as separate type.
msg265384 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2016-05-12 09:11
Ohh, you have tried to do that. It must be a large work.

But on the other hand, if this is a too large work, why not solve this case by case? This work is too large to get someone work on it, even you, the most active developer in the community I see have abandoned. And then maybe improving the situation a little bit every time is the only solution.

> This is not wrong if we consider strings of size 1 as separate type

This sounds weird. But I can understand the importance of compatibility.
msg265401 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2016-05-12 12:46
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 :)
msg265409 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2016-05-12 14:38
I also notice the document. I get surprised when I see the implementation also supports bytes while the doc says one unicode character. But then I tell myself that maybe unicode character also includes bytes? I am not sure about the English description.

But giving your opinion that maybe the bytes supports are not intended now, I think leaving the error message untouched is quite OK. It describes what it is intended to do, same as the doc.

Really glad to have your comments, Serhiy and David.
msg265415 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2016-05-12 16:11
All right, we'll close this then.
History
Date User Action Args
2022-04-11 14:58:31adminsetgithub: 71195
2016-05-12 16:11:08r.david.murraysetstatus: open -> closed
resolution: not a bug
messages: + msg265415

stage: resolved
2016-05-12 14:38:15xiang.zhangsetmessages: + msg265409
2016-05-12 12:46:13r.david.murraysetmessages: + msg265401
2016-05-12 09:11:55xiang.zhangsetmessages: + msg265384
2016-05-12 08:53:47serhiy.storchakasetnosy: + r.david.murray
messages: + msg265382
2016-05-12 08:35:05xiang.zhangsetmessages: + msg265380
2016-05-12 08:23:56xiang.zhangsetmessages: + msg265378
2016-05-12 08:18:19serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg265377
2016-05-12 08:04:50xiang.zhangcreate