blob: 6f17dc24a31200e1cacc969301b48a5308347749 [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
Georg Brandl8ec7f652007-08-15 14:28:01 +000083* An obscure change: when you use the the :func:`locals` function inside a
84 :keyword:`class` statement, the resulting dictionary no longer returns free
85 variables. (Free variables, in this case, are variables referred to in the
86 :keyword:`class` statement that aren't attributes of the class.)
87
88.. % ======================================================================
89
90
91Optimizations
92-------------
93
94* Internally, a bit is now set in type objects to indicate some of the standard
95 built-in types. This speeds up checking if an object is a subclass of one of
96 these types. (Contributed by Neal Norwitz.)
97
98The net result of the 2.6 optimizations is that Python 2.6 runs the pystone
99benchmark around XX% faster than Python 2.5.
100
101.. % ======================================================================
102
103
104New, Improved, and Deprecated Modules
105=====================================
106
107As usual, Python's standard library received a number of enhancements and bug
108fixes. Here's a partial list of the most notable changes, sorted alphabetically
109by module name. Consult the :file:`Misc/NEWS` file in the source tree for a more
110complete list of changes, or look through the CVS logs for all the details.
111
112* A new data type in the :mod:`collections` module: :class:`NamedTuple(typename,
113 fieldnames)` is a factory function that creates subclasses of the standard tuple
114 whose fields are accessible by name as well as index. For example::
115
116 var_type = collections.NamedTuple('variable',
117 'id name type size')
118 var = var_type(1, 'frequency', 'int', 4)
119
120 print var[0], var.id # Equivalent
121 print var[2], var.type # Equivalent
122
123 (Contributed by Raymond Hettinger.)
124
125* A new method in the :mod:`curses` module: for a window, :meth:`chgat` changes
126 the display characters for a certain number of characters on a single line. ::
127
128 # Boldface text starting at y=0,x=21
129 # and affecting the rest of the line.
130 stdscr.chgat(0,21, curses.A_BOLD)
131
132 (Contributed by Fabian Kreutz.)
133
134* The :func:`glob.glob` function can now return Unicode filenames if
135 a Unicode path was used and Unicode filenames are matched within the directory.
136
137 .. % Patch #1001604
138
139* The :mod:`gopherlib` module has been removed.
140
141* A new function in the :mod:`heapq` module: ``merge(iter1, iter2, ...)``
142 takes any number of iterables that return data *in sorted order*, and returns
143 a new iterator that returns the contents of all the iterators, also in sorted
144 order. For example::
145
146 heapq.merge([1, 3, 5, 9], [2, 8, 16]) ->
147 [1, 2, 3, 5, 8, 9, 16]
148
149 (Contributed by Raymond Hettinger.)
150
151* A new function in the :mod:`itertools` module: ``izip_longest(iter1, iter2,
152 ...[, fillvalue])`` makes tuples from each of the elements; if some of the
153 iterables are shorter than others, the missing values are set to *fillvalue*.
154 For example::
155
156 itertools.izip_longest([1,2,3], [1,2,3,4,5]) ->
157 [(1, 1), (2, 2), (3, 3), (None, 4), (None, 5)]
158
159 (Contributed by Raymond Hettinger.)
160
161* The :mod:`macfs` module has been removed. This in turn required the
162 :func:`macostools.touched` function to be removed because it depended on the
163 :mod:`macfs` module.
164
165 .. % Patch #1490190
166
Andrew M. Kuchling6c066dd2007-09-01 20:43:36 +0000167* In the :mod:`os.path` module, the :func:`splitext` function
168 has been changed to not split on leading period characters.
169 This produces better results when operating on Unix's dot-files.
170 For example, ``os.path.splitext('.ipython')``
171 now returns ``('.ipython', '')`` instead of ``('', '.ipython')``.
172
173 .. % Bug #115886
174
Georg Brandl8ec7f652007-08-15 14:28:01 +0000175* New functions in the :mod:`posix` module: :func:`chflags` and :func:`lchflags`
176 are wrappers for the corresponding system calls (where they're available).
177 Constants for the flag values are defined in the :mod:`stat` module; some
178 possible values include :const:`UF_IMMUTABLE` to signal the file may not be
179 changed and :const:`UF_APPEND` to indicate that data can only be appended to the
180 file. (Contributed by M. Levinson.)
181
182* The :mod:`rgbimg` module has been removed.
183
Andrew M. Kuchling6c066dd2007-09-01 20:43:36 +0000184* The :mod:`smtplib` module now supports SMTP over SSL thanks to the
185 addition of the :class:`SMTP_SSL` class. This class supports an
186 interface identical to the existing :class:`SMTP` class. An
187 implementation of the LMTP protocol (:rfc:`2033`) was also added to
188 the module. LMTP is used in place of SMTP when transferring e-mail
189 between agents that don't manage a mail queue.
190 (SMTP over SSL contributed by Monty Taylor; LMTP implemented by Leif
191 Hedstrom.)
192
193 .. % Patch #957003
Georg Brandl8ec7f652007-08-15 14:28:01 +0000194
195* The :mod:`test.test_support` module now contains a :func:`EnvironmentVarGuard`
196 context manager that supports temporarily changing environment variables and
197 automatically restores them to their old values. (Contributed by Brett Cannon.)
198
Andrew M. Kuchling6c066dd2007-09-01 20:43:36 +0000199* The :mod:`timeit` module now accepts callables as well as strings
200 for the statement being timed and for the setup code.
201 Two convenience functions were added for creating
202 :class:`Timer` instances:
203 ``repeat(stmt, setup, time, repeat, number)`` and
204 ``timeit(stmt, setup, time, number)`` create an instance and call
205 the corresponding method. (Contributed by Erik Demaine.)
206
207 .. % Patch #1533909
208
Georg Brandl8ec7f652007-08-15 14:28:01 +0000209.. % ======================================================================
210.. % whole new modules get described in \subsections here
211
212.. % ======================================================================
213
214
215Build and C API Changes
216=======================
217
218Changes to Python's build process and to the C API include:
219
220* Detailed changes are listed here.
221
222.. % ======================================================================
223
224
225Port-Specific Changes
226---------------------
227
228Platform-specific changes go here.
229
230.. % ======================================================================
231
232
233.. _section-other:
234
235Other Changes and Fixes
236=======================
237
238As usual, there were a bunch of other improvements and bugfixes scattered
239throughout the source tree. A search through the change logs finds there were
240XXX patches applied and YYY bugs fixed between Python 2.5 and 2.6. Both figures
241are likely to be underestimates.
242
243Some of the more notable changes are:
244
245* Details go here.
246
247.. % ======================================================================
248
249
250Porting to Python 2.6
251=====================
252
253This section lists previously described changes that may require changes to your
254code:
255
256* Everything is all in the details!
257
258.. % ======================================================================
259
260
261.. _acks:
262
263Acknowledgements
264================
265
266The author would like to thank the following people for offering suggestions,
267corrections and assistance with various drafts of this article: .
268