mirror of
https://github.com/python/cpython.git
synced 2025-09-29 11:45:57 +00:00
Add UnicodeWarning
This commit is contained in:
parent
581795902d
commit
efd68c789e
1 changed files with 34 additions and 0 deletions
|
@ -1184,6 +1184,35 @@ a line like this near the top of the source file:
|
||||||
# -*- coding: latin1 -*-
|
# -*- coding: latin1 -*-
|
||||||
\end{verbatim}
|
\end{verbatim}
|
||||||
|
|
||||||
|
\item A new warning, \class{UnicodeWarning}, is triggered when
|
||||||
|
you attempt to compare a Unicode string and an 8-bit string
|
||||||
|
that can't be converted to Unicode using the default ASCII encoding.
|
||||||
|
The result of the comparison is false:
|
||||||
|
|
||||||
|
\begin{verbatim}
|
||||||
|
>>> chr(128) == unichr(128) # Can't convert chr(128) to Unicode
|
||||||
|
__main__:1: UnicodeWarning: Unicode equal comparison failed
|
||||||
|
to convert both arguments to Unicode - interpreting them
|
||||||
|
as being unequal
|
||||||
|
False
|
||||||
|
>>> chr(127) == unichr(127) # chr(127) can be converted
|
||||||
|
True
|
||||||
|
\end{verbatim}
|
||||||
|
|
||||||
|
Previously this would raise a \class{UnicodeDecodeError} exception,
|
||||||
|
but in 2.5 this could result in puzzling problems when accessing a
|
||||||
|
dictionary. If you looked up \code{unichr(128)} and \code{chr(128)}
|
||||||
|
was being used as a key, you'd get a \class{UnicodeDecodeError}
|
||||||
|
exception. Other changes in 2.5 resulted in this exception being
|
||||||
|
raised instead of suppressed by the code in \file{dictobject.c} that
|
||||||
|
implements dictionaries.
|
||||||
|
|
||||||
|
Raising an exception for such a comparison is strictly correct, but
|
||||||
|
the change might have broken code, so instead
|
||||||
|
\class{UnicodeWarning} was introduced.
|
||||||
|
|
||||||
|
(Implemented by Marc-Andr\'e Lemburg.)
|
||||||
|
|
||||||
\item One error that Python programmers sometimes make is forgetting
|
\item One error that Python programmers sometimes make is forgetting
|
||||||
to include an \file{__init__.py} module in a package directory.
|
to include an \file{__init__.py} module in a package directory.
|
||||||
Debugging this mistake can be confusing, and usually requires running
|
Debugging this mistake can be confusing, and usually requires running
|
||||||
|
@ -2423,6 +2452,11 @@ was always a frame object. Because of the \pep{342} changes
|
||||||
described in section~\ref{pep-342}, it's now possible
|
described in section~\ref{pep-342}, it's now possible
|
||||||
for \member{gi_frame} to be \code{None}.
|
for \member{gi_frame} to be \code{None}.
|
||||||
|
|
||||||
|
\item A new warning, \class{UnicodeWarning}, is triggered when
|
||||||
|
you attempt to compare a Unicode string and an 8-bit string that can't
|
||||||
|
be converted to Unicode using the default ASCII encoding. Previously
|
||||||
|
such comparisons would raise a \class{UnicodeDecodeError} exception.
|
||||||
|
|
||||||
\item Library: the \module{csv} module is now stricter about multi-line quoted
|
\item Library: the \module{csv} module is now stricter about multi-line quoted
|
||||||
fields. If your files contain newlines embedded within fields, the
|
fields. If your files contain newlines embedded within fields, the
|
||||||
input should be split into lines in a manner which preserves the
|
input should be split into lines in a manner which preserves the
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue