summaryrefslogtreecommitdiffstats
path: root/Doc/whatsnew/2.6.rst
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/whatsnew/2.6.rst')
-rw-r--r--Doc/whatsnew/2.6.rst173
1 files changed, 160 insertions, 13 deletions
diff --git a/Doc/whatsnew/2.6.rst b/Doc/whatsnew/2.6.rst
index 2098508..29a2693 100644
--- a/Doc/whatsnew/2.6.rst
+++ b/Doc/whatsnew/2.6.rst
@@ -728,6 +728,12 @@ or using a :class:`bytes` constructor. For future compatibility,
Python 2.6 adds :class:`bytes` as a synonym for the :class:`str` type,
and it also supports the ``b''`` notation.
+There's also a ``__future__`` import that causes all string literals
+to become Unicode strings. This means that ``\u`` escape sequences
+can be used to include Unicode characters.
+
+XXX give example
+
.. seealso::
:pep:`3112` - Bytes literals in Python 3000
@@ -740,7 +746,70 @@ and it also supports the ``b''`` notation.
PEP 3116: New I/O Library
=====================================================
-XXX write this.
+Python's built-in file objects support a number of methods, but
+file-like objects don't necessarily support all of them. Objects that
+imitate files usually support :meth:`read` and :meth:`write`, but they
+may not support :meth:`readline`. Python 3.0 introduces a layered I/O
+library in the :mod:`io` module that separates buffering and
+text-handling features from the fundamental read and write operations.
+
+There are three levels of abstract base classes provided by
+the :mod:`io` module:
+
+* :class:`RawIOBase`: defines raw I/O operations: :meth:`read`,
+ :meth:`readinto`,
+ :meth:`write`, :meth:`seek`, :meth:`tell`, :meth:`truncate`,
+ and :meth:`close`.
+ Most of the methods of this class will often map to a single system call.
+ There are also :meth:`readable`, :meth:`writable`, and :meth:`seekable`
+ methods for determining what operations a given object will allow.
+
+ Python 3.0 has concrete implementations of this class for files and
+ sockets, but Python 2.6 hasn't restructured its file and socket objects
+ in this way.
+
+ .. XXX should 2.6 register them in io.py?
+
+* :class:`BufferedIOBase`: is an abstract base class that
+ buffers data in memory to reduce the number of
+ system calls used, making I/O processing more efficient.
+ It supports all of the methods of :class:`RawIOBase`,
+ and adds a :attr:`raw` attribute holding the underlying raw object.
+
+ There are four concrete classes implementing this ABC:
+ :class:`BufferedWriter` and
+ :class:`BufferedReader` for objects that only support
+ writing or reading and don't support random access,
+ :class:`BufferedRandom` for objects that support the :meth:`seek` method
+ for random access,
+ and :class:`BufferedRWPair` for objects such as TTYs that have
+ both read and write operations that act upon unconnected streams of data.
+
+* :class:`TextIOBase`: Provides functions for reading and writing
+ strings (remember, strings will be Unicode in Python 3.0),
+ and supporting universal newlines. :class:`TextIOBase` defines
+ the :meth:`readline` method and supports iteration upon
+ objects.
+
+ There are two concrete implementations. :class:`TextIOWrapper`
+ wraps a buffered I/O object, supporting all of the methods for
+ text I/O and adding a :attr:`buffer` attribute for access
+ to the underlying object. :class:`StringIO` simply buffers
+ everything in memory without ever writing anything to disk.
+
+ (In current 2.6 alpha releases, :class:`io.StringIO` is implemented in
+ pure Python, so it's pretty slow. You should therefore stick with the
+ existing :mod:`StringIO` module or :mod:`cStringIO` for now. At some
+ point Python 3.0's :mod:`io` module will be rewritten into C for speed,
+ and perhaps the C implementation will be backported to the 2.x releases.)
+
+ .. XXX check before final release: is io.py still written in Python?
+
+In Python 2.6, the underlying implementations haven't been
+restructured to build on top of the :mod:`io` module's classes. The
+module is being provided to make it easier to write code that's
+forward-compatible with 3.0, and to save developers the effort of writing
+their own implementations of buffering and text I/O.
.. seealso::
@@ -952,22 +1021,48 @@ Subclasses must then define a :meth:`readonly` property
PEP 3127: Integer Literal Support and Syntax
=====================================================
-XXX write this -- this section is currently just brief notes.
+Python 3.0 changes the syntax for octal (base-8) integer literals,
+which are now prefixed by "0o" or "0O" instead of a leading zero, and
+adds support for binary (base-2) integer literals, signalled by a "0b"
+or "0B" prefix.
+
+Python 2.6 doesn't drop support for a leading 0 signalling
+an octal number, but it does add support for "0o" and "0b"::
+
+ >>> 0o21, 2*8 + 1
+ (17, 17)
+ >>> 0b101111
+ 47
+
+The :func:`oct` built-in still returns numbers
+prefixed with a leading zero, and a new :func:`bin`
+built-in returns the binary representation for a number::
-Python 3.0 changes the syntax for octal integer literals, and
-adds supports for binary integers: 0o instad of 0,
-and 0b for binary. Python 2.6 doesn't support this, but a bin()
-builtin was added.
+ >>> oct(42)
+ '052'
+ >>> bin(173)
+ '0b10101101'
-XXX changes to the hex/oct builtins
+The :func:`int` and :func:`long` built-ins will now accept the "0o"
+and "0b" prefixes when base-8 or base-2 are requested, or when the
+**base** argument is zero (meaning the base used is determined from
+the string):
+ >>> int ('0o52', 0)
+ 42
+ >>> int('1101', 2)
+ 13
+ >>> int('0b1101', 2)
+ 13
+ >>> int('0b1101', 0)
+ 13
-New bin() built-in returns the binary form of a number.
.. seealso::
:pep:`3127` - Integer Literal Support and Syntax
- PEP written by Patrick Maupin.
+ PEP written by Patrick Maupin; backported to 2.6 by
+ Eric Smith.
.. ======================================================================
@@ -1124,6 +1219,13 @@ Here are all of the changes that Python 2.6 makes to the core Python language.
.. Patch 1686487
+* Tuples now have an :meth:`index` method matching the list type's
+ :meth:`index` method::
+
+ >>> t = (0,1,2,3,4)
+ >>> t.index(3)
+ 3
+
* The built-in types now have improved support for extended slicing syntax,
where various combinations of ``(start, stop, step)`` are supplied.
Previously, the support was partial and certain corner cases wouldn't work.
@@ -1532,7 +1634,7 @@ complete list of changes, or look through the CVS logs for all the details.
(3, 1), (3, 2), (3, 4),
(4, 1), (4, 2), (4, 3)]
- ``itertools.chain(*iterables)` is an existing function in
+ ``itertools.chain(*iterables)`` is an existing function in
:mod:`itertools` that gained a new constructor in Python 2.6.
``itertools.chain.from_iterable(iterable)`` takes a single
iterable that should return other iterables. :func:`chain` will
@@ -1642,6 +1744,12 @@ complete list of changes, or look through the CVS logs for all the details.
.. Patch #1393667
+ The :func:`post_mortem` function, used to enter debugging of a
+ traceback, will now use the traceback returned by :func:`sys.exc_info`
+ if no traceback is supplied. (Contributed by Facundo Batista.)
+
+ .. Patch #1106316
+
* The :mod:`pickletools` module now has an :func:`optimize` function
that takes a string containing a pickle and removes some unused
opcodes, returning a shorter pickle that contains the same data structure.
@@ -1720,6 +1828,8 @@ complete list of changes, or look through the CVS logs for all the details.
.. Patch 1657
+ .. XXX
+
* The :mod:`sets` module has been deprecated; it's better to
use the built-in :class:`set` and :class:`frozenset` types.
@@ -1791,9 +1901,12 @@ complete list of changes, or look through the CVS logs for all the details.
* The base classes in the :mod:`SocketServer` module now support
calling a :meth:`handle_timeout` method after a span of inactivity
specified by the server's :attr:`timeout` attribute. (Contributed
- by Michael Pomraning.)
+ by Michael Pomraning.) The :meth:`serve_forever` method
+ now takes an optional poll interval measured in seconds,
+ controlling how often the server will check for a shutdown request.
+ (Contributed by Pedro Werneck and Jeffrey Yasskin.)
- .. Patch #742598
+ .. Patch #742598, #1193577
* The :mod:`struct` module now supports the C99 :ctype:`_Bool` type,
using the format character ``'?'``.
@@ -2069,6 +2182,19 @@ Changes to Python's build process and to the C API include:
.. Patch 1551895
+* Python's use of the C stdio library is now thread-safe, or at least
+ as thread-safe as the underlying library is. A long-standing potential
+ bug occurred if one thread closed a file object while another thread
+ was reading from or writing to the object. In 2.6 file objects
+ have a reference count, manipulated by the
+ :cfunc:`PyFile_IncUseCount` and :cfunc:`PyFile_DecUseCount`
+ functions. File objects can't be closed unless the reference count
+ is zero. :cfunc:`PyFile_IncUseCount` should be called while the GIL
+ is still held, before carrying out an I/O operation using the
+ ``FILE *`` pointer, and :cfunc:`PyFile_DecUseCount` should be called
+ immediately after the GIL is re-acquired.
+ (Contributed by Antoine Pitrou and Gregory P. Smith.)
+
* Several functions return information about the platform's
floating-point support. :cfunc:`PyFloat_GetMax` returns
the maximum representable floating point value,
@@ -2089,6 +2215,13 @@ Changes to Python's build process and to the C API include:
.. Issue 1635
+* Many C extensions define their own little macro for adding
+ integers and strings to the module's dictionary in the
+ ``init*`` function. Python 2.6 finally defines standard macros
+ for adding values to a module, :cmacro:`PyModule_AddStringMacro`
+ and :cmacro:`PyModule_AddIntMacro()`. (Contributed by
+ Christian Heimes.)
+
* Some macros were renamed in both 3.0 and 2.6 to make it clearer that
they are macros,
not functions. :cmacro:`Py_Size()` became :cmacro:`Py_SIZE()`,
@@ -2112,6 +2245,13 @@ Changes to Python's build process and to the C API include:
``numfree``, and a macro :cmacro:`Py<typename>_MAXFREELIST` is
always defined.
+* A new Makefile target, "make check", prepares the Python source tree
+ for making a patch: it fixes trailing whitespace in all modified
+ ``.py`` files, checks whether the documentation has been changed,
+ and reports whether the :file:`Misc/ACKS` and :file:`Misc/NEWS` files
+ have been updated.
+ (Contributed by Brett Cannon.)
+
.. ======================================================================
@@ -2140,6 +2280,13 @@ Port-Specific Changes: Windows
module now support the context protocol, so they can be used
in :keyword:`with` statements. (Contributed by Christian Heimes.)
+ :mod:`_winreg` also has better support for x64 systems,
+ exposing the :func:`DisableReflectionKey`, :func:`EnableReflectionKey`,
+ and :func:`QueryReflectionKey` functions, which enable and disable
+ registry reflection for 32-bit processes running on 64-bit systems.
+
+ .. Patch 1753245
+
* The new default compiler on Windows is Visual Studio 2008 (VS 9.0). The
build directories for Visual Studio 2003 (VS7.1) and 2005 (VS8.0)
were moved into the PC/ directory. The new PCbuild directory supports
@@ -2237,5 +2384,5 @@ Acknowledgements
================
The author would like to thank the following people for offering suggestions,
-corrections and assistance with various drafts of this article: .
+corrections and assistance with various drafts of this article: Jim Jewett.