blob: 51dff47157d92ee3fcd1a97e49ebc038bebff749 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001****************************
Guido van Rossumeb3d8d42008-12-02 00:56:25 +00002 What's New In Python 3.0
Georg Brandl116aa622007-08-15 14:28:22 +00003****************************
4
Guido van Rossum715287f2008-12-02 22:34:15 +00005.. XXX Add trademark info for Apple, Microsoft.
Georg Brandl116aa622007-08-15 14:28:22 +00006
Guido van Rossum715287f2008-12-02 22:34:15 +00007.. XXX Remove duplicates; just put info in the most relevant section.
Guido van Rossumeb3d8d42008-12-02 00:56:25 +00008
Guido van Rossum4a98a2a2008-11-21 18:35:43 +00009:Author: Guido van Rossum
10:Release: |release|
11:Date: |today|
12
13.. $Id$
14 Rules for maintenance:
Georg Brandl5a165582007-08-31 06:15:01 +000015
16 * Anyone can add text to this document. Do not spend very much time
17 on the wording of your changes, because your text will probably
18 get rewritten to some degree.
19
20 * The maintainer will go through Misc/NEWS periodically and add
21 changes; it's therefore more important to add your changes to
22 Misc/NEWS than to this file.
23
24 * This is not a complete list of every single change; completeness
25 is the purpose of Misc/NEWS. Some changes I consider too small
26 or esoteric to include. If such a change is added to the text,
27 I'll just remove it. (This is another reason you shouldn't spend
28 too much time on writing your addition.)
29
30 * If you want to draw your new text to the attention of the
31 maintainer, add 'XXX' to the beginning of the paragraph or
32 section.
33
34 * It's OK to just add a fragmentary note about a change. For
35 example: "XXX Describe the transmogrify() function added to the
36 socket module." The maintainer will research the change and
37 write the necessary text.
38
39 * You can comment out your additions if you like, but it's not
40 necessary (especially when a final release is some months away).
41
42 * Credit the author of a patch or bugfix. Just the name is
43 sufficient; the e-mail address isn't necessary.
44
45 * It's helpful to add the bug/patch number as a comment:
46
47 % Patch 12345
48 XXX Describe the transmogrify() function added to the socket
49 module.
50 (Contributed by P.Y. Developer.)
51
52 This saves the maintainer the effort of going through the SVN log
53 when researching a change.
Georg Brandl116aa622007-08-15 14:28:22 +000054
Guido van Rossumeb3d8d42008-12-02 00:56:25 +000055This article explains the new features in Python 3.0, compared to 2.6.
Guido van Rossum715287f2008-12-02 22:34:15 +000056Python 3.0, also known as "Python 3000" or "Py3k", is the first ever
57*intentionally incompatible* release. There are more changes than in
58a typical release, and more that are important for all Python users.
59Nevertheless, after digesting the changes, you'll find that Python
60really hasn't changed all that much -- by and large, we're merely
61fixing well-known annoyances and warts.
Guido van Rossumb197f3c2007-08-31 00:37:00 +000062
63This article doesn't attempt to provide a complete specification of
64the new features, but instead provides a convenient overview. For
65full details, you should refer to the documentation for Python 3.0. If
66you want to understand the complete implementation and design
67rationale, refer to the PEP for a particular new feature.
Georg Brandl116aa622007-08-15 14:28:22 +000068
Georg Brandl5a165582007-08-31 06:15:01 +000069.. Compare with previous release in 2 - 3 sentences here.
70.. add hyperlink when the documentation becomes available online.
Georg Brandl116aa622007-08-15 14:28:22 +000071
Georg Brandl5a165582007-08-31 06:15:01 +000072.. ======================================================================
73.. Large, PEP-level features and changes should be described here.
74.. Should there be a new section here for 3k migration?
75.. Or perhaps a more general section describing module changes/deprecation?
76.. sets module deprecated
77.. ======================================================================
Georg Brandl116aa622007-08-15 14:28:22 +000078
79
Guido van Rossumb197f3c2007-08-31 00:37:00 +000080Common Stumbling Blocks
81=======================
82
Guido van Rossum715287f2008-12-02 22:34:15 +000083This section lists those few changes that are most likely to trip you
84up if you're used to Python 2.5.
Guido van Rossumb197f3c2007-08-31 00:37:00 +000085
Guido van Rossumeb3d8d42008-12-02 00:56:25 +000086Print Is A Function
87-------------------
Guido van Rossumdff1c312007-09-06 14:46:41 +000088
Guido van Rossum715287f2008-12-02 22:34:15 +000089The :keyword:`print` statement has been replaced with a :func:`print`
90function, with keyword arguments to replace most of the special syntax
91of the old :keyword:`print` statement (:pep:`3105`). Examples::
Guido van Rossumdff1c312007-09-06 14:46:41 +000092
Guido van Rossumeb3d8d42008-12-02 00:56:25 +000093 Old: print "The answer is", 2*2
94 New: print("The answer is", 2*2)
Guido van Rossumdff1c312007-09-06 14:46:41 +000095
Guido van Rossumeb3d8d42008-12-02 00:56:25 +000096 Old: print x, # Trailing comma suppresses newline
97 New: print(x, end=" ") # Appends a space instead of a newline
Guido van Rossumdff1c312007-09-06 14:46:41 +000098
Guido van Rossumeb3d8d42008-12-02 00:56:25 +000099 Old: print # Prints a newline
100 New: print() # You must call the function!
Guido van Rossumdff1c312007-09-06 14:46:41 +0000101
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000102 Old: print >>sys.stderr, "fatal error"
103 New: print("fatal error", file=sys.stderr)
Guido van Rossumdff1c312007-09-06 14:46:41 +0000104
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000105 Old: print (x, y) # prints repr((x, y))
106 New: print((x, y)) # Not the same as print(x, y)!
Guido van Rossumdff1c312007-09-06 14:46:41 +0000107
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000108You can also customize the separator between items, e.g.::
Guido van Rossumdff1c312007-09-06 14:46:41 +0000109
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000110 print("There are <", 2**32, "> possibilities!", sep="")
Guido van Rossumdff1c312007-09-06 14:46:41 +0000111
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000112which produces::
Guido van Rossumdff1c312007-09-06 14:46:41 +0000113
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000114 There are <4294967296> possibilities!
Guido van Rossumdff1c312007-09-06 14:46:41 +0000115
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000116Note:
Guido van Rossumdff1c312007-09-06 14:46:41 +0000117
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000118* The :func:`print` function doesn't support the "softspace" feature of
Guido van Rossum715287f2008-12-02 22:34:15 +0000119 the old :keyword:`print` statement. For example, in Python 2.x,
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000120 ``print "A\n", "B"`` would write ``"A\nB\n"``; but in Python 3.0,
121 ``print("A\n", "B")`` writes ``"A\n B\n"``.
Guido van Rossumdff1c312007-09-06 14:46:41 +0000122
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000123* Initially, you'll be finding yourself typing the old ``print x``
124 a lot in interactive mode. Time to retrain your fingers to type
125 ``print(x)`` instead!
Guido van Rossumdff1c312007-09-06 14:46:41 +0000126
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000127* When using the ``2to3`` source-to-source conversion tool, all
Guido van Rossum715287f2008-12-02 22:34:15 +0000128 :keyword:`print` statements are automatically converted to
129 :func:`print` function calls, so this is mostly a non-issue for
130 larger projects.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000131
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000132Text Strings Vs. Bytes
133----------------------
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000134
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000135Everything you thought you knew about binary data and Unicode has
Guido van Rossum715287f2008-12-02 22:34:15 +0000136changed. There's a longer section below; here's a summary of the
137changes:
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000138
139* Python 3.0 uses *strings* and *bytes* instead of *Unicode strings*
140 and *8-bit strings*. The difference is that any attempt to mix
141 strings and bytes in Python 3.0 raises a TypeError exception,
142 whereas if you were to mix Unicode and 8-bit strings in Python 2.x,
143 you would only get an exception if the 8-bit string contained
144 non-ASCII values. As a consequence, pretty much all code that
145 uses Unicode, encodings or binary data most likely has to change.
146 The change is for the better, as in the 2.x world there were
147 numerous bugs having to do with mixing encoded and unencoded text.
148
149* Files opened as text files (still the default mode for :func:`open`)
150 always use an encoding to map between strings (in memory) and bytes
151 (on disk). Binary files (opened with a ``b`` in the mode argument)
152 always use bytes in memory. This means that if a file is opened
153 using an incorrect mode or encoding, I/O will likely fail. There is
154 a platform-dependent default encoding, which on Unixy platforms can
155 be set with the ``LANG`` environment variable (and sometimes also
156 with some other platform-specific locale-related environment
157 variables). In many cases, but not all, the system default is
Walter Dörwalda4438562008-12-02 11:55:30 +0000158 UTF-8; you should never count on this default. Any application
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000159 reading or writing more than pure ASCII text should probably have a
160 way to override the encoding.
161
Guido van Rossum715287f2008-12-02 22:34:15 +0000162* The builtin :class:`basestring` abstract type was removed. Use
163 :class:`str` instead. The :class:`str` and :class:`bytes` types
164 don't have functionality enough in common to warrant a shared base
165 class.
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000166
Guido van Rossum715287f2008-12-02 22:34:15 +0000167* See also the :ref:`unicode-howto`, which was updated for Python 3.0.
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000168
169Views And Interators Instead Of Lists
170-------------------------------------
171
172Some well-known APIs no longer return lists:
173
174* :class:`dict` methods :meth:`dict.keys`, :meth:`dict.items` and
175 :meth:`dict.values` return "views" instead of lists. For example,
176 this no longer works: ``k = d.keys(); k.sort()``. Use ``k =
177 sorted(d)`` instead.
178
179* Also, the :meth:`dict.iterkeys`, :meth:`dict.iteritems` and
180 :meth:`dict.itervalues` methods are no longer supported.
Guido van Rossum4a98a2a2008-11-21 18:35:43 +0000181
Georg Brandlec17d202008-02-02 10:44:37 +0000182* :func:`map` and :func:`filter` return iterators. A quick fix is e.g.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000183 ``list(map(...))``, but a better fix is often to use a list
Georg Brandlec17d202008-02-02 10:44:37 +0000184 comprehension (especially when the original code uses :keyword:`lambda`).
185 Particularly tricky is :func:`map` invoked for the side effects of the
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000186 function; the correct transformation is to use a for-loop.
187
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000188* :func:`range` now behaves like :func:`xrange` used to behave.
189 The latter no longer exists.
190
191* :func:`zip` now returns an iterator.
192
193* XXX More below?
194
195Ordering Comparisons
196--------------------
197
198Python 3.0 has simplified the rules for ordering comparisons:
199
200* The ordering comparison operators (``<``, ``<=``, ``>=``, ``>``)
201 raise a TypeError exception when the operands don't have a
202 meaningful natural ordering. Thus, expressions like ``1 < ''``, ``0
203 > None`` or ``len <= len`` are no longer valid. A corollary is that
204 sorting a heterogeneous list no longer makes sense -- all the
205 elements must be comparable to each other. Note that this does not
206 apply to the ``==`` and ``!=`` operators: objects of different
207 uncomparable types always compare unequal to each other, and an
208 object always compares equal to itself (i.e., ``x is y`` implies ``x
209 = y``; this is true even for ``NaN``).
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000210
Kurt B. Kaiser2bc6b5e2008-02-13 18:03:11 +0000211* :meth:`builtin.sorted` and :meth:`list.sort` no longer accept the *cmp*
Kurt B. Kaiser9d0d6162008-02-14 02:47:50 +0000212 argument providing a comparison function. Use the *key* argument
Kurt B. Kaiser2bc6b5e2008-02-13 18:03:11 +0000213 instead. N.B. the *key* and *reverse* arguments are now "keyword-only".
Kurt B. Kaisera1401012008-02-13 16:09:27 +0000214
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000215* The :func:`cmp` function is gone, and the :meth:`__cmp__` special
216 method is no longer supported. Use :meth:`__lt__` for sorting,
217 :meth:`__eq__` with :meth:`__hash__`, and other rich comparisons as
218 needed. if you really need the :func:`cmp` functionality, the
219 expression ``(a > b) - (a < b)`` is equivalent to ``cmp(a, b)``.
220
221* XXX More below?
222
223Integers
224--------
225
Guido van Rossum715287f2008-12-02 22:34:15 +0000226* :pep:`0237`: :class:`long` renamed to :class:`int`. That is, there
227 is only one built-in integral type, named :class:`int`; but it
228 behaves mostly like the old :class:`long` type.
Guido van Rossum4a98a2a2008-11-21 18:35:43 +0000229
Georg Brandlec17d202008-02-02 10:44:37 +0000230* The :func:`repr` of a long integer doesn't include the trailing ``L``
Georg Brandlcc595bd2007-12-09 09:04:01 +0000231 anymore, so code that unconditionally strips that character will
Guido van Rossum715287f2008-12-02 22:34:15 +0000232 chop off the last digit instead. (Use :func:`str` instead.)
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000233
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000234* The :data:`sys.maxint` constant was removed, since there is no
235 longer a limit to the value of ints. However, :data:`sys.maxsize`
236 can be used as an integer larger than any practical list or string
237 index. It conforms to the implementation's "natural" integer size
238 and is typically the same as :data:`sys.maxint` in previous releases
239 on the same platform (assuming the same build options).
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000240
Guido van Rossum715287f2008-12-02 22:34:15 +0000241* ``1/2`` returns a float. Use ``1//2`` to get the truncating behavior.
242 (The latter syntax has existed for years, at least since Python 2.2.)
243 See :pep:`0238`.
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000244
245
246Overview Of Syntactic Changes
247=============================
248
249This section gives a brief overview of every *syntactic* change.
250Several of these are discussed at greater length later.
251
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000252Additions
253---------
254
255* Function argument and return value annotations (see below). XXX
256
Guido van Rossum715287f2008-12-02 22:34:15 +0000257* :pep:`3102`: Keyword-only arguments. Named parameters occurring
258 after ``*args`` in the parameter list *must* be specified using
259 keyword syntax in the call. You can also use a bare ``*`` in the
260 parameter list to indicate that you don't accept a variable-length
261 argument list, but you do have keyword-only arguments.
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000262
263* Keyword arguments are allowed after the list of base classes in a
264 class definition. This is used by the new convention for specifying
265 a metaclass, but can be used for other purposes as well, as long as
266 the metaclass supports it.
267
Guido van Rossum715287f2008-12-02 22:34:15 +0000268* :pep:`3104`: :keyword:`nonlocal` statement. Using ``nonlocal x``
269 you can now assign directly to a variable in an outer (but
270 non-global) scope. :keyword:`nonlocal` is a new reserved word.
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000271
Guido van Rossum715287f2008-12-02 22:34:15 +0000272* :pep:`3132`: Extended Iterable Unpacking. You can now write things
273 like ``a, b, *rest = some_sequence``. And even ``*rest, a =
274 stuff``. The ``rest`` object is always a (possibly empty) list; the
275 right-hand side may be any iterable. Example::
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000276
Guido van Rossum715287f2008-12-02 22:34:15 +0000277 (a, *rest, b) = range(5)
278
279 This sets *a* to ``0``, *b* to ``4``, and \*rest to ``[1, 2, 3]``.
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000280
281* Dictionary comprehensions: ``{k: v for k, v in stuff}`` means the
282 same thing as ``dict(stuff)`` but is more flexible.
283
284* Set literals, e.g. ``{1, 2}``. Note that ``{}`` is an empty
Guido van Rossum715287f2008-12-02 22:34:15 +0000285 dictionary; use ``set()`` for an empty set. Set comprehensions are
286 also supported; ``{x for x in stuff}`` means the same thing as
287 ``set(stuff)`` but is more flexible.
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000288
289* New octal literals, e.g. ``0o720`` (already in 2.6). The old octal
Walter Dörwaldeab34c92008-12-02 11:58:09 +0000290 literals (``0720``) are gone.
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000291
292* New binary literals, e.g. ``0b1010`` (already in 2.6).
293
294* Bytes literals are introduced with a leading ``b`` or ``B``.
295
296Changes
297-------
298
299* New :keyword:`raise` statement syntax: ``raise [expr [from expr]]``.
Guido van Rossum715287f2008-12-02 22:34:15 +0000300 Also note that string exceptions are no longer legal (:pep:`0352`).
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000301
Guido van Rossum715287f2008-12-02 22:34:15 +0000302* :keyword:`as` and :keyword:`with` are now reserved words. (Since
303 2.6, actually.)
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000304
Guido van Rossum715287f2008-12-02 22:34:15 +0000305* :keyword:`True`, :keyword:`False`, and :keyword:`None` are reserved
306 words. (2.6 partially enforced the restrictions on :keyword:`None`
307 already.)
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000308
Guido van Rossum715287f2008-12-02 22:34:15 +0000309* Change from :keyword:`except` *exc*, *var* to
310 :keyword:`except` *exc* :keyword:`as` *var*. See :pep:`3110`.
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000311
Guido van Rossum715287f2008-12-02 22:34:15 +0000312* List comprehensions no longer support the syntactic form
313 ``[... for var in item1, item2, ...]``. Use
314 ``[... for var in (item1, item2, ...)]`` instead.
315 Also note that list comprehensions have different semantics: they
316 are closer to syntactic sugar for a generator expression inside a
317 :func:`list` constructor, and in particular the loop control
318 variables are no longer leaked into the surrounding scope.
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000319
Guido van Rossum715287f2008-12-02 22:34:15 +0000320* The *ellipsis* (``...``) can be used as an atomic expression
321 anywhere. (Previously it was only allowed in slices.) Also, it
322 *must* now be spelled as ``...``. (Previously it could also be
323 spelled as ``. . .``, by a mere accident of the grammar.)
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000324
325Removals
326--------
327
Guido van Rossum715287f2008-12-02 22:34:15 +0000328* :pep:`3113`: Tuple parameter unpacking removed. You can no longer
329 write ``def foo(a, (b, c)): ...``.
330 Use ``def foo(a, b_c): b, c = b_c`` instead.
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000331
Guido van Rossum715287f2008-12-02 22:34:15 +0000332* Removed backticks (use :func:`repr` instead).
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000333
Guido van Rossum715287f2008-12-02 22:34:15 +0000334* Removed ``<>`` (use ``!=`` instead).
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000335
336* Removed keyword: :func:`exec` is no longer a keyword; it remains as
337 a function. (Fortunately the function syntax was also accepted in
Guido van Rossum715287f2008-12-02 22:34:15 +0000338 2.x.) Also note that :func:`exec` no longer takes a stream argument;
339 instead of ``exec(f)`` you can use ``exec(f.read())``.
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000340
341* Integer literals no longer support a trailing ``l`` or ``L``.
342
343* String literals no longer support a leading ``u`` or ``U``.
344
Guido van Rossum715287f2008-12-02 22:34:15 +0000345* The :keyword:`from` *module* :keyword:`import` ``*`` syntax is only
346 allowed at the module level, no longer inside functions.
347
348* The only acceptable syntax for relative imports is :keyword:`from`
349 ``.``[*module*] :keyword:`import` *name*; :keyword:`import` forms
350 not starting with ``.`` are always interpreted as absolute imports.
351 (:pep:`0328`)
352
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000353
354
355Changes Already Present In Python 2.6
356=====================================
357
Guido van Rossum715287f2008-12-02 22:34:15 +0000358Since many users presumably make the jump straight from Python 2.5 to
359Python 3.0, this section reminds the reader of new features that were
360originally designed for Python 3.0 but that were back-ported to Python
3612.6. The corresponding sections in :ref:`whats-new-in-2.6` should be
Guido van Rossum5b78dd92008-12-02 17:31:14 +0000362consulted for longer descriptions.
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000363
Guido van Rossum715287f2008-12-02 22:34:15 +0000364* :ref:`pep-0343`. The :keyword:`with` statement is now a standard
365 feature and no longer needs to be imported from the ``__future__``.
366 Also check out :ref:`new-26-context-managers` and
367 :ref:`new-module-contextlib`.
Guido van Rossum5b78dd92008-12-02 17:31:14 +0000368
Guido van Rossum715287f2008-12-02 22:34:15 +0000369* :ref:`pep-0366`. This enhances the usefulness of the :option:`-m`
370 option when the referenced module lives in a package.
Guido van Rossum5b78dd92008-12-02 17:31:14 +0000371
Guido van Rossum715287f2008-12-02 22:34:15 +0000372* :ref:`pep-0370`.
Guido van Rossum5b78dd92008-12-02 17:31:14 +0000373
Guido van Rossum715287f2008-12-02 22:34:15 +0000374* :ref:`pep-0371`.
Guido van Rossum5b78dd92008-12-02 17:31:14 +0000375
Guido van Rossum715287f2008-12-02 22:34:15 +0000376* :ref:`pep-3101`. Note: the 2.6 description mentions the
377 :meth:`format` method for both 8-bit and Unicode strings. In 3.0,
378 only the :class:`str` type (text strings with Unicode support)
379 supports this method; the :class:`bytes` type does not. The plan is
380 to eventually make this the only API for string formatting, and to
381 start deprecating the ``%`` operator in Python 3.1.
Guido van Rossum5b78dd92008-12-02 17:31:14 +0000382
Guido van Rossum715287f2008-12-02 22:34:15 +0000383* :ref:`pep-3105`. This is now a standard feature and no longer needs
384 to be imported from :mod:`__future__`.
Guido van Rossum5b78dd92008-12-02 17:31:14 +0000385
Guido van Rossum715287f2008-12-02 22:34:15 +0000386* :ref:`pep-3110`. The :keyword:`except` *exc* :keyword:`as` *var*
387 syntax is now standard and :keyword:`except` *exc*, *var* is no
388 longer supported. (Of course, the :keyword:`as` *var* part is still
389 optional.)
Guido van Rossum5b78dd92008-12-02 17:31:14 +0000390
Guido van Rossum715287f2008-12-02 22:34:15 +0000391* :ref:`pep-3112`. The ``b"..."`` string literal notation (and its
392 variants like ``b'...'``, ``b"""..."""``, and ``br"..."``) now
393 produces a literal of type :class:`bytes`. More about
394 :class:`bytes` below.
Guido van Rossum5b78dd92008-12-02 17:31:14 +0000395
Guido van Rossum715287f2008-12-02 22:34:15 +0000396* :ref:`pep-3116`. The :mod:`io` module is now the standard way of
397 doing file I/O, and the initial values of :data:`sys.stdin`,
398 :data:`sys.stdout` and :data:`sys.stderr` are now instances of
399 :class:`io.TextIOBase`. The builtin :func:`open` function is now an
400 alias for :func:`io.open` and has additional keyword arguments
401 *encoding*, *errors*, *newline* and *closefd*. Also note that an
402 invalid *mode* argument now raises :exc:`ValueError`, not
403 :exc:`IOError`.
Guido van Rossum5b78dd92008-12-02 17:31:14 +0000404
Guido van Rossum715287f2008-12-02 22:34:15 +0000405* :ref:`pep-3118`. The old builtin :func:`buffer` is now really gone;
406 the new builtin :func:`memoryview` provides (mostly) similar
407 functionality.
Guido van Rossum5b78dd92008-12-02 17:31:14 +0000408
Guido van Rossum715287f2008-12-02 22:34:15 +0000409* :ref:`pep-3119`. The :mod:`abc` module and the ABCs defined in the
410 :mod:`collections` module plays a slightly more prominent role in
411 the language now, and builtin collection types like :class:`dict`
412 and :class:`list` conform to the :class:`collections.MutableMapping`
413 and :class:`collections.MutableSequence` ABC, respectively.
Guido van Rossum5b78dd92008-12-02 17:31:14 +0000414
Guido van Rossum715287f2008-12-02 22:34:15 +0000415* :ref:`pep-3127`. As mentioned above, the new octal literal
416 notation is the only one supported, and binary literals have been
417 added.
Guido van Rossum5b78dd92008-12-02 17:31:14 +0000418
Guido van Rossum715287f2008-12-02 22:34:15 +0000419* :ref:`pep-3129`. This speaks for itself.
Guido van Rossum5b78dd92008-12-02 17:31:14 +0000420
Guido van Rossum715287f2008-12-02 22:34:15 +0000421* :ref:`pep-3141`. The :mod:`numbers` module is another new use of
422 ABCs, defining Python's "numeric tower". Also note the new
423 :mod:`fractions` module.
Guido van Rossum5b78dd92008-12-02 17:31:14 +0000424
425
426Library Changes
427===============
428
Guido van Rossum56076da2008-12-02 22:58:36 +0000429Due to time constraints, this document does not exhaustively cover
430the very extensive changes to the library.
431
Guido van Rossum5b78dd92008-12-02 17:31:14 +0000432XXX Brief overview of what's changed in the library.
433
Guido van Rossum715287f2008-12-02 22:34:15 +0000434* :pep:`3108`: stdlib reorganization.
435
436* Killed :mod:`sets`. Use the builtin :func:`set` function.
437
438* XXX macfs, new, reconvert, stringold, xmllib, pcre, pypcre, strop
439
440* XXX :pep:`4`
441
442* XXX lib-old: Para, addpack, cmp, cmpcache, codehack, dircmp, dump,
443 find, fmt, grep, lockfile, newdir, ni, packmail, poly, rand,
444 statcache, tb, tzparse, util, whatsound, whrandom, zmod
445
446* XXX Removed sys.exitfunc
447
448* XXX Removed sys.exc_clear
449
450* XXX Removed sys.exc_type, exc_value, exc_traceback. (sys.last_type
451 etc. remain.)
452
453* XXX array.read, array.write
454
455* XXX operator.sequenceIncludes
456
457* XXX thread.acquire_lock and thread.release_lock
458
459* XXX UserXXX -> XXXMixin?
460
461* XXX removed random.jumpahead API
462
463* XXX cookie module revamps
464
465* XXX heapq revamp
466
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000467
468Strings And Bytes
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000469=================
470
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000471This section discusses the many changes in string
472
Georg Brandlec17d202008-02-02 10:44:37 +0000473* There is only one string type; its name is :class:`str` but its behavior and
474 implementation are like :class:`unicode` in 2.x.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000475
Georg Brandlec17d202008-02-02 10:44:37 +0000476* The :class:`basestring` superclass has been removed. The ``2to3`` tool
Raymond Hettinger6a883842008-07-22 19:27:12 +0000477 replaces every occurrence of :class:`basestring` with :class:`str`.
Christian Heimesf534f7b2008-01-25 11:02:28 +0000478
Guido van Rossum715287f2008-12-02 22:34:15 +0000479* :pep:`3137`: There is a new type, :class:`bytes`, to represent
480 binary data (and encoded text, which is treated as binary data until
481 you decide to decode it). The :class:`str` and :class:`bytes` types
482 cannot be mixed; you must always explicitly convert between them,
483 using the :meth:`str.encode` (str -> bytes) or :meth:`bytes.decode`
484 (bytes -> str) methods.
485
486.. XXX add bytearray
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000487
Benjamin Petersona2f837f2008-04-28 21:05:10 +0000488* All backslashes in raw strings are interpreted literally. This means that
Guido van Rossum4a98a2a2008-11-21 18:35:43 +0000489 ``'\U'`` and ``'\u'`` escapes in raw strings are not treated specially.
Benjamin Petersona2f837f2008-04-28 21:05:10 +0000490
Guido van Rossum715287f2008-12-02 22:34:15 +0000491* :pep:`3138`: :func:`repr` of a string no longer escapes all
492 non-ASCII characters. XXX
Georg Brandlec17d202008-02-02 10:44:37 +0000493
Guido van Rossum715287f2008-12-02 22:34:15 +0000494* :pep:`3112`: Bytes literals, e.g. ``b"abc"``, create :class:`bytes`
495 instances.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000496
Guido van Rossum715287f2008-12-02 22:34:15 +0000497* :pep:`3120`: UTF-8 default source encoding.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000498
Guido van Rossum715287f2008-12-02 22:34:15 +0000499* :pep:`3131`: Non-ASCII identifiers. (However, the standard library remains
Georg Brandlec17d202008-02-02 10:44:37 +0000500 ASCII-only with the exception of contributor names in comments.)
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000501
Guido van Rossum715287f2008-12-02 22:34:15 +0000502* :pep:`3116`: New I/O Implementation. The API is nearly 100% backwards
Georg Brandlec17d202008-02-02 10:44:37 +0000503 compatible, but completely reimplemented (currently mostly in Python). Also,
504 binary files use bytes instead of strings.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000505
Georg Brandlec17d202008-02-02 10:44:37 +0000506* The :mod:`StringIO` and :mod:`cStringIO` modules are gone. Instead, import
507 :class:`io.StringIO` or :class:`io.BytesIO`.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000508
Benjamin Petersona2f837f2008-04-28 21:05:10 +0000509
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000510
Guido van Rossum715287f2008-12-02 22:34:15 +0000511:pep:`3101`: A New Approach To String Formatting
512================================================
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000513
Guido van Rossum4a98a2a2008-11-21 18:35:43 +0000514* A new system for built-in string formatting operations replaces the
515 ``%`` string formatting operator. (However, the ``%`` operator is
516 still supported; it will be deprecated in Python 3.1 and removed
517 from the language at some later time.)
Georg Brandl396ef802008-02-02 10:30:18 +0000518
Guido van Rossum4a98a2a2008-11-21 18:35:43 +0000519.. XXX expand this
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000520
521
Guido van Rossum715287f2008-12-02 22:34:15 +0000522:pep:`3106`: Revamping dict :meth:`dict.keys`, :meth:`dict.items` and :meth:`dict.values`
523=========================================================================================
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000524
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000525.. XXX expand this (but note that the "pitfalls" section currently has
526.. XXX more detail :-)
Georg Brandl396ef802008-02-02 10:30:18 +0000527
Georg Brandlec17d202008-02-02 10:44:37 +0000528* The :meth:`dict.iterkeys`, :meth:`dict.itervalues` and :meth:`dict.iteritems`
529 methods have been removed.
Georg Brandl396ef802008-02-02 10:30:18 +0000530
Georg Brandlec17d202008-02-02 10:44:37 +0000531* :meth:`dict.keys`, :meth:`dict.values` and :meth:`dict.items` return objects
Guido van Rossum4a98a2a2008-11-21 18:35:43 +0000532 with set behavior that reference the underlying dict; these are often
533 referred to as *dictionary views*.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000534
535
Guido van Rossum715287f2008-12-02 22:34:15 +0000536:pep:`3107`: Function Annotations
537=================================
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000538
Georg Brandl396ef802008-02-02 10:30:18 +0000539.. XXX expand this
540
Georg Brandlec17d202008-02-02 10:44:37 +0000541* A standardized way of annotating a function's parameters and return values.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000542
543
544Exception Stuff
545===============
546
Guido van Rossum715287f2008-12-02 22:34:15 +0000547* :pep:`0352`: All exceptions must be derived (directly or indirectly)
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000548 from :exc:`BaseException`. This is the root of the exception
549 hierarchy. Most exceptions should actually be derived from
550 :exc:`Exception`. This is not a new recommendation, but the
551 *requirement* to inherit from :exc:`BaseException` is new. (Python
552 2.6 still allowed classic classes to be raised, and placed no
553 restriction on what you can catch.)
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000554
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000555* :exc:`StandardError` was removed (in 2.6, actually).
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000556
Georg Brandlec17d202008-02-02 10:44:37 +0000557* Dropping sequence behavior (slicing!) and :attr:`message` attribute of
Georg Brandl5a165582007-08-31 06:15:01 +0000558 exception instances.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000559
Guido van Rossum715287f2008-12-02 22:34:15 +0000560* :pep:`3109`: Raising exceptions. You must now use ``raise Exception(args)``
Georg Brandlec17d202008-02-02 10:44:37 +0000561 instead of ``raise Exception, args``.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000562
Guido van Rossum715287f2008-12-02 22:34:15 +0000563* :pep:`3110`: Catching exceptions. You must now use ``except SomeException as
Georg Brandle06de8b2008-05-05 21:42:51 +0000564 identifier:`` instead of ``except Exception, identifier:``
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000565
Guido van Rossum715287f2008-12-02 22:34:15 +0000566* :pep:`3134`: Exception chaining. XXX
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000567
Georg Brandlec17d202008-02-02 10:44:37 +0000568* A few exception messages are improved when Windows fails to load an extension
569 module. For example, ``error code 193`` is now ``%1 is not a valid Win32
570 application``. Strings now deal with non-English locales.
Georg Brandl396ef802008-02-02 10:30:18 +0000571
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000572
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000573New Class And Metaclass Stuff
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000574=============================
575
576* Classic classes are gone.
577
Guido van Rossum715287f2008-12-02 22:34:15 +0000578* :pep:`3115`: New Metaclass Syntax.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000579
Guido van Rossum715287f2008-12-02 22:34:15 +0000580* :pep:`3119`: Abstract Base Classes (ABCs); ``@abstractmethod`` and
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000581 ``@abstractproperty`` decorators; collection ABCs.
582
Guido van Rossum715287f2008-12-02 22:34:15 +0000583* :pep:`3129`: Class decorators.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000584
Guido van Rossum715287f2008-12-02 22:34:15 +0000585* :pep:`3141`: Numeric ABCs.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000586
587
Georg Brandl116aa622007-08-15 14:28:22 +0000588Other Language Changes
589======================
590
Guido van Rossum715287f2008-12-02 22:34:15 +0000591* Moved :func:`intern` to :func:`sys.intern`.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000592
Georg Brandl396ef802008-02-02 10:30:18 +0000593* ``!=`` now returns the opposite of ``==``, unless ``==`` returns
594 ``NotImplemented``.
595
Guido van Rossum715287f2008-12-02 22:34:15 +0000596* The concept of "unbound methods" was removed from the language.
597 When referencing a method as a class attribute, you now get a plain
598 function object.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000599
Guido van Rossum715287f2008-12-02 22:34:15 +0000600* :meth:`__getslice__`, :meth:`__setslice__` and :meth:`__delslice__`
601 were killed. The syntax ``a[i:j]`` now translates to
602 ``a.__getitem__(slice(i, j))`` (or :meth:`__setitem__` or
603 :meth:`__delitem__`, when used as an assignment or deletion target,
604 respectively).
Georg Brandl396ef802008-02-02 10:30:18 +0000605
Guido van Rossum715287f2008-12-02 22:34:15 +0000606* :pep:`3111`: :func:`raw_input` renamed to :func:`input`. That is,
607 the new :func:`input` function reads a line from :data:`sys.stdin`
608 and returns it with the trailing newline stripped. It raises
609 :exc:`EOFError` if the input is terminated prematurely. To get the
610 old behavior of :func:`input`, use ``eval(input())``.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000611
Guido van Rossum715287f2008-12-02 22:34:15 +0000612* :func:`xrange` renamed to :func:`range`, so :func:`range` will no
613 longer produce a list but an iterable yielding integers when
614 iterated over. XXX dupe
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000615
Guido van Rossum715287f2008-12-02 22:34:15 +0000616* :pep:`3114`: ``.next()`` renamed to :meth:`__next__`, new builtin
617 :func:`next` to call the :meth:`__next__` method on an object.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000618
Guido van Rossum715287f2008-12-02 22:34:15 +0000619* :pep:`3135`: New :func:`super`. You can now invoke :func:`super`
620 without arguments and the right class and instance will
621 automatically be chosen. With arguments, its behavior is unchanged.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000622
Georg Brandlec17d202008-02-02 10:44:37 +0000623* :func:`zip`, :func:`map` and :func:`filter` return iterators.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000624
Georg Brandlec17d202008-02-02 10:44:37 +0000625* :data:`string.letters` and its friends (:data:`string.lowercase` and
Guido van Rossum715287f2008-12-02 22:34:15 +0000626 :data:`string.uppercase`) are gone. Use
627 :data:`string.ascii_letters` etc. instead. (The reason for the
628 removal is that :data:string.letters` and friends had
629 locale-specific behavior, which is a bad idea for such
630 attractively-named global "constants".)
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000631
Guido van Rossum715287f2008-12-02 22:34:15 +0000632* Removed: :func:`apply`. Instead of ``apply(f, args)`` use
633 ``f(*args)``.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000634
Guido van Rossum715287f2008-12-02 22:34:15 +0000635* Removed :func:`callable`. Instead of ``callable(f)`` you can use
636 ``hasattr(f, '__call__')``. The :func:`operator.isCallable` function
637 is also gone.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000638
Guido van Rossum715287f2008-12-02 22:34:15 +0000639* Removed :func:`coerce`. This function no longer serves a purpose
640 now that classic classes are gone.
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000641
Guido van Rossum715287f2008-12-02 22:34:15 +0000642* Removed :func:`execfile`. Instead of ``execfile(fn)`` use
643 ``exec(open(fn).read())``.
Georg Brandl396ef802008-02-02 10:30:18 +0000644
Guido van Rossum715287f2008-12-02 22:34:15 +0000645* Removed :class:`file`. Use :func:`open`.
Georg Brandl396ef802008-02-02 10:30:18 +0000646
Guido van Rossum715287f2008-12-02 22:34:15 +0000647* Removed :func:`reduce`. Use :func:`functools.reduce` if you really
648 need it; however, 99 percent of the time an explicit :keyword:`for`
649 loop is more readable.
Georg Brandl396ef802008-02-02 10:30:18 +0000650
Guido van Rossum715287f2008-12-02 22:34:15 +0000651* Removed :func:`reload`. Use :func:`imp.reload`.
652
653* Removed. :meth:`dict.has_key` -- use the :keyword:`in` operator
654 instead.
655
656* The :meth:`__oct__` and :meth:`__hex__` special methods are removed
657 -- :func:`oct` and :func:`hex` use :meth:`__index__` now to convert
658 the argument to an integer.
659
660* Removed support for :attr:`__members__` and :attr:`__methods__`.
661
662* Renamed the boolean conversion C-level slot and method:
663 ``nb_nonzero`` is now ``nb_bool`` and :meth:`__nonzero__` is now
664 :meth:`__bool__`.
665
666* Renamed module :mod:`__builtin__` to :mod:`builtins` (removing the
667 underscores, adding an 's'). The :data:`__builtins__` variable
668 found in most global namespaces is unchanged. To modify a builtin,
669 you should use :mod:`builtins`, not :data:`__builtins__`!
670
671* Renamed function attributes :attr:`func_whatever` to
672 :attr:`__whatever__`. XXX list every single one.
673
674* Removed :exc:`StandardError`.
675
676* Removed METH_OLDARGS and WITH_CYCLE_GC. XXX more.
Georg Brandl116aa622007-08-15 14:28:22 +0000677
Georg Brandl5a165582007-08-31 06:15:01 +0000678.. ======================================================================
Georg Brandl116aa622007-08-15 14:28:22 +0000679
680
681Optimizations
682-------------
683
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000684The net result of the 3.0 generalizations is that Python 3.0 runs the
Guido van Rossum715287f2008-12-02 22:34:15 +0000685pystone benchmark around 10% slower than Python 2.5. Most likely the
686biggest cause is the removal of special-casing for small integers.
687There's room for improvement, but it will happen after 3.0 is
688released!
Georg Brandl116aa622007-08-15 14:28:22 +0000689
Georg Brandl5a165582007-08-31 06:15:01 +0000690.. ======================================================================
Georg Brandl116aa622007-08-15 14:28:22 +0000691
692
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000693New, Improved, And Deprecated Modules
Georg Brandl116aa622007-08-15 14:28:22 +0000694=====================================
695
Georg Brandlec17d202008-02-02 10:44:37 +0000696As usual, Python's standard library received a number of enhancements and bug
697fixes. Here's a partial list of the most notable changes, sorted alphabetically
698by module name. Consult the :file:`Misc/NEWS` file in the source tree for a more
699complete list of changes, or look through the Subversion logs for all the
700details.
Georg Brandl116aa622007-08-15 14:28:22 +0000701
Georg Brandlec17d202008-02-02 10:44:37 +0000702* The :mod:`cPickle` module is gone. Use :mod:`pickle` instead. Eventually
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000703 we'll have a transparent accelerator module.
Georg Brandl116aa622007-08-15 14:28:22 +0000704
Georg Brandlec17d202008-02-02 10:44:37 +0000705* The :mod:`imageop` module is gone.
Georg Brandl396ef802008-02-02 10:30:18 +0000706
Georg Brandlec17d202008-02-02 10:44:37 +0000707* The :mod:`audiodev`, :mod:`Bastion`, :mod:`bsddb185`, :mod:`exceptions`,
708 :mod:`linuxaudiodev`, :mod:`md5`, :mod:`MimeWriter`, :mod:`mimify`,
709 :mod:`popen2`, :mod:`rexec`, :mod:`sets`, :mod:`sha`, :mod:`stringold`,
710 :mod:`strop`, :mod:`sunaudiodev`, :mod:`timing`, and :mod:`xmllib` modules are
711 gone.
Georg Brandl396ef802008-02-02 10:30:18 +0000712
Gregory P. Smith7b9a2222008-09-04 05:07:03 +0000713* The :mod:`bsddb` module is gone. It is being maintained externally
714 with its own release schedule better mirroring that of BerkeleyDB.
715 See http://www.jcea.es/programacion/pybsddb.htm.
716
Georg Brandlec17d202008-02-02 10:44:37 +0000717* The :mod:`new` module is gone.
Georg Brandl396ef802008-02-02 10:30:18 +0000718
Georg Brandlec17d202008-02-02 10:44:37 +0000719* The functions :func:`os.tmpnam`, :func:`os.tempnam` and :func:`os.tmpfile`
720 have been removed in favor of the :mod:`tempfile` module.
Georg Brandl396ef802008-02-02 10:30:18 +0000721
Trent Nelson428de652008-03-18 22:41:35 +0000722* The :mod:`tokenize` module has been changed to work with bytes. The main
723 entry point is now :func:`tokenize.tokenize`, instead of generate_tokens.
724
Georg Brandl5a165582007-08-31 06:15:01 +0000725.. ======================================================================
726.. whole new modules get described in subsections here
Georg Brandl116aa622007-08-15 14:28:22 +0000727
Georg Brandl5a165582007-08-31 06:15:01 +0000728.. ======================================================================
Georg Brandl116aa622007-08-15 14:28:22 +0000729
730
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000731Build And C API Changes
Georg Brandl116aa622007-08-15 14:28:22 +0000732=======================
733
734Changes to Python's build process and to the C API include:
735
Guido van Rossum715287f2008-12-02 22:34:15 +0000736* :pep:`3118`: New Buffer API. XXX
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000737
Guido van Rossum715287f2008-12-02 22:34:15 +0000738* :pep:`3121`: Extension Module Initialization & Finalization. XXX
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000739
Guido van Rossum715287f2008-12-02 22:34:15 +0000740* :pep:`3123`: Making :cmacro:`PyObject_HEAD` conform to standard C. XXX
Georg Brandl116aa622007-08-15 14:28:22 +0000741
Georg Brandl396ef802008-02-02 10:30:18 +0000742* No more C API support for restricted execution.
743
Georg Brandlec17d202008-02-02 10:44:37 +0000744* :cfunc:`PyNumber_Coerce`, :cfunc:`PyNumber_CoerceEx`, :cfunc:`PyMember_Get`,
745 and :cfunc:`PyMember_Set` C APIs are removed.
Georg Brandl396ef802008-02-02 10:30:18 +0000746
Georg Brandlec17d202008-02-02 10:44:37 +0000747* New C API :cfunc:`PyImport_ImportModuleNoBlock`, works like
748 :cfunc:`PyImport_ImportModule` but won't block on the import lock (returning
Georg Brandl396ef802008-02-02 10:30:18 +0000749 an error instead).
750
Georg Brandl5a165582007-08-31 06:15:01 +0000751.. ======================================================================
Georg Brandl116aa622007-08-15 14:28:22 +0000752
753
754Port-Specific Changes
755---------------------
756
Guido van Rossum715287f2008-12-02 22:34:15 +0000757XXX Platform-specific changes go here.
Georg Brandl116aa622007-08-15 14:28:22 +0000758
Guido van Rossum715287f2008-12-02 22:34:15 +0000759* XXX BeOS, RISCOS, Irix, Tru64 support
Georg Brandl396ef802008-02-02 10:30:18 +0000760
Georg Brandl5a165582007-08-31 06:15:01 +0000761.. ======================================================================
Georg Brandl116aa622007-08-15 14:28:22 +0000762
763
Benjamin Petersonf10a79a2008-10-11 00:49:57 +0000764.. _30section-other:
Georg Brandl116aa622007-08-15 14:28:22 +0000765
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000766Other Changes And Fixes
Georg Brandl116aa622007-08-15 14:28:22 +0000767=======================
768
Guido van Rossumb197f3c2007-08-31 00:37:00 +0000769As usual, there were a bunch of other improvements and bugfixes
770scattered throughout the source tree. A search through the change
771logs finds there were XXX patches applied and YYY bugs fixed between
772Python 2.6 and 3.0. Both figures are likely to be underestimates.
Georg Brandl116aa622007-08-15 14:28:22 +0000773
Guido van Rossum715287f2008-12-02 22:34:15 +0000774XXX Some of the more notable changes are:
Georg Brandl116aa622007-08-15 14:28:22 +0000775
Guido van Rossum715287f2008-12-02 22:34:15 +0000776* XXX Details go here.
Georg Brandl116aa622007-08-15 14:28:22 +0000777
Georg Brandl5a165582007-08-31 06:15:01 +0000778.. ======================================================================
Georg Brandl116aa622007-08-15 14:28:22 +0000779
780
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000781Porting To Python 3.0
Georg Brandl116aa622007-08-15 14:28:22 +0000782=====================
783
Guido van Rossum56076da2008-12-02 22:58:36 +0000784For porting existing Python 2.5 or 2.6 source code to Python 3.0, the
785best strategy is the following:
Georg Brandl116aa622007-08-15 14:28:22 +0000786
Guido van Rossum56076da2008-12-02 22:58:36 +00007870. (Prerequisite:) Start with excellent test coverage.
Georg Brandl116aa622007-08-15 14:28:22 +0000788
Guido van Rossum56076da2008-12-02 22:58:36 +00007891. Port to Python 2.6. This should be no more work than the average
790 port from Python 2.x to Python 2.(x+1). Make sure all your tests
791 pass.
Christian Heimesf78b1c62007-12-02 16:52:32 +0000792
Guido van Rossum56076da2008-12-02 22:58:36 +00007932. (Still using 2.6:) Turn on the :option:`-3` command line switch.
794 This enables warnings about features that will be removed (or
795 change) in 3.0. Run your test suite again, and fix code that you
796 get warnings about until there are no warnings left, and all your
797 tests still pass.
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000798
Guido van Rossum56076da2008-12-02 22:58:36 +00007993. Run the ``2to3`` source-to-source translator over your source code
800 tree. (See :ref:`2to3-reference` for more on this tool.) Run the
801 result of the translation under Python 3.0. Manually fix up any
802 remaining issues, fixing problems until all tests pass again.
803
804It is not recommended to try to write source code that runs unchanged
805under both Python 2.6 and 3.0; you'd have to use a very contorted
806coding style, e.g. avoiding :keyword:`print` statements, metaclasses,
807and much more. If you are maintaining a library that needs to support
808both Python 2.6 and Python 3.0, the best approach is to modify step 3
809above by editing the 2.6 version of the source code and running the
810``2to3`` translator again, rather than editing the 3.0 version of the
811source code.
812
813For porting C extensions to Python 3.0, please see :ref:`cporting-howto`.
Guido van Rossumeb3d8d42008-12-02 00:56:25 +0000814
Georg Brandl5a165582007-08-31 06:15:01 +0000815.. ======================================================================