blob: e035eb0b69e9756d896c9488acddf30fd784bedd [file] [log] [blame]
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +00001****************************
2 What's New in Python 2.7
3****************************
4
5:Author: A.M. Kuchling (amk at amk.ca)
6:Release: |release|
7:Date: |today|
8
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +00009.. Fix accents on Kristjan Valur Jonsson, Fuerstenau.
10
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +000011.. $Id$
12 Rules for maintenance:
13
14 * Anyone can add text to this document. Do not spend very much time
15 on the wording of your changes, because your text will probably
16 get rewritten to some degree.
17
18 * The maintainer will go through Misc/NEWS periodically and add
19 changes; it's therefore more important to add your changes to
20 Misc/NEWS than to this file.
21
22 * This is not a complete list of every single change; completeness
23 is the purpose of Misc/NEWS. Some changes I consider too small
24 or esoteric to include. If such a change is added to the text,
25 I'll just remove it. (This is another reason you shouldn't spend
26 too much time on writing your addition.)
27
28 * If you want to draw your new text to the attention of the
29 maintainer, add 'XXX' to the beginning of the paragraph or
30 section.
31
32 * It's OK to just add a fragmentary note about a change. For
33 example: "XXX Describe the transmogrify() function added to the
34 socket module." The maintainer will research the change and
35 write the necessary text.
36
37 * You can comment out your additions if you like, but it's not
38 necessary (especially when a final release is some months away).
39
40 * Credit the author of a patch or bugfix. Just the name is
41 sufficient; the e-mail address isn't necessary.
42
43 * It's helpful to add the bug/patch number in a parenthetical comment.
44
45 XXX Describe the transmogrify() function added to the socket
46 module.
47 (Contributed by P.Y. Developer; :issue:`12345`.)
48
49 This saves the maintainer some effort going through the SVN logs
50 when researching a change.
51
52This article explains the new features in Python 2.7.
53No release schedule has been decided yet for 2.7.
54
55.. Compare with previous release in 2 - 3 sentences here.
56 add hyperlink when the documentation becomes available online.
57
58.. ========================================================================
59.. Large, PEP-level features and changes should be described here.
60.. Should there be a new section here for 3k migration?
61.. Or perhaps a more general section describing module changes/deprecation?
62.. ========================================================================
63
64
65
66Other Language Changes
67======================
68
69Some smaller changes made to the core Python language are:
70
Mark Dickinson1a707982008-12-17 16:14:37 +000071* The :func:`int` and :func:`long` types gained a ``bit_length``
72 method that returns the number of bits necessary to represent
73 its argument in binary::
74
75 >>> n = 37
76 >>> bin(37)
77 '0b100101'
78 >>> n.bit_length()
79 6
80 >>> n = 2**123-1
81 >>> n.bit_length()
82 123
83 >>> (n+1).bit_length()
84 124
85
86 (Contributed by Fredrik Johansson and Victor Stinner; :issue:`3439`.)
87
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +000088
Mark Dickinsonefc82f72009-03-20 15:51:55 +000089* Integers are now stored internally either in base 2**15 or in base
90 2**30, the base being determined at build time. Previously, they
91 were always stored in base 2**15. Using base 2**30 gives
92 significant performance improvements on 64-bit machines, but
93 benchmark results on 32-bit machines have been mixed. Therefore,
94 the default is to use base 2**30 on 64-bit machines and base 2**15
95 on 32-bit machines; on Unix, there's a new configure option
96 --enable-big-digits that can be used to override this default.
97
98 Apart from the performance improvements this change should be
99 invisible to end users, with one exception: for testing and
100 debugging purposes there's a new structseq ``sys.long_info`` that
101 provides information about the internal format, giving the number of
102 bits per digit and the size in bytes of the C type used to store
103 each digit::
104
105 >>> import sys
106 >>> sys.long_info
107 sys.long_info(bits_per_digit=30, sizeof_digit=4)
108
109
110 (Contributed by Mark Dickinson; :issue:`4258`.)
111
112
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000113.. ======================================================================
114
115
116Optimizations
117-------------
118
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000119A few performance enhancements have been added:
120
121* The garbage collector now performs better when many objects are
122 being allocated without deallocating any. A full garbage collection
123 pass is only performed when the middle generation has been collected
124 10 times and when the number of survivor objects from the middle
125 generation exceeds 10% of the number of objects in the oldest
126 generation. The second condition was added to reduce the number
127 of full garbage collections as the number of objects on the heap grows,
128 avoiding quadratic performance when allocating very many objects.
129 (Suggested by Martin von Loewis and implemented by Antoine Pitrou;
130 :issue:`4074`.)
131
Antoine Pitrouc18f6b02009-03-28 19:10:13 +0000132* The garbage collector tries to avoid tracking simple containers which
133 can't be part of a cycle. As of now, this is true for tuples and dicts
134 containing atomic types (such as ints, strings, etc.). Transitively, a dict
135 containing tuples of atomic types won't be tracked either. This helps brings
136 down the cost of full garbage collections, since it decreases the number of
137 objects to be considered and traversed by the collector.
138 (Contributed by Antoine Pitrou; :issue:`4688`.)
139
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000140
141.. ======================================================================
142
143New, Improved, and Deprecated Modules
144=====================================
145
146As in every release, Python's standard library received a number of
147enhancements and bug fixes. Here's a partial list of the most notable
148changes, sorted alphabetically by module name. Consult the
149:file:`Misc/NEWS` file in the source tree for a more complete list of
150changes, or look through the Subversion logs for all the details.
151
Tarek Ziadéf1c95fe2009-02-16 22:38:43 +0000152* In Distutils, distutils.sdist.add_defaults now uses package_dir and data_files
153 to feed MANIFEST.
154
Andrew M. Kuchling9cb42772009-01-21 02:15:43 +0000155* It is not mandatory anymore to store clear text passwords in the
156 :file:`.pypirc` file when registering and uploading packages to PyPI. As long
157 as the username is present in that file, the :mod:`distutils` package will
158 prompt for the password if not present. (Added by tarek, with the initial
159 contribution of Nathan Van Gheem; :issue:`4394`.)
160
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000161* The :mod:`bz2` module's :class:`BZ2File` now supports the context
162 management protocol, so you can write ``with bz2.BZ2File(...) as f: ...``.
163 (Contributed by Hagen Fuerstenau; :issue:`3860`.)
164
165* A new :class:`Counter` class in the :mod:`collections` module is
166 useful for tallying data. :class:`Counter` instances behave mostly
167 like dictionaries but return zero for missing keys instead of
168 raising a :exc:`KeyError`::
169
170 >>> from collections import Counter
171 >>> c=Counter()
172 >>> for letter in 'here is a sample of english text':
173 ... c[letter] += 1
174 ...
175 >>> c
176 Counter({' ': 6, 'e': 5, 's': 3, 'a': 2, 'i': 2, 'h': 2,
177 'l': 2, 't': 2, 'g': 1, 'f': 1, 'm': 1, 'o': 1, 'n': 1,
178 'p': 1, 'r': 1, 'x': 1})
179 >>> c['e']
180 5
181 >>> c['z']
182 0
183
184 There are two additional :class:`Counter` methods: :meth:`most_common`
185 returns the N most common elements and their counts, and :meth:`elements`
186 returns an iterator over the contained element, repeating each element
187 as many times as its count::
188
189 >>> c.most_common(5)
190 [(' ', 6), ('e', 5), ('s', 3), ('a', 2), ('i', 2)]
191 >>> c.elements() ->
192 'a', 'a', ' ', ' ', ' ', ' ', ' ', ' ',
193 'e', 'e', 'e', 'e', 'e', 'g', 'f', 'i', 'i',
194 'h', 'h', 'm', 'l', 'l', 'o', 'n', 'p', 's',
195 's', 's', 'r', 't', 't', 'x']
196
197 Contributed by Raymond Hettinger; :issue:`1696199`.
198
199* The :mod:`gzip` module's :class:`GzipFile` now supports the context
200 management protocol, so you can write ``with gzip.GzipFile(...) as f: ...``.
201 (Contributed by Hagen Fuerstenau; :issue:`3860`.)
202
203* The :class:`io.FileIO` class now raises an :exc:`OSError` when passed
204 an invalid file descriptor. (Implemented by Benjamin Peterson;
205 :issue:`4991`.)
206
Andrew M. Kuchling9cb42772009-01-21 02:15:43 +0000207* The :mod:`pydoc` module now has help for the various symbols that Python
208 uses. You can now do ``help('<<')`` or ``help('@')``, for example.
209 (Contributed by David Laban; :issue:`4739`.)
210
Andrew M. Kuchling10b1ec92009-01-02 21:00:35 +0000211* A new function in the :mod:`subprocess` module,
212 :func:`check_output`, runs a command with a specified set of arguments
213 and returns the command's output as a string if the command runs without
214 error, or raises a :exc:`CalledProcessError` exception otherwise.
215
216 ::
217
218 >>> subprocess.check_output(['df', '-h', '.'])
219 'Filesystem Size Used Avail Capacity Mounted on\n
220 /dev/disk0s2 52G 49G 3.0G 94% /\n'
221
222 >>> subprocess.check_output(['df', '-h', '/bogus'])
223 ...
224 subprocess.CalledProcessError: Command '['df', '-h', '/bogus']' returned non-zero exit status 1
225
226 (Contributed by Gregory P. Smith.)
227
Andrew M. Kuchling9cb42772009-01-21 02:15:43 +0000228* The :func:`is_zipfile` function in the :mod:`zipfile` module will now
229 accept a file object, in addition to the path names accepted in earlier
230 versions. (Contributed by Gabriel Genellina; :issue:`4756`.)
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000231
232.. ======================================================================
233.. whole new modules get described in subsections here
234
Andrew M. Kuchlinga17cd4a2009-01-31 02:50:09 +0000235ttk: Themed Widgets for Tk
236--------------------------
237
238Tcl/Tk 8.5 includes a set of themed widgets that re-implement basic Tk
239widgets but have a more customizable appearance and can therefore more
240closely resemble the native platform's widgets. This widget
241set was originally called Tile, but was renamed to Ttk (for "themed Tk")
242on being added to Tcl/Tck release 8.5.
243
244XXX write a brief discussion and an example here.
245
246The :mod:`ttk` module was written by Guilherme Polo and added in
247:issue:`2983`. An alternate version called ``Tile.py``, written by
248Martin Franklin and maintained by Kevin Walzer, was proposed for
249inclusion in :issue:`2618`, but the authors argued that Guilherme
250Polo's work was more comprehensive.
251
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000252.. ======================================================================
253
254
255Build and C API Changes
256=======================
257
258Changes to Python's build process and to the C API include:
259
Andrew M. Kuchling10b1ec92009-01-02 21:00:35 +0000260* If you use the :file:`.gdbinit` file provided with Python,
261 the "pyo" macro in the 2.7 version will now work when the thread being
262 debugged doesn't hold the GIL; the macro will now acquire it before printing.
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000263 (Contributed by Victor Stinner; :issue:`3632`.)
264
265* :cfunc:`Py_AddPendingCall` is now thread safe, letting any
266 worker thread submit notifications to the main Python thread. This
267 is particularly useful for asynchronous IO operations.
268 (Contributed by Kristjan Valur Jonsson; :issue:`4293`.)
269
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000270
271.. ======================================================================
272
273Port-Specific Changes: Windows
274-----------------------------------
275
Andrew M. Kuchling10b1ec92009-01-02 21:00:35 +0000276* The :mod:`msvcrt` module now contains some constants from
277 the :file:`crtassem.h` header file:
278 :data:`CRT_ASSEMBLY_VERSION`,
279 :data:`VC_ASSEMBLY_PUBLICKEYTOKEN`,
280 and :data:`LIBRARIES_ASSEMBLY_NAME_PREFIX`.
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000281 (Contributed by David Cournapeau; :issue:`4365`.)
282
283* The new :cfunc:`_beginthreadex` API is used to start threads, and
284 the native thread-local storage functions are now used.
285 (Contributed by Kristjan Valur Jonsson; :issue:`3582`.)
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000286
287.. ======================================================================
288
289Port-Specific Changes: Mac OS X
290-----------------------------------
291
292
293.. ======================================================================
294
295Porting to Python 2.7
296=====================
297
298This section lists previously described changes and other bugfixes
299that may require changes to your code:
300
301To be written.
302
303.. ======================================================================
304
305
306.. _acks27:
307
308Acknowledgements
309================
310
311The author would like to thank the following people for offering
312suggestions, corrections and assistance with various drafts of this
313article: no one yet.
314