[Python-Dev] Re: [Patches] [Patch #102955] bltinmodule.c warning fix
Tim Peters
tim.one@home.com
Sat, 23 Dec 2000 02:15:59 -0500
[Tim]
> ...
> So we should say "8-bit string" or "Unicode string" when *only*
> one of those is allowable. So
>
> "ord() expected string ..."
>
> instead of (even a repaired version of)
>
> "ord() expected string or Unicode character ..."
[MAL]
> I think this has to do with understanding that there are two
> string types in Python 2.0 -- a novice won't notice this until
> she sees the error message.
Except that this error msg has nothing to do with how many string types
there are: they didn't pass *any* flavor of string when they get this msg.
At the time they pass (say) a float to ord(), that there are currently two
flavors of string is more information than they need to know.
> My understanding is similar to yours, "string" should mean
> "any string object" and in cases where the difference between
> 8-bit string and Unicode matters, these should be referred to
> as "8-bit string" and "Unicode string".
In that happy case of universal harmony, the msg above should say just
"string" and leave it at that.
> Still, I think it is a good idea to make people aware of the
> possibility of passing Unicode objects to these functions,
Me too.
> so perhaps the idea of adding both possibilies to error messages
> is not such a bad idea for 2.1.
But not that. The user is trying to track down their problem. Advertising
an irrelevant (to their problem) distinction at that time of crisis is
simply spam.
TypeError: ord() requires an 8-bit string or a Unicode string.
On the other hand, you'd be surprised to discover
all the things you can pass to chr(): it's not just
ints. Long ints are also accepted, by design, and
due to an obscure bug in the Python internals, you
can also pass floats, which get truncated to ints.
> The next phases would be converting all messages back to "string"
> and then convert all strings to Unicode ;-)
Then we'll save a lot of work by skipping the need for the first half of
that -- unless you're volunteering to do all of it <wink>.