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