blob: 6c799fdea921f70cd2892d6da3eb3899f2fb4d1e [file] [log] [blame]
Georg Brandl8ec7f652007-08-15 14:28:01 +00001****************************
2 What's New in Python 2.6
3****************************
4
5:Author: A.M. Kuchling
6:Release: |release|
7:Date: |today|
8
9.. % $Id: whatsnew26.tex 55746 2007-06-02 18:33:53Z neal.norwitz $
10.. % Rules for maintenance:
11.. %
12.. % * Anyone can add text to this document. Do not spend very much time
13.. % on the wording of your changes, because your text will probably
14.. % get rewritten to some degree.
15.. %
16.. % * The maintainer will go through Misc/NEWS periodically and add
17.. % changes; it's therefore more important to add your changes to
18.. % Misc/NEWS than to this file.
19.. %
20.. % * This is not a complete list of every single change; completeness
21.. % is the purpose of Misc/NEWS. Some changes I consider too small
22.. % or esoteric to include. If such a change is added to the text,
23.. % I'll just remove it. (This is another reason you shouldn't spend
24.. % too much time on writing your addition.)
25.. %
26.. % * If you want to draw your new text to the attention of the
27.. % maintainer, add 'XXX' to the beginning of the paragraph or
28.. % section.
29.. %
30.. % * It's OK to just add a fragmentary note about a change. For
31.. % example: "XXX Describe the transmogrify() function added to the
32.. % socket module." The maintainer will research the change and
33.. % write the necessary text.
34.. %
35.. % * You can comment out your additions if you like, but it's not
36.. % necessary (especially when a final release is some months away).
37.. %
38.. % * Credit the author of a patch or bugfix. Just the name is
39.. % sufficient; the e-mail address isn't necessary.
40.. %
41.. % * It's helpful to add the bug/patch number as a comment:
42.. %
43.. % % Patch 12345
44.. % XXX Describe the transmogrify() function added to the socket
45.. % module.
46.. % (Contributed by P.Y. Developer.)
47.. %
48.. % This saves the maintainer the effort of going through the SVN log
49.. % when researching a change.
50
51This article explains the new features in Python 2.6. No release date for
52Python 2.6 has been set; it will probably be released in mid 2008.
53
54This article doesn't attempt to provide a complete specification of the new
55features, but instead provides a convenient overview. For full details, you
56should refer to the documentation for Python 2.6. If you want to understand the
57complete implementation and design rationale, refer to the PEP for a particular
58new feature.
59
60.. % Compare with previous release in 2 - 3 sentences here.
61.. % add hyperlink when the documentation becomes available online.
62
63.. % ======================================================================
64.. % Large, PEP-level features and changes should be described here.
65.. % Should there be a new section here for 3k migration?
66.. % Or perhaps a more general section describing module changes/deprecation?
67.. % sets module deprecated
68.. % ======================================================================
69
70
71Other Language Changes
72======================
73
74Here are all of the changes that Python 2.6 makes to the core Python language.
75
Andrew M. Kuchling6c066dd2007-09-01 20:43:36 +000076* The :func:`complex` constructor now accepts strings containing
77 parenthesized complex numbers, letting ``complex(repr(cmplx))``
78 will now round-trip values. For example, ``complex('(3+4j)')``
79 now returns the value (3+4j).
80
81 .. % Patch 1491866
82
Andrew M. Kuchlingb4c62952007-09-01 21:18:31 +000083* The string :meth:`translate` method now accepts ``None`` as the
84 translation table parameter, which is treated as the identity
85 transformation. This makes it easier to carry out operations
86 that only delete characters. (Contributed by Bengt Richter.)
87
88 .. % Patch 1193128
89
Georg Brandl8ec7f652007-08-15 14:28:01 +000090* An obscure change: when you use the the :func:`locals` function inside a
91 :keyword:`class` statement, the resulting dictionary no longer returns free
92 variables. (Free variables, in this case, are variables referred to in the
93 :keyword:`class` statement that aren't attributes of the class.)
94
95.. % ======================================================================
96
97
98Optimizations
99-------------
100
101* Internally, a bit is now set in type objects to indicate some of the standard
102 built-in types. This speeds up checking if an object is a subclass of one of
103 these types. (Contributed by Neal Norwitz.)
104
105The net result of the 2.6 optimizations is that Python 2.6 runs the pystone
106benchmark around XX% faster than Python 2.5.
107
108.. % ======================================================================
109
110
111New, Improved, and Deprecated Modules
112=====================================
113
114As usual, Python's standard library received a number of enhancements and bug
115fixes. Here's a partial list of the most notable changes, sorted alphabetically
116by module name. Consult the :file:`Misc/NEWS` file in the source tree for a more
117complete list of changes, or look through the CVS logs for all the details.
118
119* A new data type in the :mod:`collections` module: :class:`NamedTuple(typename,
120 fieldnames)` is a factory function that creates subclasses of the standard tuple
121 whose fields are accessible by name as well as index. For example::
122
123 var_type = collections.NamedTuple('variable',
124 'id name type size')
125 var = var_type(1, 'frequency', 'int', 4)
126
127 print var[0], var.id # Equivalent
128 print var[2], var.type # Equivalent
129
130 (Contributed by Raymond Hettinger.)
131
132* A new method in the :mod:`curses` module: for a window, :meth:`chgat` changes
133 the display characters for a certain number of characters on a single line. ::
134
135 # Boldface text starting at y=0,x=21
136 # and affecting the rest of the line.
137 stdscr.chgat(0,21, curses.A_BOLD)
138
139 (Contributed by Fabian Kreutz.)
140
Andrew M. Kuchlingb4c62952007-09-01 21:18:31 +0000141* An optional ``timeout`` parameter was added to the
142 :class:`ftplib.FTP` class constructor as well as the :meth:`connect`
143 method, specifying a timeout measured in seconds. (Added by Facundo
144 Batista.)
145
Georg Brandl8ec7f652007-08-15 14:28:01 +0000146* The :func:`glob.glob` function can now return Unicode filenames if
147 a Unicode path was used and Unicode filenames are matched within the directory.
148
149 .. % Patch #1001604
150
151* The :mod:`gopherlib` module has been removed.
152
153* A new function in the :mod:`heapq` module: ``merge(iter1, iter2, ...)``
154 takes any number of iterables that return data *in sorted order*, and returns
155 a new iterator that returns the contents of all the iterators, also in sorted
156 order. For example::
157
158 heapq.merge([1, 3, 5, 9], [2, 8, 16]) ->
159 [1, 2, 3, 5, 8, 9, 16]
160
161 (Contributed by Raymond Hettinger.)
162
163* A new function in the :mod:`itertools` module: ``izip_longest(iter1, iter2,
164 ...[, fillvalue])`` makes tuples from each of the elements; if some of the
165 iterables are shorter than others, the missing values are set to *fillvalue*.
166 For example::
167
168 itertools.izip_longest([1,2,3], [1,2,3,4,5]) ->
169 [(1, 1), (2, 2), (3, 3), (None, 4), (None, 5)]
170
171 (Contributed by Raymond Hettinger.)
172
173* The :mod:`macfs` module has been removed. This in turn required the
174 :func:`macostools.touched` function to be removed because it depended on the
175 :mod:`macfs` module.
176
177 .. % Patch #1490190
178
Andrew M. Kuchling6c066dd2007-09-01 20:43:36 +0000179* In the :mod:`os.path` module, the :func:`splitext` function
180 has been changed to not split on leading period characters.
181 This produces better results when operating on Unix's dot-files.
182 For example, ``os.path.splitext('.ipython')``
183 now returns ``('.ipython', '')`` instead of ``('', '.ipython')``.
184
185 .. % Bug #115886
186
Andrew M. Kuchlingb4c62952007-09-01 21:18:31 +0000187 A new function, :func:`relpath(path, start)` returns a relative path
188 from the ``start`` path, if it's supplied, or from the current
189 working directory to the destination ``path``. (Contributed by
190 Richard Barran.)
191
192 .. % Patch 1339796
193
Georg Brandl8ec7f652007-08-15 14:28:01 +0000194* New functions in the :mod:`posix` module: :func:`chflags` and :func:`lchflags`
195 are wrappers for the corresponding system calls (where they're available).
196 Constants for the flag values are defined in the :mod:`stat` module; some
197 possible values include :const:`UF_IMMUTABLE` to signal the file may not be
198 changed and :const:`UF_APPEND` to indicate that data can only be appended to the
199 file. (Contributed by M. Levinson.)
200
201* The :mod:`rgbimg` module has been removed.
202
Andrew M. Kuchling6c066dd2007-09-01 20:43:36 +0000203* The :mod:`smtplib` module now supports SMTP over SSL thanks to the
204 addition of the :class:`SMTP_SSL` class. This class supports an
Andrew M. Kuchlingb4c62952007-09-01 21:18:31 +0000205 interface identical to the existing :class:`SMTP` class. Both
206 class constructors also have an optional ``timeout`` parameter
207 that specifies a timeout for the initial connection attempt, measured in
208 seconds.
209
210 An implementation of the LMTP protocol (:rfc:`2033`) was also added to
Andrew M. Kuchling6c066dd2007-09-01 20:43:36 +0000211 the module. LMTP is used in place of SMTP when transferring e-mail
212 between agents that don't manage a mail queue.
Andrew M. Kuchlingb4c62952007-09-01 21:18:31 +0000213
214 (SMTP over SSL contributed by Monty Taylor; timeout parameter
215 added by Facundo Batista; LMTP implemented by Leif
Andrew M. Kuchling6c066dd2007-09-01 20:43:36 +0000216 Hedstrom.)
217
218 .. % Patch #957003
Georg Brandl8ec7f652007-08-15 14:28:01 +0000219
Andrew M. Kuchlingb4c62952007-09-01 21:18:31 +0000220* An optional ``timeout`` parameter was added to the
221 :class:`telnetlib.Telnet` class constructor, specifying a timeout
222 measured in seconds. (Added by Facundo Batista.)
223
Georg Brandl8ec7f652007-08-15 14:28:01 +0000224* The :mod:`test.test_support` module now contains a :func:`EnvironmentVarGuard`
225 context manager that supports temporarily changing environment variables and
226 automatically restores them to their old values. (Contributed by Brett Cannon.)
227
Andrew M. Kuchling6c066dd2007-09-01 20:43:36 +0000228* The :mod:`timeit` module now accepts callables as well as strings
229 for the statement being timed and for the setup code.
230 Two convenience functions were added for creating
231 :class:`Timer` instances:
232 ``repeat(stmt, setup, time, repeat, number)`` and
233 ``timeit(stmt, setup, time, number)`` create an instance and call
234 the corresponding method. (Contributed by Erik Demaine.)
235
236 .. % Patch #1533909
237
Georg Brandl8ec7f652007-08-15 14:28:01 +0000238.. % ======================================================================
239.. % whole new modules get described in \subsections here
240
241.. % ======================================================================
242
243
244Build and C API Changes
245=======================
246
247Changes to Python's build process and to the C API include:
248
249* Detailed changes are listed here.
250
251.. % ======================================================================
252
253
254Port-Specific Changes
255---------------------
256
257Platform-specific changes go here.
258
259.. % ======================================================================
260
261
262.. _section-other:
263
264Other Changes and Fixes
265=======================
266
267As usual, there were a bunch of other improvements and bugfixes scattered
268throughout the source tree. A search through the change logs finds there were
269XXX patches applied and YYY bugs fixed between Python 2.5 and 2.6. Both figures
270are likely to be underestimates.
271
272Some of the more notable changes are:
273
274* Details go here.
275
276.. % ======================================================================
277
278
279Porting to Python 2.6
280=====================
281
282This section lists previously described changes that may require changes to your
283code:
284
Gregory P. Smithe9fef692007-09-09 23:36:46 +0000285* The :mod:`socket` module exception :exc:`socket.error` now inherits from
286 :exc:`IOError`.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000287
288.. % ======================================================================
289
290
291.. _acks:
292
293Acknowledgements
294================
295
296The author would like to thank the following people for offering suggestions,
297corrections and assistance with various drafts of this article: .
298