Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1 | **************************** |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 2 | What's New In Python 3.0 |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 3 | **************************** |
| 4 | |
Guido van Rossum | 4a98a2a | 2008-11-21 18:35:43 +0000 | [diff] [blame] | 5 | .. XXX add trademark info for Apple, Microsoft, SourceForge. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 6 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 7 | .. XXX turn all PEP references into :pep:`NNN` markup. |
| 8 | |
Guido van Rossum | 4a98a2a | 2008-11-21 18:35:43 +0000 | [diff] [blame] | 9 | :Author: Guido van Rossum |
| 10 | :Release: |release| |
| 11 | :Date: |today| |
| 12 | |
| 13 | .. $Id$ |
| 14 | Rules for maintenance: |
Georg Brandl | 5a16558 | 2007-08-31 06:15:01 +0000 | [diff] [blame] | 15 | |
| 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 Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 54 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 55 | This article explains the new features in Python 3.0, compared to 2.6. |
| 56 | Python 3.0 is the first ever *intentionally incompatible* release. |
| 57 | There are more changes than in a typical release, and more that are |
| 58 | important for all Python users. Nevertheless, after digesting the |
| 59 | changes, you'll find that Python really hasn't changed all that much |
| 60 | -- by and large, we're merely fixing well-known annoyances and warts. |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 61 | |
| 62 | This article doesn't attempt to provide a complete specification of |
| 63 | the new features, but instead provides a convenient overview. For |
| 64 | full details, you should refer to the documentation for Python 3.0. If |
| 65 | you want to understand the complete implementation and design |
| 66 | rationale, refer to the PEP for a particular new feature. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 67 | |
Georg Brandl | 5a16558 | 2007-08-31 06:15:01 +0000 | [diff] [blame] | 68 | .. Compare with previous release in 2 - 3 sentences here. |
| 69 | .. add hyperlink when the documentation becomes available online. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 70 | |
Georg Brandl | 5a16558 | 2007-08-31 06:15:01 +0000 | [diff] [blame] | 71 | .. ====================================================================== |
| 72 | .. Large, PEP-level features and changes should be described here. |
| 73 | .. Should there be a new section here for 3k migration? |
| 74 | .. Or perhaps a more general section describing module changes/deprecation? |
| 75 | .. sets module deprecated |
| 76 | .. ====================================================================== |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 77 | |
| 78 | |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 79 | Common Stumbling Blocks |
| 80 | ======================= |
| 81 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 82 | This section briefly lists a few changes that are more likely to trip |
| 83 | people up, without necessarily raising obvious errors. Most issues |
| 84 | are explained in more detail in later sections. |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 85 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 86 | Print Is A Function |
| 87 | ------------------- |
Guido van Rossum | dff1c31 | 2007-09-06 14:46:41 +0000 | [diff] [blame] | 88 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 89 | The ``print`` statement has been replaced with a :func:`print` function, |
| 90 | with keyword arguments to replace most of the special syntax of the |
| 91 | old ``print`` statement (PEP 3105). Examples:: |
Guido van Rossum | dff1c31 | 2007-09-06 14:46:41 +0000 | [diff] [blame] | 92 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 93 | Old: print "The answer is", 2*2 |
| 94 | New: print("The answer is", 2*2) |
Guido van Rossum | dff1c31 | 2007-09-06 14:46:41 +0000 | [diff] [blame] | 95 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 96 | Old: print x, # Trailing comma suppresses newline |
| 97 | New: print(x, end=" ") # Appends a space instead of a newline |
Guido van Rossum | dff1c31 | 2007-09-06 14:46:41 +0000 | [diff] [blame] | 98 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 99 | Old: print # Prints a newline |
| 100 | New: print() # You must call the function! |
Guido van Rossum | dff1c31 | 2007-09-06 14:46:41 +0000 | [diff] [blame] | 101 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 102 | Old: print >>sys.stderr, "fatal error" |
| 103 | New: print("fatal error", file=sys.stderr) |
Guido van Rossum | dff1c31 | 2007-09-06 14:46:41 +0000 | [diff] [blame] | 104 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 105 | Old: print (x, y) # prints repr((x, y)) |
| 106 | New: print((x, y)) # Not the same as print(x, y)! |
Guido van Rossum | dff1c31 | 2007-09-06 14:46:41 +0000 | [diff] [blame] | 107 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 108 | You can also customize the separator between items, e.g.:: |
Guido van Rossum | dff1c31 | 2007-09-06 14:46:41 +0000 | [diff] [blame] | 109 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 110 | print("There are <", 2**32, "> possibilities!", sep="") |
Guido van Rossum | dff1c31 | 2007-09-06 14:46:41 +0000 | [diff] [blame] | 111 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 112 | which produces:: |
Guido van Rossum | dff1c31 | 2007-09-06 14:46:41 +0000 | [diff] [blame] | 113 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 114 | There are <4294967296> possibilities! |
Guido van Rossum | dff1c31 | 2007-09-06 14:46:41 +0000 | [diff] [blame] | 115 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 116 | Note: |
Guido van Rossum | dff1c31 | 2007-09-06 14:46:41 +0000 | [diff] [blame] | 117 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 118 | * The :func:`print` function doesn't support the "softspace" feature of |
| 119 | the old ``print`` statement. For example, in Python 2.x, |
| 120 | ``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 Rossum | dff1c31 | 2007-09-06 14:46:41 +0000 | [diff] [blame] | 122 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 123 | * 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 Rossum | dff1c31 | 2007-09-06 14:46:41 +0000 | [diff] [blame] | 126 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 127 | * When using the ``2to3`` source-to-source conversion tool, all |
| 128 | ``print`` statements are automatically converted to :func:`print` |
| 129 | function calls, so this is mostly a non-issue for larger projects. |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 130 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 131 | Text Strings Vs. Bytes |
| 132 | ---------------------- |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 133 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 134 | Everything you thought you knew about binary data and Unicode has |
| 135 | changed: |
| 136 | |
| 137 | * Python 3.0 uses *strings* and *bytes* instead of *Unicode strings* |
| 138 | and *8-bit strings*. The difference is that any attempt to mix |
| 139 | strings and bytes in Python 3.0 raises a TypeError exception, |
| 140 | whereas if you were to mix Unicode and 8-bit strings in Python 2.x, |
| 141 | you would only get an exception if the 8-bit string contained |
| 142 | non-ASCII values. As a consequence, pretty much all code that |
| 143 | uses Unicode, encodings or binary data most likely has to change. |
| 144 | The change is for the better, as in the 2.x world there were |
| 145 | numerous bugs having to do with mixing encoded and unencoded text. |
| 146 | |
| 147 | * Files opened as text files (still the default mode for :func:`open`) |
| 148 | always use an encoding to map between strings (in memory) and bytes |
| 149 | (on disk). Binary files (opened with a ``b`` in the mode argument) |
| 150 | always use bytes in memory. This means that if a file is opened |
| 151 | using an incorrect mode or encoding, I/O will likely fail. There is |
| 152 | a platform-dependent default encoding, which on Unixy platforms can |
| 153 | be set with the ``LANG`` environment variable (and sometimes also |
| 154 | with some other platform-specific locale-related environment |
| 155 | variables). In many cases, but not all, the system default is |
Walter Dörwald | a443856 | 2008-12-02 11:55:30 +0000 | [diff] [blame] | 156 | UTF-8; you should never count on this default. Any application |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 157 | reading or writing more than pure ASCII text should probably have a |
| 158 | way to override the encoding. |
| 159 | |
| 160 | * XXX More below? |
| 161 | |
| 162 | * See also the *Unicode HOWTO*. (XXX How to make this a link?) |
| 163 | (XXX Move to longer section below?) |
| 164 | |
| 165 | Views And Interators Instead Of Lists |
| 166 | ------------------------------------- |
| 167 | |
| 168 | Some well-known APIs no longer return lists: |
| 169 | |
| 170 | * :class:`dict` methods :meth:`dict.keys`, :meth:`dict.items` and |
| 171 | :meth:`dict.values` return "views" instead of lists. For example, |
| 172 | this no longer works: ``k = d.keys(); k.sort()``. Use ``k = |
| 173 | sorted(d)`` instead. |
| 174 | |
| 175 | * Also, the :meth:`dict.iterkeys`, :meth:`dict.iteritems` and |
| 176 | :meth:`dict.itervalues` methods are no longer supported. |
Guido van Rossum | 4a98a2a | 2008-11-21 18:35:43 +0000 | [diff] [blame] | 177 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 178 | * :func:`map` and :func:`filter` return iterators. A quick fix is e.g. |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 179 | ``list(map(...))``, but a better fix is often to use a list |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 180 | comprehension (especially when the original code uses :keyword:`lambda`). |
| 181 | Particularly tricky is :func:`map` invoked for the side effects of the |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 182 | function; the correct transformation is to use a for-loop. |
| 183 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 184 | * :func:`range` now behaves like :func:`xrange` used to behave. |
| 185 | The latter no longer exists. |
| 186 | |
| 187 | * :func:`zip` now returns an iterator. |
| 188 | |
| 189 | * XXX More below? |
| 190 | |
| 191 | Ordering Comparisons |
| 192 | -------------------- |
| 193 | |
| 194 | Python 3.0 has simplified the rules for ordering comparisons: |
| 195 | |
| 196 | * The ordering comparison operators (``<``, ``<=``, ``>=``, ``>``) |
| 197 | raise a TypeError exception when the operands don't have a |
| 198 | meaningful natural ordering. Thus, expressions like ``1 < ''``, ``0 |
| 199 | > None`` or ``len <= len`` are no longer valid. A corollary is that |
| 200 | sorting a heterogeneous list no longer makes sense -- all the |
| 201 | elements must be comparable to each other. Note that this does not |
| 202 | apply to the ``==`` and ``!=`` operators: objects of different |
| 203 | uncomparable types always compare unequal to each other, and an |
| 204 | object always compares equal to itself (i.e., ``x is y`` implies ``x |
| 205 | = y``; this is true even for ``NaN``). |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 206 | |
Kurt B. Kaiser | 2bc6b5e | 2008-02-13 18:03:11 +0000 | [diff] [blame] | 207 | * :meth:`builtin.sorted` and :meth:`list.sort` no longer accept the *cmp* |
Kurt B. Kaiser | 9d0d616 | 2008-02-14 02:47:50 +0000 | [diff] [blame] | 208 | argument providing a comparison function. Use the *key* argument |
Kurt B. Kaiser | 2bc6b5e | 2008-02-13 18:03:11 +0000 | [diff] [blame] | 209 | instead. N.B. the *key* and *reverse* arguments are now "keyword-only". |
Kurt B. Kaiser | a140101 | 2008-02-13 16:09:27 +0000 | [diff] [blame] | 210 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 211 | * The :func:`cmp` function is gone, and the :meth:`__cmp__` special |
| 212 | method is no longer supported. Use :meth:`__lt__` for sorting, |
| 213 | :meth:`__eq__` with :meth:`__hash__`, and other rich comparisons as |
| 214 | needed. if you really need the :func:`cmp` functionality, the |
| 215 | expression ``(a > b) - (a < b)`` is equivalent to ``cmp(a, b)``. |
| 216 | |
| 217 | * XXX More below? |
| 218 | |
| 219 | Integers |
| 220 | -------- |
| 221 | |
| 222 | * We unified the :class:`int` and :class:`long` types. All integers |
| 223 | are now of type :class:`int`. |
Georg Brandl | b667087 | 2008-11-22 08:35:59 +0000 | [diff] [blame] | 224 | |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 225 | * ``1/2`` returns a float. Use ``1//2`` to get the truncating behavior. |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 226 | (The latter syntax has existed for years, at least since Python 2.2.) |
Guido van Rossum | 4a98a2a | 2008-11-21 18:35:43 +0000 | [diff] [blame] | 227 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 228 | * The :func:`repr` of a long integer doesn't include the trailing ``L`` |
Georg Brandl | cc595bd | 2007-12-09 09:04:01 +0000 | [diff] [blame] | 229 | anymore, so code that unconditionally strips that character will |
| 230 | chop off the last digit instead. |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 231 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 232 | * The :data:`sys.maxint` constant was removed, since there is no |
| 233 | longer a limit to the value of ints. However, :data:`sys.maxsize` |
| 234 | can be used as an integer larger than any practical list or string |
| 235 | index. It conforms to the implementation's "natural" integer size |
| 236 | and is typically the same as :data:`sys.maxint` in previous releases |
| 237 | on the same platform (assuming the same build options). |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 238 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 239 | * XXX More below? |
| 240 | |
| 241 | |
| 242 | Overview Of Syntactic Changes |
| 243 | ============================= |
| 244 | |
| 245 | This section gives a brief overview of every *syntactic* change. |
| 246 | Several of these are discussed at greater length later. |
| 247 | |
| 248 | XXX Did I get everything? |
| 249 | |
| 250 | Additions |
| 251 | --------- |
| 252 | |
| 253 | * Function argument and return value annotations (see below). XXX |
| 254 | |
| 255 | * A lone ``*`` in a formal parameter list implies that any following |
| 256 | arguments *must* be specified in keyword form. (XXX Didn't this make |
| 257 | it into 2.6 as well?) |
| 258 | |
| 259 | * Keyword arguments are allowed after the list of base classes in a |
| 260 | class definition. This is used by the new convention for specifying |
| 261 | a metaclass, but can be used for other purposes as well, as long as |
| 262 | the metaclass supports it. |
| 263 | |
| 264 | * Tuple-unpacking assignment now has a *wildcard* syntax, e.g.:: |
| 265 | |
| 266 | (a, b, *rest) = range(5) |
| 267 | |
Benjamin Peterson | cc163bb | 2008-12-02 01:12:04 +0000 | [diff] [blame] | 268 | This sets *a* to 0, *b* to 1, and \*rest to ``[2, 3, 4]``. |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 269 | |
| 270 | * Dictionary comprehensions: ``{k: v for k, v in stuff}`` means the |
| 271 | same thing as ``dict(stuff)`` but is more flexible. |
| 272 | |
| 273 | * Set literals, e.g. ``{1, 2}``. Note that ``{}`` is an empty |
| 274 | dictionary; use ``set()`` for an empty set. Set comprehensions |
| 275 | are also supported; ``{x for x in stuff}`` means the same thing |
| 276 | as ``set(stuff)`` but is more flexible. |
| 277 | |
| 278 | * New octal literals, e.g. ``0o720`` (already in 2.6). The old octal |
Walter Dörwald | eab34c9 | 2008-12-02 11:58:09 +0000 | [diff] [blame^] | 279 | literals (``0720``) are gone. |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 280 | |
| 281 | * New binary literals, e.g. ``0b1010`` (already in 2.6). |
| 282 | |
| 283 | * Bytes literals are introduced with a leading ``b`` or ``B``. |
| 284 | |
| 285 | Changes |
| 286 | ------- |
| 287 | |
| 288 | * New :keyword:`raise` statement syntax: ``raise [expr [from expr]]``. |
| 289 | |
| 290 | * New keywords: :keyword:`as`, :keyword:`with` (already in 2.6), |
| 291 | :keyword:`None` (partially enforced in 2.6), :keyword:`True`, |
| 292 | :keyword:`False` (these were built-ins previously), and |
| 293 | :keyword:`nonlocal` (for the new ``nonlocal`` statement). |
| 294 | |
| 295 | * Change from ``except exc, var:`` to ``except exc as var:``. XXX |
| 296 | |
| 297 | * *Very* subtle changes in the syntax for list comprehensions, |
| 298 | generator expressions, :keyword:`lambda expression and :keyword:`if` |
| 299 | expressions. For example, this is valid in Python 2.6:: |
| 300 | |
| 301 | [ x for x in lambda: True, lambda: False if x() ] |
| 302 | |
| 303 | In Python 3.0 you'll have to add parentheses, like this:: |
| 304 | |
| 305 | [ x for x in (lambda: True, lambda: False) if x() ] |
| 306 | |
| 307 | * The *ellipsis* (``...``) can be used as an atomic expression anywhere. |
| 308 | (Previously it was only allowed in slices.) |
| 309 | |
| 310 | Removals |
| 311 | -------- |
| 312 | |
| 313 | * Tuple parameter unpacking removed. XXX |
| 314 | |
| 315 | * Removal of backticks. XXX |
| 316 | |
| 317 | * Removal of ``<>``. Use ``!=`` instead. XXX |
| 318 | |
| 319 | * Removed keyword: :func:`exec` is no longer a keyword; it remains as |
| 320 | a function. (Fortunately the function syntax was also accepted in |
| 321 | 2.x.) |
| 322 | |
| 323 | * Integer literals no longer support a trailing ``l`` or ``L``. |
| 324 | |
| 325 | * String literals no longer support a leading ``u`` or ``U``. |
| 326 | |
| 327 | * The *ellipsis* must now be spelled as ``...``; previously it could |
| 328 | (by a mere accident of the grammar) also be spelled as ``. . .``. |
| 329 | |
| 330 | |
| 331 | Changes Already Present In Python 2.6 |
| 332 | ===================================== |
| 333 | |
| 334 | This section reminds the reader of new features that were originally |
| 335 | designed for Python 3.0 but that were already introduced in Python |
| 336 | 2.6. The descriptions in "What's New in Python 2.6" are hereby |
| 337 | included by reference. |
| 338 | |
| 339 | * XXX List each of those briefly. |
| 340 | |
| 341 | Strings And Bytes |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 342 | ================= |
| 343 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 344 | This section discusses the many changes in string |
| 345 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 346 | * There is only one string type; its name is :class:`str` but its behavior and |
| 347 | implementation are like :class:`unicode` in 2.x. |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 348 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 349 | * The :class:`basestring` superclass has been removed. The ``2to3`` tool |
Raymond Hettinger | 6a88384 | 2008-07-22 19:27:12 +0000 | [diff] [blame] | 350 | replaces every occurrence of :class:`basestring` with :class:`str`. |
Christian Heimes | f534f7b | 2008-01-25 11:02:28 +0000 | [diff] [blame] | 351 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 352 | * PEP 3137: There is a new type, :class:`bytes`, to represent binary data (and |
| 353 | encoded text, which is treated as binary data until you decide to decode it). |
| 354 | The :class:`str` and :class:`bytes` types cannot be mixed; you must always |
| 355 | explicitly convert between them, using the :meth:`str.encode` (str -> bytes) |
| 356 | or :meth:`bytes.decode` (bytes -> str) methods. |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 357 | |
Benjamin Peterson | a2f837f | 2008-04-28 21:05:10 +0000 | [diff] [blame] | 358 | * All backslashes in raw strings are interpreted literally. This means that |
Guido van Rossum | 4a98a2a | 2008-11-21 18:35:43 +0000 | [diff] [blame] | 359 | ``'\U'`` and ``'\u'`` escapes in raw strings are not treated specially. |
Benjamin Peterson | a2f837f | 2008-04-28 21:05:10 +0000 | [diff] [blame] | 360 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 361 | .. XXX add bytearray |
| 362 | |
| 363 | * PEP 3112: Bytes literals, e.g. ``b"abc"``, create :class:`bytes` instances. |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 364 | |
| 365 | * PEP 3120: UTF-8 default source encoding. |
| 366 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 367 | * PEP 3131: Non-ASCII identifiers. (However, the standard library remains |
| 368 | ASCII-only with the exception of contributor names in comments.) |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 369 | |
| 370 | * PEP 3116: New I/O Implementation. The API is nearly 100% backwards |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 371 | compatible, but completely reimplemented (currently mostly in Python). Also, |
| 372 | binary files use bytes instead of strings. |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 373 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 374 | * The :mod:`StringIO` and :mod:`cStringIO` modules are gone. Instead, import |
| 375 | :class:`io.StringIO` or :class:`io.BytesIO`. |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 376 | |
Benjamin Peterson | a2f837f | 2008-04-28 21:05:10 +0000 | [diff] [blame] | 377 | |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 378 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 379 | PEP 3101: A New Approach To String Formatting |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 380 | ============================================= |
| 381 | |
Guido van Rossum | 4a98a2a | 2008-11-21 18:35:43 +0000 | [diff] [blame] | 382 | * A new system for built-in string formatting operations replaces the |
| 383 | ``%`` string formatting operator. (However, the ``%`` operator is |
| 384 | still supported; it will be deprecated in Python 3.1 and removed |
| 385 | from the language at some later time.) |
Georg Brandl | 396ef80 | 2008-02-02 10:30:18 +0000 | [diff] [blame] | 386 | |
Guido van Rossum | 4a98a2a | 2008-11-21 18:35:43 +0000 | [diff] [blame] | 387 | .. XXX expand this |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 388 | |
| 389 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 390 | PEP 3106: Revamping dict :meth:`dict.keys`, :meth:`dict.items` and :meth:`dict.values` |
| 391 | ====================================================================================== |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 392 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 393 | .. XXX expand this (but note that the "pitfalls" section currently has |
| 394 | .. XXX more detail :-) |
Georg Brandl | 396ef80 | 2008-02-02 10:30:18 +0000 | [diff] [blame] | 395 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 396 | * The :meth:`dict.iterkeys`, :meth:`dict.itervalues` and :meth:`dict.iteritems` |
| 397 | methods have been removed. |
Georg Brandl | 396ef80 | 2008-02-02 10:30:18 +0000 | [diff] [blame] | 398 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 399 | * :meth:`dict.keys`, :meth:`dict.values` and :meth:`dict.items` return objects |
Guido van Rossum | 4a98a2a | 2008-11-21 18:35:43 +0000 | [diff] [blame] | 400 | with set behavior that reference the underlying dict; these are often |
| 401 | referred to as *dictionary views*. |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 402 | |
| 403 | |
| 404 | PEP 3107: Function Annotations |
| 405 | ============================== |
| 406 | |
Georg Brandl | 396ef80 | 2008-02-02 10:30:18 +0000 | [diff] [blame] | 407 | .. XXX expand this |
| 408 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 409 | * A standardized way of annotating a function's parameters and return values. |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 410 | |
| 411 | |
| 412 | Exception Stuff |
| 413 | =============== |
| 414 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 415 | * PEP 352: All exceptions must be derived (directly or indirectly) |
| 416 | from :exc:`BaseException`. This is the root of the exception |
| 417 | hierarchy. Most exceptions should actually be derived from |
| 418 | :exc:`Exception`. This is not a new recommendation, but the |
| 419 | *requirement* to inherit from :exc:`BaseException` is new. (Python |
| 420 | 2.6 still allowed classic classes to be raised, and placed no |
| 421 | restriction on what you can catch.) |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 422 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 423 | * :exc:`StandardError` was removed (in 2.6, actually). |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 424 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 425 | * Dropping sequence behavior (slicing!) and :attr:`message` attribute of |
Georg Brandl | 5a16558 | 2007-08-31 06:15:01 +0000 | [diff] [blame] | 426 | exception instances. |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 427 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 428 | * PEP 3109: Raising exceptions. You must now use ``raise Exception(args)`` |
| 429 | instead of ``raise Exception, args``. |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 430 | |
Georg Brandl | e06de8b | 2008-05-05 21:42:51 +0000 | [diff] [blame] | 431 | * PEP 3110: Catching exceptions. You must now use ``except SomeException as |
| 432 | identifier:`` instead of ``except Exception, identifier:`` |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 433 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 434 | * PEP 3134: Exception chaining. |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 435 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 436 | * A few exception messages are improved when Windows fails to load an extension |
| 437 | module. For example, ``error code 193`` is now ``%1 is not a valid Win32 |
| 438 | application``. Strings now deal with non-English locales. |
Georg Brandl | 396ef80 | 2008-02-02 10:30:18 +0000 | [diff] [blame] | 439 | |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 440 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 441 | New Class And Metaclass Stuff |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 442 | ============================= |
| 443 | |
| 444 | * Classic classes are gone. |
| 445 | |
| 446 | * PEP 3115: New Metaclass Syntax. |
| 447 | |
Skip Montanaro | a86f5d4 | 2007-09-04 02:48:01 +0000 | [diff] [blame] | 448 | * PEP 3119: Abstract Base Classes (ABCs); ``@abstractmethod`` and |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 449 | ``@abstractproperty`` decorators; collection ABCs. |
| 450 | |
| 451 | * PEP 3129: Class decorators. |
| 452 | |
| 453 | * PEP 3141: Numeric ABCs. |
| 454 | |
| 455 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 456 | Other Language Changes |
| 457 | ====================== |
| 458 | |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 459 | Here are most of the changes that Python 3.0 makes to the core Python |
| 460 | language and built-in functions. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 461 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 462 | * Removed backticks (use :func:`repr` instead). |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 463 | |
| 464 | * Removed ``<>`` (use ``!=`` instead). |
| 465 | |
Georg Brandl | 396ef80 | 2008-02-02 10:30:18 +0000 | [diff] [blame] | 466 | * ``!=`` now returns the opposite of ``==``, unless ``==`` returns |
| 467 | ``NotImplemented``. |
| 468 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 469 | * :keyword:`as` and :keyword:`with` are keywords. |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 470 | |
Georg Brandl | 396ef80 | 2008-02-02 10:30:18 +0000 | [diff] [blame] | 471 | * ``True``, ``False``, and ``None`` are keywords. |
| 472 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 473 | * PEP 237: :class:`long` renamed to :class:`int`. That is, there is only one |
| 474 | built-in integral type, named :class:`int`; but it behaves like the old |
| 475 | :class:`long` type, with the exception that the literal suffix ``L`` is |
| 476 | neither supported by the parser nor produced by :func:`repr` anymore. |
| 477 | :data:`sys.maxint` was also removed since the int type has no maximum value |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 478 | anymore. Use :data:`sys.maxsize` instead. |
| 479 | XXX Is this a dupe from the intro section on integers? |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 480 | |
| 481 | * PEP 238: int division returns a float. |
| 482 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 483 | * The ordering operators behave differently: for example, ``x < y`` where ``x`` |
| 484 | and ``y`` have incompatible types raises :exc:`TypeError` instead of returning |
| 485 | a pseudo-random boolean. |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 486 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 487 | * :meth:`__getslice__` and friends killed. The syntax ``a[i:j]`` now translates |
| 488 | to ``a.__getitem__(slice(i, j))`` (or :meth:`__setitem__` or |
| 489 | :meth:`__delitem__`, depending on context). |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 490 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 491 | * PEP 3102: Keyword-only arguments. Named parameters occurring after ``*args`` |
| 492 | in the parameter list *must* be specified using keyword syntax in the call. |
| 493 | You can also use a bare ``*`` in the parameter list to indicate that you don't |
| 494 | accept a variable-length argument list, but you do have keyword-only |
| 495 | arguments. |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 496 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 497 | * PEP 3104: :keyword:`nonlocal` statement. Using ``nonlocal x`` you can now |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 498 | assign directly to a variable in an outer (but non-global) scope. |
| 499 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 500 | * PEP 3111: :func:`raw_input` renamed to :func:`input`. That is, the new |
| 501 | :func:`input` function reads a line from :data:`sys.stdin` and returns it with |
| 502 | the trailing newline stripped. It raises :exc:`EOFError` if the input is |
| 503 | terminated prematurely. To get the old behavior of :func:`input`, use |
| 504 | ``eval(input())``. |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 505 | |
Georg Brandl | 67b8cad | 2008-04-09 07:32:07 +0000 | [diff] [blame] | 506 | * :func:`xrange` renamed to :func:`range`, so :func:`range` will no longer |
| 507 | produce a list but an iterable yielding integers when iterated over. |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 508 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 509 | * PEP 3113: Tuple parameter unpacking removed. You can no longer write ``def |
| 510 | foo(a, (b, c)): ...``. Use ``def foo(a, b_c): b, c = b_c`` instead. |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 511 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 512 | * PEP 3114: ``.next()`` renamed to :meth:`__next__`, new builtin :func:`next` to |
| 513 | call the :meth:`__next__` method on an object. |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 514 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 515 | * PEP 3127: New octal literals; binary literals and :func:`bin`. Instead of |
| 516 | ``0666``, you write ``0o666``. The :func:`oct` function is modified |
| 517 | accordingly. Also, ``0b1010`` equals 10, and ``bin(10)`` returns |
| 518 | ``"0b1010"``. ``0666`` is now a :exc:`SyntaxError`. |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 519 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 520 | * PEP 3132: Extended Iterable Unpacking. You can now write things like ``a, b, |
| 521 | *rest = some_sequence``. And even ``*rest, a = stuff``. The ``rest`` object |
| 522 | is always a list; the right-hand side may be any iterable. |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 523 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 524 | * PEP 3135: New :func:`super`. You can now invoke :func:`super` without |
| 525 | arguments and the right class and instance will automatically be chosen. With |
| 526 | arguments, its behavior is unchanged. |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 527 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 528 | * :func:`zip`, :func:`map` and :func:`filter` return iterators. |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 529 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 530 | * :data:`string.letters` and its friends (:data:`string.lowercase` and |
| 531 | :data:`string.uppercase`) are gone. Use :data:`string.ascii_letters` |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 532 | etc. instead. |
| 533 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 534 | * Removed: :func:`apply`, :func:`callable`, :func:`coerce`, :func:`execfile`, |
| 535 | :func:`file`, :func:`reduce`, :func:`reload`. |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 536 | |
Georg Brandl | 0327e60 | 2008-02-18 22:20:55 +0000 | [diff] [blame] | 537 | * Removed: :meth:`dict.has_key` -- use the ``in`` operator instead. |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 538 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 539 | * :func:`exec` is now a function. |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 540 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 541 | * The :meth:`__oct__` and :meth:`__hex__` special methods are removed -- |
| 542 | :func:`oct` and :func:`hex` use :meth:`__index__` now to convert the argument |
| 543 | to an integer. |
Georg Brandl | 396ef80 | 2008-02-02 10:30:18 +0000 | [diff] [blame] | 544 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 545 | * Support is removed for :attr:`__members__` and :attr:`__methods__`. |
Georg Brandl | 396ef80 | 2008-02-02 10:30:18 +0000 | [diff] [blame] | 546 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 547 | * Renamed the boolean conversion C-level slot and method: ``nb_nonzero`` is now |
| 548 | ``nb_bool`` and :meth:`__nonzero__` is now :meth:`__bool__`. |
Georg Brandl | 396ef80 | 2008-02-02 10:30:18 +0000 | [diff] [blame] | 549 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 550 | |
Georg Brandl | 5a16558 | 2007-08-31 06:15:01 +0000 | [diff] [blame] | 551 | .. ====================================================================== |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 552 | |
| 553 | |
| 554 | Optimizations |
| 555 | ------------- |
| 556 | |
| 557 | * Detailed changes are listed here. |
| 558 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 559 | The net result of the 3.0 generalizations is that Python 3.0 runs the |
| 560 | pystone benchmark around a third slower than Python 2.5. There's room |
| 561 | for improvement, but it will happen after 3.0 is released! |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 562 | |
Georg Brandl | 5a16558 | 2007-08-31 06:15:01 +0000 | [diff] [blame] | 563 | .. ====================================================================== |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 564 | |
| 565 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 566 | New, Improved, And Deprecated Modules |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 567 | ===================================== |
| 568 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 569 | As usual, Python's standard library received a number of enhancements and bug |
| 570 | fixes. Here's a partial list of the most notable changes, sorted alphabetically |
| 571 | by module name. Consult the :file:`Misc/NEWS` file in the source tree for a more |
| 572 | complete list of changes, or look through the Subversion logs for all the |
| 573 | details. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 574 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 575 | * The :mod:`cPickle` module is gone. Use :mod:`pickle` instead. Eventually |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 576 | we'll have a transparent accelerator module. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 577 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 578 | * The :mod:`imageop` module is gone. |
Georg Brandl | 396ef80 | 2008-02-02 10:30:18 +0000 | [diff] [blame] | 579 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 580 | * The :mod:`audiodev`, :mod:`Bastion`, :mod:`bsddb185`, :mod:`exceptions`, |
| 581 | :mod:`linuxaudiodev`, :mod:`md5`, :mod:`MimeWriter`, :mod:`mimify`, |
| 582 | :mod:`popen2`, :mod:`rexec`, :mod:`sets`, :mod:`sha`, :mod:`stringold`, |
| 583 | :mod:`strop`, :mod:`sunaudiodev`, :mod:`timing`, and :mod:`xmllib` modules are |
| 584 | gone. |
Georg Brandl | 396ef80 | 2008-02-02 10:30:18 +0000 | [diff] [blame] | 585 | |
Gregory P. Smith | 7b9a222 | 2008-09-04 05:07:03 +0000 | [diff] [blame] | 586 | * The :mod:`bsddb` module is gone. It is being maintained externally |
| 587 | with its own release schedule better mirroring that of BerkeleyDB. |
| 588 | See http://www.jcea.es/programacion/pybsddb.htm. |
| 589 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 590 | * The :mod:`new` module is gone. |
Georg Brandl | 396ef80 | 2008-02-02 10:30:18 +0000 | [diff] [blame] | 591 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 592 | * The functions :func:`os.tmpnam`, :func:`os.tempnam` and :func:`os.tmpfile` |
| 593 | have been removed in favor of the :mod:`tempfile` module. |
Georg Brandl | 396ef80 | 2008-02-02 10:30:18 +0000 | [diff] [blame] | 594 | |
Trent Nelson | 428de65 | 2008-03-18 22:41:35 +0000 | [diff] [blame] | 595 | * The :mod:`tokenize` module has been changed to work with bytes. The main |
| 596 | entry point is now :func:`tokenize.tokenize`, instead of generate_tokens. |
| 597 | |
Georg Brandl | 5a16558 | 2007-08-31 06:15:01 +0000 | [diff] [blame] | 598 | .. ====================================================================== |
| 599 | .. whole new modules get described in subsections here |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 600 | |
Georg Brandl | 5a16558 | 2007-08-31 06:15:01 +0000 | [diff] [blame] | 601 | .. ====================================================================== |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 602 | |
| 603 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 604 | Build And C API Changes |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 605 | ======================= |
| 606 | |
| 607 | Changes to Python's build process and to the C API include: |
| 608 | |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 609 | * PEP 3118: New Buffer API. |
| 610 | |
| 611 | * PEP 3121: Extension Module Initialization & Finalization. |
| 612 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 613 | * PEP 3123: Making :cmacro:`PyObject_HEAD` conform to standard C. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 614 | |
Georg Brandl | 396ef80 | 2008-02-02 10:30:18 +0000 | [diff] [blame] | 615 | * No more C API support for restricted execution. |
| 616 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 617 | * :cfunc:`PyNumber_Coerce`, :cfunc:`PyNumber_CoerceEx`, :cfunc:`PyMember_Get`, |
| 618 | and :cfunc:`PyMember_Set` C APIs are removed. |
Georg Brandl | 396ef80 | 2008-02-02 10:30:18 +0000 | [diff] [blame] | 619 | |
Georg Brandl | ec17d20 | 2008-02-02 10:44:37 +0000 | [diff] [blame] | 620 | * New C API :cfunc:`PyImport_ImportModuleNoBlock`, works like |
| 621 | :cfunc:`PyImport_ImportModule` but won't block on the import lock (returning |
Georg Brandl | 396ef80 | 2008-02-02 10:30:18 +0000 | [diff] [blame] | 622 | an error instead). |
| 623 | |
Georg Brandl | 5a16558 | 2007-08-31 06:15:01 +0000 | [diff] [blame] | 624 | .. ====================================================================== |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 625 | |
| 626 | |
| 627 | Port-Specific Changes |
| 628 | --------------------- |
| 629 | |
| 630 | Platform-specific changes go here. |
| 631 | |
Georg Brandl | 396ef80 | 2008-02-02 10:30:18 +0000 | [diff] [blame] | 632 | |
Georg Brandl | 5a16558 | 2007-08-31 06:15:01 +0000 | [diff] [blame] | 633 | .. ====================================================================== |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 634 | |
| 635 | |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 636 | .. _30section-other: |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 637 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 638 | Other Changes And Fixes |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 639 | ======================= |
| 640 | |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 641 | As usual, there were a bunch of other improvements and bugfixes |
| 642 | scattered throughout the source tree. A search through the change |
| 643 | logs finds there were XXX patches applied and YYY bugs fixed between |
| 644 | Python 2.6 and 3.0. Both figures are likely to be underestimates. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 645 | |
| 646 | Some of the more notable changes are: |
| 647 | |
| 648 | * Details go here. |
| 649 | |
Georg Brandl | 5a16558 | 2007-08-31 06:15:01 +0000 | [diff] [blame] | 650 | .. ====================================================================== |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 651 | |
| 652 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 653 | Porting To Python 3.0 |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 654 | ===================== |
| 655 | |
Guido van Rossum | b197f3c | 2007-08-31 00:37:00 +0000 | [diff] [blame] | 656 | This section lists previously described changes that may require |
| 657 | changes to your code: |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 658 | |
| 659 | * Everything is all in the details! |
| 660 | |
Georg Brandl | 7274858 | 2008-01-20 10:59:44 +0000 | [diff] [blame] | 661 | * Developers can include :file:`intobject.h` after :file:`Python.h` for |
| 662 | some ``PyInt_`` aliases. |
Christian Heimes | f78b1c6 | 2007-12-02 16:52:32 +0000 | [diff] [blame] | 663 | |
Guido van Rossum | eb3d8d4 | 2008-12-02 00:56:25 +0000 | [diff] [blame] | 664 | * XXX Mention 2to3. |
| 665 | |
| 666 | * XXX Reference external doc about porting extensions? |
| 667 | |
Georg Brandl | 5a16558 | 2007-08-31 06:15:01 +0000 | [diff] [blame] | 668 | .. ====================================================================== |