[Python-Dev] Dict suppressing exceptions

Guido van Rossum guido at python.org
Thu Aug 10 16:36:29 CEST 2006


On 8/10/06, M.-A. Lemburg <mal at egenix.com> wrote:
> I'd suggest that we still inform the programmers of the problem
> by issuing a warning (which they can then silence at will),
> maybe a new PyExc_UnicodeWarning.

Hmm... Here's an idea... How about we change unicode-vs-str __eq__ to
issue a warning (and return False) instead of raising
UnicodeException? That won't break much code (it's unlikely that
people *depend* on this exception since it's generally a symptom of
insane mixing of str and unicode). Then no further changes to
dictobject.c are necessary (except fixing that one misleading
comment).

> Note that these exceptions help programmers making their applications
> Unicode compatible, so silencing them completely would remove the
> possibility to detect the case of mixing strings and Unicode as
> keys in a dictionary.

A warning would arguably have the same helping effect. (I suspect
actually that we would have used warnings all along except we didn't
have the warning framework when unicode was first introduced.)

> BTW, in Py3k, this case would not trigger at all, since all text
> would be Unicode and bytes wouldn't be comparable to Unicode
> anyway. However, that's a different discussion which we can have
> after Python 2.5 is out the door.

Which is why I said I would have gladly waited until Py3k to fix this.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list