blob: 5940cd64e281ee4fc4b5a964b2673f0a0bbff1e6 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001****************************
2 What's New in Python 3.0
3****************************
4
Guido van Rossum4a98a2a2008-11-21 18:35:43 +00005.. XXX add trademark info for Apple, Microsoft, SourceForge.
Georg Brandl116aa622007-08-15 14:28:22 +00006
Guido van Rossum4a98a2a2008-11-21 18:35:43 +00007:Author: Guido van Rossum
8:Release: |release|
9:Date: |today|
10
11.. $Id$
12 Rules for maintenance:
Georg Brandl5a165582007-08-31 06:15:01 +000013
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 as a comment:
44
45 % Patch 12345
46 XXX Describe the transmogrify() function added to the socket
47 module.
48 (Contributed by P.Y. Developer.)
49
50 This saves the maintainer the effort of going through the SVN log
51 when researching a change.
Georg Brandl116aa622007-08-15 14:28:22 +000052
Guido van Rossum4a98a2a2008-11-21 18:35:43 +000053This article explains the new features in Python 3.0, comparing to 2.6.
54In some cases it will also summarize changes since 2.5, with a reference
55to "What's New in Python 2.6" for the details. Python 2.6 was released
56on October 1 2008. Python 3.0 will be released in December 2008.
Guido van Rossumb197f3c2007-08-31 00:37:00 +000057
58This article doesn't attempt to provide a complete specification of
59the new features, but instead provides a convenient overview. For
60full details, you should refer to the documentation for Python 3.0. If
61you want to understand the complete implementation and design
62rationale, refer to the PEP for a particular new feature.
Georg Brandl116aa622007-08-15 14:28:22 +000063
Georg Brandl5a165582007-08-31 06:15:01 +000064.. Compare with previous release in 2 - 3 sentences here.
65.. add hyperlink when the documentation becomes available online.
Georg Brandl116aa622007-08-15 14:28:22 +000066
Georg Brandl5a165582007-08-31 06:15:01 +000067.. ======================================================================
68.. Large, PEP-level features and changes should be described here.
69.. Should there be a new section here for 3k migration?
70.. Or perhaps a more general section describing module changes/deprecation?
71.. sets module deprecated
72.. ======================================================================
Georg Brandl116aa622007-08-15 14:28:22 +000073
74
Guido van Rossumb197f3c2007-08-31 00:37:00 +000075Common Stumbling Blocks
76=======================
77
78This section briefly lists the changes that are more likely to trip
79people up, without necessarily raising obvious errors. These are all
80explained in more detail below. (I'm not listing syntactic changes
81and removed or renamed features here, since those tend to produce hard
82and fast errors; it's the subtle behavioral changes in code that
83remains syntactically valid that trips people up. I'm also omitting
84changes to rarely used features.)
85
Georg Brandlec17d202008-02-02 10:44:37 +000086* The ``print`` statement has been replaced with a :func:`print` function,
Guido van Rossumdff1c312007-09-06 14:46:41 +000087 with keyword arguments to replace most of the special syntax of the
88 old ``print`` statement (PEP 3105). Examples::
89
90 Old: print "The answer is", 2*2
91 New: print("The answer is", 2*2)
92
93 Old: print x, # Trailing comma suppresses newline
94 New: print(x, end=" ") # Appends a space instead of a newline
95
96 Old: print # Prints a newline
97 New: print() # You must call the function!
98
99 Old: print >>sys.stderr, "fatal error"
100 New: print("fatal error", file=sys.stderr)
101
102 Old: print (x, y) # prints repr((x, y))
103 New: print((x, y)) # Not the same as print(x, y)!
104
105 You can also customize the separator between items, e.g.::
106
107 print("There are <", 2**32, "> possibilities!", sep="")
108
109 which produces::
110
111 There are <4294967296> possibilities!
112
Georg Brandlec17d202008-02-02 10:44:37 +0000113 Notes about the :func:`print` function:
Guido van Rossumdff1c312007-09-06 14:46:41 +0000114
Georg Brandlec17d202008-02-02 10:44:37 +0000115 * The :func:`print` function doesn't support the "softspace" feature of
Guido van Rossumdff1c312007-09-06 14:46:41 +0000116 the old ``print`` statement. For example, in Python 2.x,
117 ``print "A\n", "B"`` would write ``"A\nB\n"``; but in Python 3.0,
118 ``print("A\n", "B")`` writes ``"A\n B\n"``.
119
120 * Initially, you'll be finding yourself typing the old ``print x``
121 a lot in interactive mode. Time to retrain your fingers to type
122 ``print(x)`` instead!
123
124 * When using the ``2to3`` source-to-source conversion tool, all
Raymond Hettinger6a883842008-07-22 19:27:12 +0000125 ``print`` statements are automatically converted to :func:`print`
Guido van Rossumdff1c312007-09-06 14:46:41 +0000126 function calls, so this is mostly a non-issue for larger projects.
127
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000128* Python 3.0 uses strings and bytes instead of the Unicode strings and
129 8-bit strings. This means that pretty much all code that uses
130 Unicode, encodings or binary data in any way has to change. The
131 change is for the better, as in the 2.x world there were numerous
132 bugs having to do with mixing encoded and unencoded text.
133
134* Text files enforce an encoding; binary files use bytes. This means
135 that if a file is opened using an incorrect mode or encoding, I/O
136 will likely fail.
137
Guido van Rossum4a98a2a2008-11-21 18:35:43 +0000138* The ordering comparison operators (``<``, ``<=``, ``>=``, ``>``)
139 raise a TypeError exception when the operands don't have a
140 meaningful natural ordering. Thus, expressions like ``1 < ''``, ``0
141 > None`` or ``len < len`` are no longer valid. A corollary is that
142 sorting a heterogeneous list no longer makes sense -- all the
143 elements must be comparable to each other. Note that this does not
144 apply to the ``==`` and ``!=`` operators: objects of different
145 uncomparable types always compare unequal to each other, and an
146 object always compares equal to itself (i.e., ``x is y`` implies ``x
147 = y``; this is true even for ``NaN``).
148
Georg Brandlec17d202008-02-02 10:44:37 +0000149* :func:`map` and :func:`filter` return iterators. A quick fix is e.g.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000150 ``list(map(...))``, but a better fix is often to use a list
Georg Brandlec17d202008-02-02 10:44:37 +0000151 comprehension (especially when the original code uses :keyword:`lambda`).
152 Particularly tricky is :func:`map` invoked for the side effects of the
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000153 function; the correct transformation is to use a for-loop.
154
Georg Brandlec17d202008-02-02 10:44:37 +0000155* :class:`dict` methods :meth:`dict.keys`, :meth:`dict.items` and
156 :meth:`dict.values` return views instead of lists. For example, this no
157 longer works: ``k = d.keys(); k.sort()``. Use ``k = sorted(d)`` instead.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000158
Kurt B. Kaiser2bc6b5e2008-02-13 18:03:11 +0000159* :meth:`builtin.sorted` and :meth:`list.sort` no longer accept the *cmp*
Kurt B. Kaiser9d0d6162008-02-14 02:47:50 +0000160 argument providing a comparison function. Use the *key* argument
Kurt B. Kaiser2bc6b5e2008-02-13 18:03:11 +0000161 instead. N.B. the *key* and *reverse* arguments are now "keyword-only".
Kurt B. Kaisera1401012008-02-13 16:09:27 +0000162
Georg Brandlb6670872008-11-22 08:35:59 +0000163* The :meth:`__cmp__` special method is no longer supported. Use :meth:`__lt__`
164 for sorting, :meth:`__eq__` with :meth:`__hash__`, and other rich comparisons
165 as needed.
166
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000167* ``1/2`` returns a float. Use ``1//2`` to get the truncating behavior.
168
Guido van Rossum4a98a2a2008-11-21 18:35:43 +0000169.. XXX move the next one to a later point, it's not a common stumbling block.
170
Georg Brandlec17d202008-02-02 10:44:37 +0000171* The :func:`repr` of a long integer doesn't include the trailing ``L``
Georg Brandlcc595bd2007-12-09 09:04:01 +0000172 anymore, so code that unconditionally strips that character will
173 chop off the last digit instead.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000174
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000175
176Strings and Bytes
177=================
178
Georg Brandlec17d202008-02-02 10:44:37 +0000179* There is only one string type; its name is :class:`str` but its behavior and
180 implementation are like :class:`unicode` in 2.x.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000181
Georg Brandlec17d202008-02-02 10:44:37 +0000182* The :class:`basestring` superclass has been removed. The ``2to3`` tool
Raymond Hettinger6a883842008-07-22 19:27:12 +0000183 replaces every occurrence of :class:`basestring` with :class:`str`.
Christian Heimesf534f7b2008-01-25 11:02:28 +0000184
Georg Brandlec17d202008-02-02 10:44:37 +0000185* PEP 3137: There is a new type, :class:`bytes`, to represent binary data (and
186 encoded text, which is treated as binary data until you decide to decode it).
187 The :class:`str` and :class:`bytes` types cannot be mixed; you must always
188 explicitly convert between them, using the :meth:`str.encode` (str -> bytes)
189 or :meth:`bytes.decode` (bytes -> str) methods.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000190
Benjamin Petersona2f837f2008-04-28 21:05:10 +0000191* All backslashes in raw strings are interpreted literally. This means that
Guido van Rossum4a98a2a2008-11-21 18:35:43 +0000192 ``'\U'`` and ``'\u'`` escapes in raw strings are not treated specially.
Benjamin Petersona2f837f2008-04-28 21:05:10 +0000193
Georg Brandlec17d202008-02-02 10:44:37 +0000194.. XXX add bytearray
195
196* PEP 3112: Bytes literals, e.g. ``b"abc"``, create :class:`bytes` instances.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000197
198* PEP 3120: UTF-8 default source encoding.
199
Georg Brandlec17d202008-02-02 10:44:37 +0000200* PEP 3131: Non-ASCII identifiers. (However, the standard library remains
201 ASCII-only with the exception of contributor names in comments.)
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000202
203* PEP 3116: New I/O Implementation. The API is nearly 100% backwards
Georg Brandlec17d202008-02-02 10:44:37 +0000204 compatible, but completely reimplemented (currently mostly in Python). Also,
205 binary files use bytes instead of strings.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000206
Georg Brandlec17d202008-02-02 10:44:37 +0000207* The :mod:`StringIO` and :mod:`cStringIO` modules are gone. Instead, import
208 :class:`io.StringIO` or :class:`io.BytesIO`.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000209
Benjamin Petersona2f837f2008-04-28 21:05:10 +0000210
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000211
212PEP 3101: A New Approach to String Formatting
213=============================================
214
Guido van Rossum4a98a2a2008-11-21 18:35:43 +0000215* A new system for built-in string formatting operations replaces the
216 ``%`` string formatting operator. (However, the ``%`` operator is
217 still supported; it will be deprecated in Python 3.1 and removed
218 from the language at some later time.)
Georg Brandl396ef802008-02-02 10:30:18 +0000219
Guido van Rossum4a98a2a2008-11-21 18:35:43 +0000220.. XXX expand this
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000221
222
Georg Brandlec17d202008-02-02 10:44:37 +0000223PEP 3106: Revamping dict :meth:`dict.keys`, :meth:`dict.items` and :meth:`dict.values`
224======================================================================================
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000225
Georg Brandl396ef802008-02-02 10:30:18 +0000226.. XXX expand this
227
Georg Brandlec17d202008-02-02 10:44:37 +0000228* The :meth:`dict.iterkeys`, :meth:`dict.itervalues` and :meth:`dict.iteritems`
229 methods have been removed.
Georg Brandl396ef802008-02-02 10:30:18 +0000230
Georg Brandlec17d202008-02-02 10:44:37 +0000231* :meth:`dict.keys`, :meth:`dict.values` and :meth:`dict.items` return objects
Guido van Rossum4a98a2a2008-11-21 18:35:43 +0000232 with set behavior that reference the underlying dict; these are often
233 referred to as *dictionary views*.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000234
235
236PEP 3107: Function Annotations
237==============================
238
Georg Brandl396ef802008-02-02 10:30:18 +0000239.. XXX expand this
240
Georg Brandlec17d202008-02-02 10:44:37 +0000241* A standardized way of annotating a function's parameters and return values.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000242
243
244Exception Stuff
245===============
246
Georg Brandlec17d202008-02-02 10:44:37 +0000247* PEP 352: Exceptions must derive from :exc:`BaseException`. This is the root
248 of the exception hierarchy.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000249
Georg Brandlec17d202008-02-02 10:44:37 +0000250* :exc:`StandardError` was removed (already in 2.6).
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000251
Georg Brandlec17d202008-02-02 10:44:37 +0000252* Dropping sequence behavior (slicing!) and :attr:`message` attribute of
Georg Brandl5a165582007-08-31 06:15:01 +0000253 exception instances.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000254
Georg Brandlec17d202008-02-02 10:44:37 +0000255* PEP 3109: Raising exceptions. You must now use ``raise Exception(args)``
256 instead of ``raise Exception, args``.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000257
Georg Brandle06de8b2008-05-05 21:42:51 +0000258* PEP 3110: Catching exceptions. You must now use ``except SomeException as
259 identifier:`` instead of ``except Exception, identifier:``
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000260
Georg Brandlec17d202008-02-02 10:44:37 +0000261* PEP 3134: Exception chaining. (The :attr:`__context__` feature from the PEP
262 hasn't been implemented yet in 3.0a2.)
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000263
Georg Brandlec17d202008-02-02 10:44:37 +0000264* A few exception messages are improved when Windows fails to load an extension
265 module. For example, ``error code 193`` is now ``%1 is not a valid Win32
266 application``. Strings now deal with non-English locales.
Georg Brandl396ef802008-02-02 10:30:18 +0000267
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000268
269New Class and Metaclass Stuff
270=============================
271
272* Classic classes are gone.
273
274* PEP 3115: New Metaclass Syntax.
275
Skip Montanaroa86f5d42007-09-04 02:48:01 +0000276* PEP 3119: Abstract Base Classes (ABCs); ``@abstractmethod`` and
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000277 ``@abstractproperty`` decorators; collection ABCs.
278
279* PEP 3129: Class decorators.
280
281* PEP 3141: Numeric ABCs.
282
283
Georg Brandl116aa622007-08-15 14:28:22 +0000284Other Language Changes
285======================
286
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000287Here are most of the changes that Python 3.0 makes to the core Python
288language and built-in functions.
Georg Brandl116aa622007-08-15 14:28:22 +0000289
Georg Brandlec17d202008-02-02 10:44:37 +0000290* Removed backticks (use :func:`repr` instead).
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000291
292* Removed ``<>`` (use ``!=`` instead).
293
Georg Brandl396ef802008-02-02 10:30:18 +0000294* ``!=`` now returns the opposite of ``==``, unless ``==`` returns
295 ``NotImplemented``.
296
Georg Brandlec17d202008-02-02 10:44:37 +0000297* :keyword:`as` and :keyword:`with` are keywords.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000298
Georg Brandl396ef802008-02-02 10:30:18 +0000299* ``True``, ``False``, and ``None`` are keywords.
300
Georg Brandlec17d202008-02-02 10:44:37 +0000301* PEP 237: :class:`long` renamed to :class:`int`. That is, there is only one
302 built-in integral type, named :class:`int`; but it behaves like the old
303 :class:`long` type, with the exception that the literal suffix ``L`` is
304 neither supported by the parser nor produced by :func:`repr` anymore.
305 :data:`sys.maxint` was also removed since the int type has no maximum value
306 anymore.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000307
308* PEP 238: int division returns a float.
309
Georg Brandlec17d202008-02-02 10:44:37 +0000310* The ordering operators behave differently: for example, ``x < y`` where ``x``
311 and ``y`` have incompatible types raises :exc:`TypeError` instead of returning
312 a pseudo-random boolean.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000313
Georg Brandlec17d202008-02-02 10:44:37 +0000314* :meth:`__getslice__` and friends killed. The syntax ``a[i:j]`` now translates
315 to ``a.__getitem__(slice(i, j))`` (or :meth:`__setitem__` or
316 :meth:`__delitem__`, depending on context).
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000317
Georg Brandlec17d202008-02-02 10:44:37 +0000318* PEP 3102: Keyword-only arguments. Named parameters occurring after ``*args``
319 in the parameter list *must* be specified using keyword syntax in the call.
320 You can also use a bare ``*`` in the parameter list to indicate that you don't
321 accept a variable-length argument list, but you do have keyword-only
322 arguments.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000323
Georg Brandlec17d202008-02-02 10:44:37 +0000324* PEP 3104: :keyword:`nonlocal` statement. Using ``nonlocal x`` you can now
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000325 assign directly to a variable in an outer (but non-global) scope.
326
Georg Brandlec17d202008-02-02 10:44:37 +0000327* PEP 3111: :func:`raw_input` renamed to :func:`input`. That is, the new
328 :func:`input` function reads a line from :data:`sys.stdin` and returns it with
329 the trailing newline stripped. It raises :exc:`EOFError` if the input is
330 terminated prematurely. To get the old behavior of :func:`input`, use
331 ``eval(input())``.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000332
Georg Brandl67b8cad2008-04-09 07:32:07 +0000333* :func:`xrange` renamed to :func:`range`, so :func:`range` will no longer
334 produce a list but an iterable yielding integers when iterated over.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000335
Georg Brandlec17d202008-02-02 10:44:37 +0000336* PEP 3113: Tuple parameter unpacking removed. You can no longer write ``def
337 foo(a, (b, c)): ...``. Use ``def foo(a, b_c): b, c = b_c`` instead.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000338
Georg Brandlec17d202008-02-02 10:44:37 +0000339* PEP 3114: ``.next()`` renamed to :meth:`__next__`, new builtin :func:`next` to
340 call the :meth:`__next__` method on an object.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000341
Georg Brandlec17d202008-02-02 10:44:37 +0000342* PEP 3127: New octal literals; binary literals and :func:`bin`. Instead of
343 ``0666``, you write ``0o666``. The :func:`oct` function is modified
344 accordingly. Also, ``0b1010`` equals 10, and ``bin(10)`` returns
345 ``"0b1010"``. ``0666`` is now a :exc:`SyntaxError`.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000346
Georg Brandlec17d202008-02-02 10:44:37 +0000347* PEP 3132: Extended Iterable Unpacking. You can now write things like ``a, b,
348 *rest = some_sequence``. And even ``*rest, a = stuff``. The ``rest`` object
349 is always a list; the right-hand side may be any iterable.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000350
Georg Brandlec17d202008-02-02 10:44:37 +0000351* PEP 3135: New :func:`super`. You can now invoke :func:`super` without
352 arguments and the right class and instance will automatically be chosen. With
353 arguments, its behavior is unchanged.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000354
Georg Brandlec17d202008-02-02 10:44:37 +0000355* :func:`zip`, :func:`map` and :func:`filter` return iterators.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000356
Georg Brandlec17d202008-02-02 10:44:37 +0000357* :data:`string.letters` and its friends (:data:`string.lowercase` and
358 :data:`string.uppercase`) are gone. Use :data:`string.ascii_letters`
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000359 etc. instead.
360
Georg Brandlec17d202008-02-02 10:44:37 +0000361* Removed: :func:`apply`, :func:`callable`, :func:`coerce`, :func:`execfile`,
362 :func:`file`, :func:`reduce`, :func:`reload`.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000363
Georg Brandl0327e602008-02-18 22:20:55 +0000364* Removed: :meth:`dict.has_key` -- use the ``in`` operator instead.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000365
Georg Brandlec17d202008-02-02 10:44:37 +0000366* :func:`exec` is now a function.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000367
Georg Brandlec17d202008-02-02 10:44:37 +0000368* The :meth:`__oct__` and :meth:`__hex__` special methods are removed --
369 :func:`oct` and :func:`hex` use :meth:`__index__` now to convert the argument
370 to an integer.
Georg Brandl396ef802008-02-02 10:30:18 +0000371
Georg Brandlec17d202008-02-02 10:44:37 +0000372* Support is removed for :attr:`__members__` and :attr:`__methods__`.
Georg Brandl396ef802008-02-02 10:30:18 +0000373
Georg Brandlec17d202008-02-02 10:44:37 +0000374* Renamed the boolean conversion C-level slot and method: ``nb_nonzero`` is now
375 ``nb_bool`` and :meth:`__nonzero__` is now :meth:`__bool__`.
Georg Brandl396ef802008-02-02 10:30:18 +0000376
Georg Brandlec17d202008-02-02 10:44:37 +0000377* Removed :data:`sys.maxint`. Use :data:`sys.maxsize`.
Georg Brandl396ef802008-02-02 10:30:18 +0000378
Georg Brandl116aa622007-08-15 14:28:22 +0000379
Georg Brandl5a165582007-08-31 06:15:01 +0000380.. ======================================================================
Georg Brandl116aa622007-08-15 14:28:22 +0000381
382
383Optimizations
384-------------
385
386* Detailed changes are listed here.
387
Georg Brandlec17d202008-02-02 10:44:37 +0000388The net result of the 3.0 generalizations is that Python 3.0 runs the pystone
389benchmark around 33% slower than Python 2.5. There's room for improvement; we
390expect to be optimizing string and integer operations significantly before the
391final 3.0 release!
Georg Brandl116aa622007-08-15 14:28:22 +0000392
Georg Brandl5a165582007-08-31 06:15:01 +0000393.. ======================================================================
Georg Brandl116aa622007-08-15 14:28:22 +0000394
395
396New, Improved, and Deprecated Modules
397=====================================
398
Georg Brandlec17d202008-02-02 10:44:37 +0000399As usual, Python's standard library received a number of enhancements and bug
400fixes. Here's a partial list of the most notable changes, sorted alphabetically
401by module name. Consult the :file:`Misc/NEWS` file in the source tree for a more
402complete list of changes, or look through the Subversion logs for all the
403details.
Georg Brandl116aa622007-08-15 14:28:22 +0000404
Georg Brandlec17d202008-02-02 10:44:37 +0000405* The :mod:`cPickle` module is gone. Use :mod:`pickle` instead. Eventually
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000406 we'll have a transparent accelerator module.
Georg Brandl116aa622007-08-15 14:28:22 +0000407
Georg Brandlec17d202008-02-02 10:44:37 +0000408* The :mod:`imageop` module is gone.
Georg Brandl396ef802008-02-02 10:30:18 +0000409
Georg Brandlec17d202008-02-02 10:44:37 +0000410* The :mod:`audiodev`, :mod:`Bastion`, :mod:`bsddb185`, :mod:`exceptions`,
411 :mod:`linuxaudiodev`, :mod:`md5`, :mod:`MimeWriter`, :mod:`mimify`,
412 :mod:`popen2`, :mod:`rexec`, :mod:`sets`, :mod:`sha`, :mod:`stringold`,
413 :mod:`strop`, :mod:`sunaudiodev`, :mod:`timing`, and :mod:`xmllib` modules are
414 gone.
Georg Brandl396ef802008-02-02 10:30:18 +0000415
Gregory P. Smith7b9a2222008-09-04 05:07:03 +0000416* The :mod:`bsddb` module is gone. It is being maintained externally
417 with its own release schedule better mirroring that of BerkeleyDB.
418 See http://www.jcea.es/programacion/pybsddb.htm.
419
Georg Brandlec17d202008-02-02 10:44:37 +0000420* The :mod:`new` module is gone.
Georg Brandl396ef802008-02-02 10:30:18 +0000421
Georg Brandlec17d202008-02-02 10:44:37 +0000422* The functions :func:`os.tmpnam`, :func:`os.tempnam` and :func:`os.tmpfile`
423 have been removed in favor of the :mod:`tempfile` module.
Georg Brandl396ef802008-02-02 10:30:18 +0000424
Trent Nelson428de652008-03-18 22:41:35 +0000425* The :mod:`tokenize` module has been changed to work with bytes. The main
426 entry point is now :func:`tokenize.tokenize`, instead of generate_tokens.
427
Georg Brandl5a165582007-08-31 06:15:01 +0000428.. ======================================================================
429.. whole new modules get described in subsections here
Georg Brandl116aa622007-08-15 14:28:22 +0000430
Georg Brandl5a165582007-08-31 06:15:01 +0000431.. ======================================================================
Georg Brandl116aa622007-08-15 14:28:22 +0000432
433
434Build and C API Changes
435=======================
436
437Changes to Python's build process and to the C API include:
438
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000439* PEP 3118: New Buffer API.
440
441* PEP 3121: Extension Module Initialization & Finalization.
442
Georg Brandlec17d202008-02-02 10:44:37 +0000443* PEP 3123: Making :cmacro:`PyObject_HEAD` conform to standard C.
Georg Brandl116aa622007-08-15 14:28:22 +0000444
Georg Brandl396ef802008-02-02 10:30:18 +0000445* No more C API support for restricted execution.
446
Georg Brandlec17d202008-02-02 10:44:37 +0000447* :cfunc:`PyNumber_Coerce`, :cfunc:`PyNumber_CoerceEx`, :cfunc:`PyMember_Get`,
448 and :cfunc:`PyMember_Set` C APIs are removed.
Georg Brandl396ef802008-02-02 10:30:18 +0000449
Georg Brandlec17d202008-02-02 10:44:37 +0000450* New C API :cfunc:`PyImport_ImportModuleNoBlock`, works like
451 :cfunc:`PyImport_ImportModule` but won't block on the import lock (returning
Georg Brandl396ef802008-02-02 10:30:18 +0000452 an error instead).
453
Georg Brandl5a165582007-08-31 06:15:01 +0000454.. ======================================================================
Georg Brandl116aa622007-08-15 14:28:22 +0000455
456
457Port-Specific Changes
458---------------------
459
460Platform-specific changes go here.
461
Georg Brandl396ef802008-02-02 10:30:18 +0000462
Georg Brandl5a165582007-08-31 06:15:01 +0000463.. ======================================================================
Georg Brandl116aa622007-08-15 14:28:22 +0000464
465
Benjamin Petersonf10a79a2008-10-11 00:49:57 +0000466.. _30section-other:
Georg Brandl116aa622007-08-15 14:28:22 +0000467
468Other Changes and Fixes
469=======================
470
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000471As usual, there were a bunch of other improvements and bugfixes
472scattered throughout the source tree. A search through the change
473logs finds there were XXX patches applied and YYY bugs fixed between
474Python 2.6 and 3.0. Both figures are likely to be underestimates.
Georg Brandl116aa622007-08-15 14:28:22 +0000475
476Some of the more notable changes are:
477
478* Details go here.
479
Georg Brandl5a165582007-08-31 06:15:01 +0000480.. ======================================================================
Georg Brandl116aa622007-08-15 14:28:22 +0000481
482
483Porting to Python 3.0
484=====================
485
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000486This section lists previously described changes that may require
487changes to your code:
Georg Brandl116aa622007-08-15 14:28:22 +0000488
489* Everything is all in the details!
490
Georg Brandl72748582008-01-20 10:59:44 +0000491* Developers can include :file:`intobject.h` after :file:`Python.h` for
492 some ``PyInt_`` aliases.
Christian Heimesf78b1c62007-12-02 16:52:32 +0000493
Georg Brandl5a165582007-08-31 06:15:01 +0000494.. ======================================================================
Georg Brandl116aa622007-08-15 14:28:22 +0000495
496
497.. _acks:
498
499Acknowledgements
500================
501
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000502The author would like to thank the following people for offering
503suggestions, corrections and assistance with various drafts of this
Georg Brandl5a165582007-08-31 06:15:01 +0000504article: Georg Brandl.
Georg Brandl116aa622007-08-15 14:28:22 +0000505