blob: 32d7a3eb7fdbea833cc6424346df8e9d05c64da6 [file] [log] [blame]
Giampaolo Rodolà3108f982011-02-24 20:59:48 +00001****************************
2 What's New In Python 3.3
3****************************
4
5:Author: Raymond Hettinger
6:Release: |release|
7:Date: |today|
8
9.. $Id$
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 3.3, compared to 3.2.
52
53
54PEP XXX: Stub
55=============
56
57
Ezio Melotti48a2f8f2011-09-29 00:18:19 +030058PEP 393: Flexible String Representation
59=======================================
60
61XXX Add list of changes introduced by :pep:`393` here:
62
63* The value of :data:`sys.maxunicode` is now always ``1114111`` (``0x10FFFF``
64 in hexadecimal). The :c:func:`PyUnicode_GetMax` function still returns
65 either ``0xFFFF`` or ``0x10FFFF`` for backward compatibility, and it should
66 not be used with the new Unicode API (see :issue:`13054`).
67
Victor Stinner7d637ab2011-09-29 02:56:16 +020068* Non-BMP characters (U+10000-U+10FFFF range) are no more special cases.
69 ``'\U0010FFFF'[0]`` is now ``'\U0010FFFF'`` on any platform, instead of
70 ``'\uDFFF'`` on narrow build or ``'\U0010FFFF'`` on wide build. And
71 ``len('\U0010FFFF')`` is now ``1`` on any platform, instead of ``2`` on
72 narrow build or ``1`` on wide build. More generally, most bugs related to
73 non-BMP characters are now fixed. For example, :func:`unicodedata.normalize`
74 handles correctly non-BMP characters on all platforms.
75
76* The storage of Unicode string is now adapted on the content of the string.
77 Pure ASCII and Latin1 strings (U+0000-U+00FF) use 1 byte per character, BMP
78 strings (U+0000-U+FFFF) use 2 bytes per character, and non-BMP characters
79 (U+10000-U+10FFFF range) use 4 bytes per characters. The memory usage of
80 Python 3.3 is two to three times smaller than Python 3.2, and a little bit
81 better than Python 2.7, on a `Django benchmark
82 <http://mail.python.org/pipermail/python-dev/2011-September/113714.html>`_.
83
84* The PEP 393 is fully backward compatible. The legacy API should remain
85 available at least five years. Applications using the legacy API will not
86 fully benefit of the memory reduction, or worse may use a little bit more
87 memory, because Python may have to maintain two versions of each string (in
88 the legacy format and in the new efficient storage).
89
Ezio Melotti48a2f8f2011-09-29 00:18:19 +030090
Giampaolo Rodolà3108f982011-02-24 20:59:48 +000091Other Language Changes
92======================
93
94Some smaller changes made to the core Python language are:
95
96* Stub
97
98
99New, Improved, and Deprecated Modules
100=====================================
101
102* Stub
103
Meador Ingec5dbb3d2011-09-20 21:48:16 -0500104array
105-----
106
107The :mod:`array` module supports the :c:type:`long long` type using ``q`` and
108``Q`` type codes.
109
110(Contributed by Oren Tirosh and Hirokazu Yamamoto in :issue:`1172711`)
111
112
Victor Stinner2cded9c2011-07-08 01:45:13 +0200113codecs
114------
115
116Multibyte CJK decoders now resynchronize faster. They only ignore the first
Georg Brandl6c0929b2011-07-09 11:43:33 +0200117byte of an invalid byte sequence. For example, ``b'\xff\n'.decode('gb2312',
118'replace')`` now returns a ``\n`` after the replacement character.
Victor Stinner2cded9c2011-07-08 01:45:13 +0200119
Georg Brandl6c0929b2011-07-09 11:43:33 +0200120(:issue:`12016`)
Victor Stinner2cded9c2011-07-08 01:45:13 +0200121
122Don't reset incremental encoders of CJK codecs at each call to their encode()
Georg Brandl6c0929b2011-07-09 11:43:33 +0200123method anymore. For example::
Victor Stinner2cded9c2011-07-08 01:45:13 +0200124
125 $ ./python -q
126 >>> import codecs
127 >>> encoder = codecs.getincrementalencoder('hz')('strict')
128 >>> b''.join(encoder.encode(x) for x in '\u52ff\u65bd\u65bc\u4eba\u3002 Bye.')
129 b'~{NpJ)l6HK!#~} Bye.'
130
Georg Brandl6c0929b2011-07-09 11:43:33 +0200131This example gives ``b'~{Np~}~{J)~}~{l6~}~{HK~}~{!#~} Bye.'`` with older Python
Victor Stinner2cded9c2011-07-08 01:45:13 +0200132versions.
133
Georg Brandl6c0929b2011-07-09 11:43:33 +0200134(:issue:`12100`)
Victor Stinner2cded9c2011-07-08 01:45:13 +0200135
Éric Araujo84b8ed82011-08-29 21:42:47 +0200136crypt
137-----
138
Victor Stinnerc78fb332011-09-21 03:35:44 +0200139Addition of salt and modular crypt format and the :func:`~crypt.mksalt`
140function to the :mod:`crypt` module.
Éric Araujo84b8ed82011-08-29 21:42:47 +0200141
142(:issue:`10924`)
143
Victor Stinnera7878b72011-07-14 23:07:44 +0200144curses
145------
146
Victor Stinnerc78fb332011-09-21 03:35:44 +0200147 * The :class:`curses.window` class has a new :meth:`~curses.window.get_wch`
148 method to get a wide character
149 * The :mod:`curses` module has a new :meth:`~curses.unget_wch` function to
150 push a wide character so the next :meth:`~curses.window.get_wch` will return
151 it
Victor Stinnera7878b72011-07-14 23:07:44 +0200152
Victor Stinnerc78fb332011-09-21 03:35:44 +0200153(Contributed by Iñigo Serna in :issue:`6755`)
Victor Stinnera7878b72011-07-14 23:07:44 +0200154
Victor Stinner024e37a2011-03-31 01:31:06 +0200155faulthandler
156------------
157
158New module: :mod:`faulthandler`.
159
160 * :envvar:`PYTHONFAULTHANDLER`
161 * :option:`-X` ``faulthandler``
162
Victor Stinnerfa0e3d52011-05-09 01:01:09 +0200163
Victor Stinner811db3b2011-09-21 03:20:03 +0200164ftplib
165------
166
167The :class:`~ftplib.FTP_TLS` class now provides a new
168:func:`~ftplib.FTP_TLS.ccc` function to revert control channel back to
169plaintex. This can be useful to take advantage of firewalls that know how to
170handle NAT with non-secure FTP without opening fixed ports.
171
172(Contributed by Giampaolo Rodolà in :issue:`12139`)
173
174
Victor Stinnerfa0e3d52011-05-09 01:01:09 +0200175math
176----
177
178The :mod:`math` module has a new function:
179
180 * :func:`~math.log2`: return the base-2 logarithm of *x*
181 (Written by Mark Dickinson in :issue:`11888`).
182
183
184nntplib
185-------
186
187The :class:`nntplib.NNTP` class now supports the context manager protocol to
188unconditionally consume :exc:`socket.error` exceptions and to close the NNTP
189connection when done::
190
191 >>> from nntplib import NNTP
Ezio Melotti3c14b4e2011-07-13 11:44:44 +0300192 >>> with NNTP('news.gmane.org') as n:
Victor Stinnerfa0e3d52011-05-09 01:01:09 +0200193 ... n.group('gmane.comp.python.committers')
194 ...
Ezio Melotti04f648c2011-07-26 09:37:46 +0300195 ('211 1755 1 1755 gmane.comp.python.committers', 1755, 1, 1755, 'gmane.comp.python.committers')
Victor Stinnerfa0e3d52011-05-09 01:01:09 +0200196 >>>
197
198(Contributed by Giampaolo Rodolà in :issue:`9795`)
199
200
Giampaolo Rodolàc9c2c8b2011-02-25 14:39:16 +0000201os
202--
203
Charles-François Natalia003af12011-06-01 20:30:52 +0200204* The :mod:`os` module has a new :func:`~os.pipe2` function that makes it
205 possible to create a pipe with :data:`~os.O_CLOEXEC` or
206 :data:`~os.O_NONBLOCK` flags set atomically. This is especially useful to
207 avoid race conditions in multi-threaded programs.
208
Giampaolo Rodolà18e8bcb2011-02-25 20:57:54 +0000209* The :mod:`os` module has a new :func:`~os.sendfile` function which provides
210 an efficent "zero-copy" way for copying data from one file (or socket)
211 descriptor to another. The phrase "zero-copy" refers to the fact that all of
212 the copying of data between the two descriptors is done entirely by the
213 kernel, with no copying of data into userspace buffers. :func:`~os.sendfile`
214 can be used to efficiently copy data from a file on disk to a network socket,
215 e.g. for downloading a file.
Giampaolo Rodolàc9c2c8b2011-02-25 14:39:16 +0000216
Giampaolo Rodolà18e8bcb2011-02-25 20:57:54 +0000217 (Patch submitted by Ross Lagerwall and Giampaolo Rodolà in :issue:`10882`.)
218
219* The :mod:`os` module has two new functions: :func:`~os.getpriority` and
220 :func:`~os.setpriority`. They can be used to get or set process
221 niceness/priority in a fashion similar to :func:`os.nice` but extended to all
222 processes instead of just the current one.
223
224 (Patch submitted by Giampaolo Rodolà in :issue:`10784`.)
Giampaolo Rodolà3108f982011-02-24 20:59:48 +0000225
Giampaolo Rodolà424298a2011-03-03 18:34:06 +0000226
Éric Araujo765e94f2011-06-03 17:26:59 +0200227packaging
228---------
229
230:mod:`distutils` has undergone additions and refactoring under a new name,
231:mod:`packaging`, to allow developers to break backward compatibility.
232:mod:`distutils` is still provided in the standard library, but users are
233encouraged to transition to :mod:`packaging`. For older versions of Python, a
234backport compatible with 2.4+ and 3.1+ will be made available on PyPI under the
235name :mod:`distutils2`.
236
237.. TODO add examples and howto to the packaging docs and link to them
238
239
Victor Stinner383c3fc2011-05-25 01:35:05 +0200240pydoc
241-----
242
Victor Stinner6daa33c2011-05-25 01:41:22 +0200243The Tk GUI and the :func:`~pydoc.serve` function have been removed from the
244:mod:`pydoc` module: ``pydoc -g`` and :func:`~pydoc.serve` have been deprecated
245in Python 3.2.
Victor Stinner383c3fc2011-05-25 01:35:05 +0200246
247
Victor Stinnerd5c355c2011-04-30 14:53:09 +0200248sys
249---
Victor Stinner754851f2011-04-19 23:58:51 +0200250
Éric Araujo84b8ed82011-08-29 21:42:47 +0200251* The :mod:`sys` module has a new :data:`~sys.thread_info` :term:`struct
Victor Stinnerd5c355c2011-04-30 14:53:09 +0200252 sequence` holding informations about the thread implementation.
Victor Stinner754851f2011-04-19 23:58:51 +0200253
Georg Brandl00db5822011-04-30 15:30:03 +0200254 (:issue:`11223`)
Victor Stinnera9293352011-04-30 15:21:58 +0200255
Victor Stinnerfa0e3d52011-05-09 01:01:09 +0200256
Victor Stinnera9293352011-04-30 15:21:58 +0200257signal
258------
259
Victor Stinnerfa0e3d52011-05-09 01:01:09 +0200260* The :mod:`signal` module has new functions:
Victor Stinnera9293352011-04-30 15:21:58 +0200261
Victor Stinnerb3e72192011-05-08 01:46:11 +0200262 * :func:`~signal.pthread_sigmask`: fetch and/or change the signal mask of the
263 calling thread (Contributed by Jean-Paul Calderone in :issue:`8407`) ;
264 * :func:`~signal.pthread_kill`: send a signal to a thread ;
265 * :func:`~signal.sigpending`: examine pending functions ;
266 * :func:`~signal.sigwait`: wait a signal.
Ross Lagerwallbc808222011-06-25 12:13:40 +0200267 * :func:`~signal.sigwaitinfo`: wait for a signal, returning detailed
268 information about it.
269 * :func:`~signal.sigtimedwait`: like :func:`~signal.sigwaitinfo` but with a
270 timeout.
Victor Stinnera9293352011-04-30 15:21:58 +0200271
Victor Stinnerd49b1f12011-05-08 02:03:15 +0200272* The signal handler writes the signal number as a single byte instead of
273 a nul byte into the wakeup file descriptor. So it is possible to wait more
274 than one signal and know which signals were raised.
275
Victor Stinner388196e2011-05-10 17:13:00 +0200276* :func:`signal.signal` and :func:`signal.siginterrupt` raise an OSError,
277 instead of a RuntimeError: OSError has an errno attribute.
278
Nick Coghlan96fe56a2011-08-22 11:55:57 +1000279socket
280------
281
282The :class:`~socket.socket` class now exposes addititonal methods to
283process ancillary data when supported by the underlying platform:
284
285* :func:`~socket.socket.sendmsg`
286* :func:`~socket.socket.recvmsg`
287* :func:`~socket.socket.recvmsg_into`
288
289(Contributed by David Watson in :issue:`6560`, based on an earlier patch
290by Heiko Wundram)
Victor Stinner754851f2011-04-19 23:58:51 +0200291
Victor Stinner99c8b162011-05-24 12:05:19 +0200292ssl
293---
294
295The :mod:`ssl` module has new functions:
296
297 * :func:`~ssl.RAND_bytes`: generate cryptographically strong
298 pseudo-random bytes.
299 * :func:`~ssl.RAND_pseudo_bytes`: generate pseudo-random bytes.
300
301
Giampaolo Rodola'210e7ca2011-07-01 13:55:36 +0200302shutil
303------
304
Sandro Tosiaec2f212011-08-23 00:58:21 +0200305* The :mod:`shutil` module has these new fuctions:
Giampaolo Rodola'210e7ca2011-07-01 13:55:36 +0200306
Sandro Tosiaec2f212011-08-23 00:58:21 +0200307 * :func:`~shutil.disk_usage`: provides total, used and free disk space
308 statistics. (Contributed by Giampaolo Rodolà in :issue:`12442`)
309 * :func:`~shutil.chown`: allows one to change user and/or group of the given
310 path also specifying the user/group names and not only their numeric
311 ids. (Contributed by Sandro Tosi in :issue:`12191`)
Giampaolo Rodola'096dcb12011-06-27 11:17:51 +0200312
313
Giampaolo Rodolà3108f982011-02-24 20:59:48 +0000314Optimizations
315=============
316
317Major performance enhancements have been added:
318
319* Stub
320
321
322Build and C API Changes
323=======================
324
325Changes to Python's build process and to the C API include:
326
327* Stub
328
329
Georg Brandl0cd25c92011-04-29 13:45:54 +0200330Unsupported Operating Systems
Victor Stinnerb90db4c2011-04-26 22:48:24 +0200331=============================
332
Brian Curtin49a40cd2011-05-02 22:30:06 -0500333OS/2 and VMS are no longer supported due to the lack of a maintainer.
334
335Windows 2000 and Windows platforms which set ``COMSPEC`` to ``command.com``
336are no longer supported due to maintenance burden.
Victor Stinnerb90db4c2011-04-26 22:48:24 +0200337
338
Giampaolo Rodolà3108f982011-02-24 20:59:48 +0000339Porting to Python 3.3
340=====================
341
342This section lists previously described changes and other bugfixes
343that may require changes to your code:
344
Victor Stinnerff3d9392011-08-20 23:39:26 +0200345* Issue #12326: On Linux, sys.platform doesn't contain the major version
346 anymore. It is now always 'linux', instead of 'linux2' or 'linux3' depending
347 on the Linux version used to build Python. Replace sys.platform == 'linux2'
348 with sys.platform.startswith('linux'), or directly sys.platform == 'linux' if
349 you don't need to support older Python versions.
Éric Araujoc09fca62011-03-23 02:06:24 +0100350
351.. Issue #11591: When :program:`python` was started with :option:`-S`,
352 ``import site`` will not add site-specific paths to the module search
353 paths. In previous versions, it did. See changeset for doc changes in
354 various files. Contributed by Carl Meyer with editions by Éric Araujo.
Éric Araujobe3bd572011-03-26 01:55:15 +0100355
356.. Issue #10998: -Q command-line flags are related artifacts have been
357 removed. Code checking sys.flags.division_warning will need updating.
358 Contributed by Éric Araujo.
Victor Stinner7d637ab2011-09-29 02:56:16 +0200359
360* :pep:`393`: The :c:type:`Py_UNICODE` type and all functions using this type
361 are deprecated. To fully benefit of the memory footprint reduction provided
362 by the PEP 393, you have to convert your code to the new Unicode API. Read
363 the porting guide: XXX.
364