|
| 1 | +\documentclass{howto} |
| 2 | + |
| 3 | +\title{What's New in Python 1.6} |
| 4 | +\release{0.01} |
| 5 | +\author{A.M. Kuchling} |
| 6 | +\authoraddress{ \email{ [email protected]}} |
| 7 | +\begin{document} |
| 8 | +\maketitle\tableofcontents |
| 9 | + |
| 10 | +\section{Introduction} |
| 11 | + |
| 12 | +A new release of Python, version 1.6, will be released some time this |
| 13 | +summer. Alpha versions are already available from |
| 14 | +\url{http://www.python.org/1.6/}. This article talks about the |
| 15 | +exciting new features in 1.6, highlights some useful new features, and |
| 16 | +points out a few incompatible changes that may require rewriting code. |
| 17 | + |
| 18 | +Python's development never ceases, and a steady flow of bug fixes and |
| 19 | +improvements are always being submitted. A host of minor bug-fixes, a |
| 20 | +few optimizations, additional docstrings, and better error messages |
| 21 | +went into 1.6; to list them all would be impossible, but they're |
| 22 | +certainly significant. Consult the publicly-available CVS logs if you |
| 23 | +want to see the full list. |
| 24 | + |
| 25 | +% ====================================================================== |
| 26 | +\section{Unicode} |
| 27 | + |
| 28 | +XXX |
| 29 | + |
| 30 | +unicode support: Unicode strings are marked with u"string", and there |
| 31 | +is support for arbitrary encoders/decoders |
| 32 | + |
| 33 | +Added -U command line option. With the option enabled the Python |
| 34 | +compiler interprets all "..." strings as u"..." (same with r"..." and |
| 35 | +ur"..."). (Is this just for experimenting?) |
| 36 | + |
| 37 | + |
| 38 | +% ====================================================================== |
| 39 | +\section{Distribution Utilities} |
| 40 | + |
| 41 | +XXX |
| 42 | + |
| 43 | +% ====================================================================== |
| 44 | +\section{String Methods} |
| 45 | + |
| 46 | +% ====================================================================== |
| 47 | +\section{Porting to 1.6} |
| 48 | + |
| 49 | +New Python releases try hard to be compatible with previous releases, |
| 50 | +and the record has been pretty good. However, some changes are |
| 51 | +considered useful enough (often fixing design decisions that were |
| 52 | +initially bad) that breaking backward compatibility in subtle ways |
| 53 | +can't always be avoided. This section lists the changes in Python 1.6 |
| 54 | +that may cause old Python code to break. |
| 55 | + |
| 56 | +The change which will probably break the most code is tightening up |
| 57 | +the arguments accepted by some methods. Some methods would take |
| 58 | +multiple arguments and treat them as a tuple, particularly various |
| 59 | +list methods such as \method{.append()}, \method{.insert()}, |
| 60 | +\method{remove()}, and \method{.count()}. |
| 61 | +% |
| 62 | +% XXX did anyone ever call the last 2 methods with multiple args? |
| 63 | +% |
| 64 | +In earlier versions of Python, if \code{L} is a list, \code{L.append( |
| 65 | +1,2 )} appends the tuple \code{(1,2)} to the list. In Python 1.6 this |
| 66 | +causes a \exception{TypeError} exception to be raised, with the |
| 67 | +message: 'append requires exactly 1 argument; 2 given'. The fix is to |
| 68 | +simply add an extra set of parentheses to pass both values as a tuple: |
| 69 | +\code{L.append( (1,2) )}. |
| 70 | + |
| 71 | +The earlier versions of these methods were more forgiving because they |
| 72 | +used an old function in Python's C interface to parse their arguments; |
| 73 | +1.6 modernizes them to use \function{PyArg_ParseTuple}, the current |
| 74 | +argument parsing function, which provides more helpful error messages |
| 75 | +and treats multi-argument calls as errors. If you absolutely must use |
| 76 | +1.6 but can't fix your code, you can edit \file{Objects/listobject.c} |
| 77 | +and define the preprocessor symbol \code{NO_STRICT_LIST_APPEND} to |
| 78 | +preserve the old behaviour; this isn't recommended. |
| 79 | + |
| 80 | +Some of the functions in the \module{socket} module are still |
| 81 | +forgiving in this way. For example, \function{socket.connect( |
| 82 | +('hostname', 25) )} is the correct form, passing a tuple representing |
| 83 | +an IP address, but |
| 84 | +\function{socket.connect( 'hostname', 25 )} also |
| 85 | +works. \function{socket.connect_ex()} and \function{socket.bind()} are |
| 86 | +similarly easy-going. 1.6alpha1 tightened these functions up, but |
| 87 | +because the documentation actually used the erroneous multiple |
| 88 | +argument form, many people wrote code which will break. So for |
| 89 | +the\module{socket} module, the documentation was fixed and the |
| 90 | +multiple argument form is simply marked as deprecated; it'll be |
| 91 | +removed in a future Python version. |
| 92 | + |
| 93 | +Some work has been done to make integers and long integers a bit more |
| 94 | +interchangeable. In 1.5.2, large-file support was added for Solaris, |
| 95 | +to allow reading files larger than 2Gb; this made the \method{tell()} |
| 96 | +method of file objects return a long integer instead of a regular |
| 97 | +integer. Some code would subtract two file offsets and attempt to use |
| 98 | +the result to multiply a sequence or slice a string, but this raised a |
| 99 | +\exception{TypeError}. In 1.6, long integers can be used to multiply |
| 100 | +or slice a sequence, and it'll behave as you'd intuitively expect it to; |
| 101 | +\code{3L * 'abc'} produces 'abcabcabc', and |
| 102 | +\code{ (0,1,2,3)[2L:4L]} produces (2,3). Long integers can also be |
| 103 | +used in various new places where previously only integers were |
| 104 | +accepted, such as in the \method{seek()} method of file objects. |
| 105 | + |
| 106 | +The subtlest long integer change of all is that the \function{str()} |
| 107 | +of a long integer no longer has a trailing 'L' character, though |
| 108 | +\function{repr()} still includes it. The 'L' annoyed many people who |
| 109 | +wanted to print long integers that looked just like regular integers, |
| 110 | +since they had to go out of their way to chop off the character. This |
| 111 | +is no longer a problem in 1.6, but code which assumes the 'L' is |
| 112 | +there, and does \code{str(longval)[:-1]} will now lose the final |
| 113 | +digit. |
| 114 | + |
| 115 | +Taking the \function{repr()} of a float now uses a different |
| 116 | +formatting precision than \function{str()}. \function{repr()} uses |
| 117 | +``%.17g'' format string for C's \function{sprintf()}, while |
| 118 | +\function{str()} uses ``%.12g'' as before. The effect is that |
| 119 | +\function{repr()} may occasionally show more decimal places than |
| 120 | +\function{str()}, for numbers |
| 121 | +XXX need example value here. |
| 122 | +
|
| 123 | +
|
| 124 | +% ====================================================================== |
| 125 | +\section{Core Changes} |
| 126 | +
|
| 127 | +Deleting objects is safe even for deeply nested data structures. |
| 128 | +Comparing recursive objects is now safe (doesn't dump core). |
| 129 | +
|
| 130 | +Builds on NT Alpha, and work on Win64 (NT Itanium -- sys.platform is |
| 131 | +still 'win32') is ongoing. Supports Windows CE (confirm with Mark |
| 132 | +Hammond) |
| 133 | +
|
| 134 | +UnboundLocalError is raised when a local variable is undefined |
| 135 | +long, int take optional "base" parameter |
| 136 | + |
| 137 | +string objects now have methods (though they are still immutable) |
| 138 | + |
| 139 | +sys.version_info is a tuple: (major, minor, micro, level, serial); level |
| 140 | +is a string "a2", "b1", "c1", or '' for a final release. |
| 141 | + |
| 142 | +New format style '%r' inserts repr(arg) instead of str(arg). |
| 143 | + |
| 144 | +"in" operator can now be overriden in user-defined classes to mean anything: |
| 145 | +it calls the magic method __contains__ |
| 146 | + |
| 147 | +New calling syntax: f(*args, **kw) equivalent to apply(f, args, kw) |
| 148 | + |
| 149 | +% ====================================================================== |
| 150 | +\section{Extending/embedding Changes} |
| 151 | + |
| 152 | +Some of the changes are under the covers, and will only be apparent to |
| 153 | +people writing C extension modules, or embedding a Python interpreter |
| 154 | +in a larger application. If you aren't dealing with Python's C API, |
| 155 | +you can safely skip this section since it won't contain anything of |
| 156 | +interest to you. |
| 157 | + |
| 158 | +Users of Jim Fulton's ExtensionClass module will be pleased to find |
| 159 | +out that hooks have been added so that ExtensionClasses are now |
| 160 | +supported by \function{isinstance()} and \function{issubclass()}. |
| 161 | +This means you no longer have to remember to write code such as |
| 162 | +\code{if type(obj) == myExtensionClass}, but can use the more natural |
| 163 | +\code{if isinstance(obj, myExtensionClass)}. |
| 164 | + |
| 165 | +The \file{Python/importdl.c} file, which was a mass of #ifdefs to |
| 166 | +support dynamic loading on many different platforms, was cleaned up |
| 167 | +are reorganized by Greg Stein. \file{importdl.c} is now quite small, |
| 168 | +and platform-specific code has been moved into a bunch of |
| 169 | +\file{Python/dynload_*.c} files. |
| 170 | + |
| 171 | +Vladimir Marangozov's long-awaited malloc restructuring was completed, |
| 172 | +to make it easy to have the Python interpreter use a custom allocator |
| 173 | +instead of C's standard \function{malloc()}. For documentation, read |
| 174 | +the comments in \file{Include/mymalloc.h} and |
| 175 | +\file{Include/objimpl.h}. For the lengthy discussions during which |
| 176 | +the interface was hammered out, see the Web archives of the 'patches' |
| 177 | +and 'python-dev' lists at python.org. |
| 178 | + |
| 179 | +Recent versions of the GUSI % XXX what is GUSI? |
| 180 | +development environment for MacOS support POSIX threads. Therefore, |
| 181 | +POSIX threads are now supported on the Macintosh too. Threading |
| 182 | +support using the user-space GNU pth library was also contributed. |
| 183 | + |
| 184 | +Threading support on Windows was enhanced, too. Windows supports |
| 185 | +thread locks that use kernel objects only in case of contention; in |
| 186 | +the common case when there's no contention, they use simpler functions |
| 187 | +which are an order of magnitude faster. A threaded version of Python |
| 188 | +1.5.2 on NT is twice as slow as an unthreaded version; with the 1.6 |
| 189 | +changes, the difference is only 10\%. These improvements were |
| 190 | +contributed by Yakov Markovitch. |
| 191 | + |
| 192 | +% ====================================================================== |
| 193 | +\section{Module changes} |
| 194 | + |
| 195 | +re - changed to be a frontend to sre |
| 196 | + |
| 197 | +readline, ConfigParser, cgi, calendar, posix, readline, xmllib, aifc, chunk, |
| 198 | +wave, random, shelve, nntplib - minor enhancements |
| 199 | + |
| 200 | +socket, httplib, urllib - optional OpenSSL support |
| 201 | + |
| 202 | +_tkinter - support for 8.1,8.2,8.3 (support for versions older then 8.0 |
| 203 | +has been dropped). Supports Unicode (Lib/lib-tk/Tkinter.py has a test) |
| 204 | + |
| 205 | +curses -- changed to use ncurses |
| 206 | + |
| 207 | +% ====================================================================== |
| 208 | +\section{New modules} |
| 209 | + |
| 210 | +winreg - Windows registry interface. |
| 211 | +Distutils - tools for distributing Python modules |
| 212 | +PyExpat - interface to Expat XML parser |
| 213 | +robotparser - parse a robots.txt file (for writing web spiders) |
| 214 | +linuxaudio - audio for Linux |
| 215 | +mmap - treat a file as a memory buffer |
| 216 | +filecmp - supersedes the old cmp.py and dircmp.py modules |
| 217 | +tabnanny - check Python sources for tab-width dependance |
| 218 | +sre - regular expressions (fast, supports unicode) |
| 219 | +unicode - support for unicode |
| 220 | +codecs - support for Unicode encoders/decoders |
| 221 | + |
| 222 | +% ====================================================================== |
| 223 | +\section{IDLE Improvements} |
| 224 | + |
| 225 | +XXX IDLE -- complete overhaul; what are the changes? |
| 226 | + |
| 227 | +% ====================================================================== |
| 228 | +\section{Deleted and Deprecated Modules} |
| 229 | + |
| 230 | +stdwin |
| 231 | + |
| 232 | +\end{document} |
| 233 | + |
0 commit comments