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