blob: 8037b1319cb7f033594bad64989452b30b78d400 [file] [log] [blame]
Benjamin Petersonf10a79a2008-10-11 00:49:57 +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
Benjamin Peterson1010bf32009-01-30 04:00:29 +00009.. Fix accents on Kristjan Valur Jonsson, Fuerstenau.
10
Benjamin Petersonf10a79a2008-10-11 00:49:57 +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 Dickinson54bc1ec2008-12-17 16:19:07 +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
Benjamin Petersonf10a79a2008-10-11 00:49:57 +000088
89.. ======================================================================
90
91
92Optimizations
93-------------
94
Benjamin Peterson1010bf32009-01-30 04:00:29 +000095A few performance enhancements have been added:
96
97* The garbage collector now performs better when many objects are
98 being allocated without deallocating any. A full garbage collection
99 pass is only performed when the middle generation has been collected
100 10 times and when the number of survivor objects from the middle
101 generation exceeds 10% of the number of objects in the oldest
102 generation. The second condition was added to reduce the number
103 of full garbage collections as the number of objects on the heap grows,
104 avoiding quadratic performance when allocating very many objects.
105 (Suggested by Martin von Loewis and implemented by Antoine Pitrou;
106 :issue:`4074`.)
107
Benjamin Petersonf10a79a2008-10-11 00:49:57 +0000108
109.. ======================================================================
110
111New, Improved, and Deprecated Modules
112=====================================
113
114As in every release, Python's standard library received a number of
115enhancements and bug fixes. Here's a partial list of the most notable
116changes, sorted alphabetically by module name. Consult the
117:file:`Misc/NEWS` file in the source tree for a more complete list of
118changes, or look through the Subversion logs for all the details.
119
Tarek Ziadé555f0e92009-02-16 22:42:39 +0000120* In Distutils, distutils.sdist.add_defaults now uses package_dir and data_files
121 to feed MANIFEST.
122
Benjamin Peterson1010bf32009-01-30 04:00:29 +0000123* It is not mandatory anymore to store clear text passwords in the
124 :file:`.pypirc` file when registering and uploading packages to PyPI. As long
125 as the username is present in that file, the :mod:`distutils` package will
126 prompt for the password if not present. (Added by tarek, with the initial
127 contribution of Nathan Van Gheem; :issue:`4394`.)
128
129* The :mod:`bz2` module's :class:`BZ2File` now supports the context
130 management protocol, so you can write ``with bz2.BZ2File(...) as f: ...``.
131 (Contributed by Hagen Fuerstenau; :issue:`3860`.)
132
133* A new :class:`Counter` class in the :mod:`collections` module is
134 useful for tallying data. :class:`Counter` instances behave mostly
135 like dictionaries but return zero for missing keys instead of
136 raising a :exc:`KeyError`::
137
138 >>> from collections import Counter
139 >>> c=Counter()
140 >>> for letter in 'here is a sample of english text':
141 ... c[letter] += 1
142 ...
143 >>> c
144 Counter({' ': 6, 'e': 5, 's': 3, 'a': 2, 'i': 2, 'h': 2,
145 'l': 2, 't': 2, 'g': 1, 'f': 1, 'm': 1, 'o': 1, 'n': 1,
146 'p': 1, 'r': 1, 'x': 1})
147 >>> c['e']
148 5
149 >>> c['z']
150 0
151
152 There are two additional :class:`Counter` methods: :meth:`most_common`
153 returns the N most common elements and their counts, and :meth:`elements`
154 returns an iterator over the contained element, repeating each element
155 as many times as its count::
156
157 >>> c.most_common(5)
158 [(' ', 6), ('e', 5), ('s', 3), ('a', 2), ('i', 2)]
159 >>> c.elements() ->
160 'a', 'a', ' ', ' ', ' ', ' ', ' ', ' ',
161 'e', 'e', 'e', 'e', 'e', 'g', 'f', 'i', 'i',
162 'h', 'h', 'm', 'l', 'l', 'o', 'n', 'p', 's',
163 's', 's', 'r', 't', 't', 'x']
164
165 Contributed by Raymond Hettinger; :issue:`1696199`.
166
167* The :mod:`gzip` module's :class:`GzipFile` now supports the context
168 management protocol, so you can write ``with gzip.GzipFile(...) as f: ...``.
169 (Contributed by Hagen Fuerstenau; :issue:`3860`.)
170
171* The :class:`io.FileIO` class now raises an :exc:`OSError` when passed
172 an invalid file descriptor. (Implemented by Benjamin Peterson;
173 :issue:`4991`.)
174
175* The :mod:`pydoc` module now has help for the various symbols that Python
176 uses. You can now do ``help('<<')`` or ``help('@')``, for example.
177 (Contributed by David Laban; :issue:`4739`.)
178
Georg Brandl1f01deb2009-01-03 22:47:39 +0000179* A new function in the :mod:`subprocess` module,
180 :func:`check_output`, runs a command with a specified set of arguments
181 and returns the command's output as a string if the command runs without
182 error, or raises a :exc:`CalledProcessError` exception otherwise.
183
184 ::
185
186 >>> subprocess.check_output(['df', '-h', '.'])
187 'Filesystem Size Used Avail Capacity Mounted on\n
188 /dev/disk0s2 52G 49G 3.0G 94% /\n'
189
190 >>> subprocess.check_output(['df', '-h', '/bogus'])
191 ...
192 subprocess.CalledProcessError: Command '['df', '-h', '/bogus']' returned non-zero exit status 1
193
194 (Contributed by Gregory P. Smith.)
195
Benjamin Peterson1010bf32009-01-30 04:00:29 +0000196* The :func:`is_zipfile` function in the :mod:`zipfile` module will now
197 accept a file object, in addition to the path names accepted in earlier
198 versions. (Contributed by Gabriel Genellina; :issue:`4756`.)
Benjamin Petersonf10a79a2008-10-11 00:49:57 +0000199
200.. ======================================================================
201.. whole new modules get described in subsections here
202
Benjamin Peterson5c6d7872009-02-06 02:40:07 +0000203ttk: Themed Widgets for Tk
204--------------------------
205
206Tcl/Tk 8.5 includes a set of themed widgets that re-implement basic Tk
207widgets but have a more customizable appearance and can therefore more
208closely resemble the native platform's widgets. This widget
209set was originally called Tile, but was renamed to Ttk (for "themed Tk")
210on being added to Tcl/Tck release 8.5.
211
212XXX write a brief discussion and an example here.
213
214The :mod:`ttk` module was written by Guilherme Polo and added in
215:issue:`2983`. An alternate version called ``Tile.py``, written by
216Martin Franklin and maintained by Kevin Walzer, was proposed for
217inclusion in :issue:`2618`, but the authors argued that Guilherme
218Polo's work was more comprehensive.
219
Benjamin Petersonf10a79a2008-10-11 00:49:57 +0000220.. ======================================================================
221
222
223Build and C API Changes
224=======================
225
226Changes to Python's build process and to the C API include:
227
Georg Brandl1f01deb2009-01-03 22:47:39 +0000228* If you use the :file:`.gdbinit` file provided with Python,
229 the "pyo" macro in the 2.7 version will now work when the thread being
230 debugged doesn't hold the GIL; the macro will now acquire it before printing.
Benjamin Peterson1010bf32009-01-30 04:00:29 +0000231 (Contributed by Victor Stinner; :issue:`3632`.)
232
233* :cfunc:`Py_AddPendingCall` is now thread safe, letting any
234 worker thread submit notifications to the main Python thread. This
235 is particularly useful for asynchronous IO operations.
236 (Contributed by Kristjan Valur Jonsson; :issue:`4293`.)
237
Benjamin Petersonf10a79a2008-10-11 00:49:57 +0000238
239.. ======================================================================
240
241Port-Specific Changes: Windows
242-----------------------------------
243
Georg Brandl1f01deb2009-01-03 22:47:39 +0000244* The :mod:`msvcrt` module now contains some constants from
245 the :file:`crtassem.h` header file:
246 :data:`CRT_ASSEMBLY_VERSION`,
247 :data:`VC_ASSEMBLY_PUBLICKEYTOKEN`,
248 and :data:`LIBRARIES_ASSEMBLY_NAME_PREFIX`.
Benjamin Peterson1010bf32009-01-30 04:00:29 +0000249 (Contributed by David Cournapeau; :issue:`4365`.)
250
251* The new :cfunc:`_beginthreadex` API is used to start threads, and
252 the native thread-local storage functions are now used.
253 (Contributed by Kristjan Valur Jonsson; :issue:`3582`.)
Benjamin Petersonf10a79a2008-10-11 00:49:57 +0000254
255.. ======================================================================
256
257Port-Specific Changes: Mac OS X
258-----------------------------------
259
260
261.. ======================================================================
262
263Porting to Python 2.7
264=====================
265
266This section lists previously described changes and other bugfixes
267that may require changes to your code:
268
269To be written.
270
271.. ======================================================================
272
273
274.. _acks27:
275
276Acknowledgements
277================
278
279The author would like to thank the following people for offering
280suggestions, corrections and assistance with various drafts of this
281article: no one yet.
282