This section lists previously described changes and other bugfixes that may require changes to your code:
- The
range()
function processes its arguments more consistently; it will now call__int__()
on non-float, non-integer arguments that are supplied to it. (Fixed by Alexander Belopolsky; bpo-1533.) - The string
format()
method changed the default precision used for floating-point and complex numbers from 6 decimal places to 12, which matches the precision used bystr()
. (Changed by Eric Smith; bpo-5920.) - Because of an optimization for the
with
statement, the special methods__enter__()
and__exit__()
must belong to the object’s type, and cannot be directly attached to the object’s instance. This affects new-style classes (derived fromobject
) and C extension types. (bpo-6101.) - Due to a bug in Python 2.6, the exc_value parameter to
__exit__()
methods was often the string representation of the exception, not an instance. This was fixed in 2.7, so exc_value will be an instance as expected. (Fixed by Florent Xicluna; bpo-7853.) - When a restricted set of attributes were set using
__slots__
, deleting an unset attribute would not raiseAttributeError
as you would expect. Fixed by Benjamin Peterson; bpo-7604.)
In the standard library:
- Operations with
datetime
instances that resulted in a year falling outside the supported range didn’t always raiseOverflowError
. Such errors are now checked more carefully and will now raise the exception. (Reported by Mark Leander, patch by Anand B. Pillai and Alexander Belopolsky; bpo-7150.) - When using
Decimal
instances with a string’sformat()
method, the default alignment was previously left-alignment. This has been changed to right-alignment, which might change the output of your programs. (Changed by Mark Dickinson; bpo-6857.)Comparisons involving a signaling NaN value (orsNAN
) now signalInvalidOperation
instead of silently returning a true or false value depending on the comparison operator. Quiet NaN values (orNaN
) are now hashable. (Fixed by Mark Dickinson; bpo-7279.) - The ElementTree library,
xml.etree
, no longer escapes ampersands and angle brackets when outputting an XML processing instruction (which looks like <?xml-stylesheet href=”#style1”?>) or comment (which looks like <!– comment –>). (Patch by Neil Muller; bpo-2746.) - The
tarfile
module’s default error handling has changed, to no longer suppress fatal errors. The default error level was previously 0, which meant that errors would only result in a message being written to the debug log, but because the debug log is not activated by default, these errors go unnoticed. The default error level is now 1, which raises an exception if there’s an error. (Changed by Lars Gustäbel; bpo-7357.) - The
urlparse
module’surlsplit()
now handles unknown URL schemes in a fashion compliant with RFC 3986: if the URL is of the form"<something>://..."
, the text before the://
is treated as the scheme, even if it’s a made-up scheme that the module doesn’t know about. This change may break code that worked around the old behaviour. For example, Python 2.6.4 or 2.5 will return the following:Python 2.7 (and Python 2.6.5) will return:(Python 2.7 actually produces slightly different output, since it returns a named tuple instead of a standard tuple.)
For C extensions:
- C extensions that use integer format codes with the
PyArg_Parse*
family of functions will now raise aTypeError
exception instead of triggering aDeprecationWarning
(bpo-5080). - Use the new
PyOS_string_to_double()
function instead of the oldPyOS_ascii_strtod()
andPyOS_ascii_atof()
functions, which are now deprecated.
For applications that embed Python:
- The
PySys_SetArgvEx()
function was added, letting applications close a security hole when the existingPySys_SetArgv()
function was used. Check whether you’re callingPySys_SetArgv()
and carefully consider whether the application should be usingPySys_SetArgvEx()
with updatepath set to false.
No comments:
Post a Comment