blob: 8ff32e494d0f9f4a8694573cc7e9b921c0f90461 [file] [log] [blame]
Fred Drake03e10312002-03-26 19:17:43 +00001\documentclass{howto}
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +00002% $Id$
3
Andrew M. Kuchling517109b2002-05-07 21:01:16 +00004% TODO:
5% Go through and get the contributor's name for all the various changes
6
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +00007\title{What's New in Python 2.3}
8\release{0.01}
9\author{A.M. Kuchling}
10\authoraddress{\email{akuchlin@mems-exchange.org}}
Fred Drake03e10312002-03-26 19:17:43 +000011
12\begin{document}
13\maketitle
14\tableofcontents
15
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +000016%\section{Introduction \label{intro}}
17
18{\large This article is a draft, and is currently up to date for some
Andrew M. Kuchling821013e2002-05-06 17:46:39 +000019random version of the CVS tree around May 26 2002. Please send any
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +000020additions, comments or errata to the author.}
21
22This article explains the new features in Python 2.3. The tentative
23release date of Python 2.3 is currently scheduled for August 30 2002.
24
25This article doesn't attempt to provide a complete specification of
26the new features, but instead provides a convenient overview. For
27full details, you should refer to the documentation for Python 2.3,
28such as the
29\citetitle[http://www.python.org/doc/2.3/lib/lib.html]{Python Library
30Reference} and the
31\citetitle[http://www.python.org/doc/2.3/ref/ref.html]{Python
32Reference Manual}. If you want to understand the complete
33implementation and design rationale for a change, refer to the PEP for
34a particular new feature.
Fred Drake03e10312002-03-26 19:17:43 +000035
36
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +000037%======================================================================
Andrew M. Kuchling517109b2002-05-07 21:01:16 +000038\section{PEP 255: Simple Generators\label{section-generators}}
Andrew M. Kuchlingf4dd65d2002-04-01 19:28:09 +000039
40In Python 2.2, generators were added as an optional feature, to be
41enabled by a \code{from __future__ import generators} directive. In
422.3 generators no longer need to be specially enabled, and are now
43always present; this means that \keyword{yield} is now always a
44keyword. The rest of this section is a copy of the description of
45generators from the ``What's New in Python 2.2'' document; if you read
46it when 2.2 came out, you can skip the rest of this section.
47
Andrew M. Kuchling517109b2002-05-07 21:01:16 +000048You're doubtless familiar with how function calls work in Python or C.
49When you call a function, it gets a private namespace where its local
Andrew M. Kuchlingf4dd65d2002-04-01 19:28:09 +000050variables are created. When the function reaches a \keyword{return}
51statement, the local variables are destroyed and the resulting value
52is returned to the caller. A later call to the same function will get
Andrew M. Kuchling517109b2002-05-07 21:01:16 +000053a fresh new set of local variables. But, what if the local variables
Andrew M. Kuchlingf4dd65d2002-04-01 19:28:09 +000054weren't thrown away on exiting a function? What if you could later
55resume the function where it left off? This is what generators
56provide; they can be thought of as resumable functions.
57
58Here's the simplest example of a generator function:
59
60\begin{verbatim}
61def generate_ints(N):
62 for i in range(N):
63 yield i
64\end{verbatim}
65
66A new keyword, \keyword{yield}, was introduced for generators. Any
67function containing a \keyword{yield} statement is a generator
68function; this is detected by Python's bytecode compiler which
69compiles the function specially as a result.
70
71When you call a generator function, it doesn't return a single value;
72instead it returns a generator object that supports the iterator
73protocol. On executing the \keyword{yield} statement, the generator
74outputs the value of \code{i}, similar to a \keyword{return}
75statement. The big difference between \keyword{yield} and a
76\keyword{return} statement is that on reaching a \keyword{yield} the
77generator's state of execution is suspended and local variables are
78preserved. On the next call to the generator's \code{.next()} method,
79the function will resume executing immediately after the
80\keyword{yield} statement. (For complicated reasons, the
81\keyword{yield} statement isn't allowed inside the \keyword{try} block
82of a \code{try...finally} statement; read \pep{255} for a full
83explanation of the interaction between \keyword{yield} and
84exceptions.)
85
86Here's a sample usage of the \function{generate_ints} generator:
87
88\begin{verbatim}
89>>> gen = generate_ints(3)
90>>> gen
91<generator object at 0x8117f90>
92>>> gen.next()
930
94>>> gen.next()
951
96>>> gen.next()
972
98>>> gen.next()
99Traceback (most recent call last):
100 File "<stdin>", line 1, in ?
101 File "<stdin>", line 2, in generate_ints
102StopIteration
103\end{verbatim}
104
105You could equally write \code{for i in generate_ints(5)}, or
106\code{a,b,c = generate_ints(3)}.
107
108Inside a generator function, the \keyword{return} statement can only
109be used without a value, and signals the end of the procession of
110values; afterwards the generator cannot return any further values.
111\keyword{return} with a value, such as \code{return 5}, is a syntax
112error inside a generator function. The end of the generator's results
113can also be indicated by raising \exception{StopIteration} manually,
114or by just letting the flow of execution fall off the bottom of the
115function.
116
117You could achieve the effect of generators manually by writing your
118own class and storing all the local variables of the generator as
119instance variables. For example, returning a list of integers could
120be done by setting \code{self.count} to 0, and having the
121\method{next()} method increment \code{self.count} and return it.
122However, for a moderately complicated generator, writing a
123corresponding class would be much messier.
124\file{Lib/test/test_generators.py} contains a number of more
125interesting examples. The simplest one implements an in-order
126traversal of a tree using generators recursively.
127
128\begin{verbatim}
129# A recursive generator that generates Tree leaves in in-order.
130def inorder(t):
131 if t:
132 for x in inorder(t.left):
133 yield x
134 yield t.label
135 for x in inorder(t.right):
136 yield x
137\end{verbatim}
138
139Two other examples in \file{Lib/test/test_generators.py} produce
140solutions for the N-Queens problem (placing $N$ queens on an $NxN$
141chess board so that no queen threatens another) and the Knight's Tour
142(a route that takes a knight to every square of an $NxN$ chessboard
143without visiting any square twice).
144
145The idea of generators comes from other programming languages,
146especially Icon (\url{http://www.cs.arizona.edu/icon/}), where the
147idea of generators is central. In Icon, every
148expression and function call behaves like a generator. One example
149from ``An Overview of the Icon Programming Language'' at
150\url{http://www.cs.arizona.edu/icon/docs/ipd266.htm} gives an idea of
151what this looks like:
152
153\begin{verbatim}
154sentence := "Store it in the neighboring harbor"
155if (i := find("or", sentence)) > 5 then write(i)
156\end{verbatim}
157
158In Icon the \function{find()} function returns the indexes at which the
159substring ``or'' is found: 3, 23, 33. In the \keyword{if} statement,
160\code{i} is first assigned a value of 3, but 3 is less than 5, so the
161comparison fails, and Icon retries it with the second value of 23. 23
162is greater than 5, so the comparison now succeeds, and the code prints
163the value 23 to the screen.
164
165Python doesn't go nearly as far as Icon in adopting generators as a
166central concept. Generators are considered a new part of the core
167Python language, but learning or using them isn't compulsory; if they
168don't solve any problems that you have, feel free to ignore them.
169One novel feature of Python's interface as compared to
170Icon's is that a generator's state is represented as a concrete object
171(the iterator) that can be passed around to other functions or stored
172in a data structure.
173
174\begin{seealso}
175
176\seepep{255}{Simple Generators}{Written by Neil Schemenauer, Tim
177Peters, Magnus Lie Hetland. Implemented mostly by Neil Schemenauer
178and Tim Peters, with other fixes from the Python Labs crew.}
179
180\end{seealso}
181
182
183%======================================================================
Andrew M. Kuchlingf3676512002-04-15 02:27:55 +0000184\section{PEP 278: Universal Newline Support}
185
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000186The three major operating systems used today are Microsoft Windows,
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000187Apple's Macintosh OS, and the various \UNIX\ derivatives. A minor
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000188irritation is that these three platforms all use different characters
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000189to mark the ends of lines in text files. \UNIX\ uses character 10,
190the ASCII linefeed, while MacOS uses character 13, the ASCII carriage
191return, and Windows uses a two-character sequence of a carriage return
192plus a newline.
Andrew M. Kuchlingf3676512002-04-15 02:27:55 +0000193
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000194Python's file objects can now support end of line conventions other
195than the one followed by the platform on which Python is running.
196Opening a file with the mode \samp{U} or \samp{rU} will open a file
197for reading in universal newline mode. All three line ending
198conventions will be translated to a \samp{\e n} in the strings
199returned by the various file methods such as \method{read()} and
200\method{readline()}.
Andrew M. Kuchlingf3676512002-04-15 02:27:55 +0000201
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000202Universal newline support is also used when importing modules and when
203executing a file with the \function{execfile()} function. This means
204that Python modules can be shared between all three operating systems
205without needing to convert the line-endings.
206
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000207This feature can be disabled at compile-time by specifying
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000208\longprogramopt{without-universal-newlines} when running Python's
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000209\file{configure} script.
Andrew M. Kuchlingf3676512002-04-15 02:27:55 +0000210
211\begin{seealso}
212
213\seepep{278}{Universal Newline Support}{Written
214and implemented by Jack Jansen.}
215
216\end{seealso}
217
Andrew M. Kuchlingfad2f592002-05-10 21:00:05 +0000218
219%======================================================================
220\section{PEP 279: The \function{enumerate()} Built-in Function}
221
222A new built-in function, \function{enumerate()}, will make
223certain loops a bit clearer. \code{enumerate(thing)}, where
224\var{thing} is either an iterator or a sequence, returns a iterator
225that will return \code{(0, \var{thing[0]})}, \code{(1,
226\var{thing[1]})}, \code{(2, \var{thing[2]})}, and so forth. Fairly
227often you'll see code to change every element of a list that looks
228like this:
229
230\begin{verbatim}
231for i in range(len(L)):
232 item = L[i]
233 # ... compute some result based on item ...
234 L[i] = result
235\end{verbatim}
236
237This can be rewritten using \function{enumerate()} as:
238
239\begin{verbatim}
240for i, item in enumerate(L):
241 # ... compute some result based on item ...
242 L[i] = result
243\end{verbatim}
244
245
246\begin{seealso}
247
248\seepep{279}{The enumerate() built-in function}{Written
249by Raymond D. Hettinger.}
250
251\end{seealso}
252
253
Andrew M. Kuchlingf3676512002-04-15 02:27:55 +0000254%======================================================================
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000255\section{PEP 285: The \class{bool} Type\label{section-bool}}
256
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000257A Boolean type was added to Python 2.3. Two new constants were added
258to the \module{__builtin__} module, \constant{True} and
259\constant{False}. The type object for this new type is named
260\class{bool}; the constructor for it takes any Python value and
261converts it to \constant{True} or \constant{False}.
262
263\begin{verbatim}
264>>> bool(1)
265True
266>>> bool(0)
267False
268>>> bool([])
269False
270>>> bool( (1,) )
271True
272\end{verbatim}
273
274Most of the standard library modules and built-in functions have been
275changed to return Booleans.
276
277\begin{verbatim}
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000278>>> obj = []
279>>> hasattr(obj, 'append')
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000280True
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000281>>> isinstance(obj, list)
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000282True
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000283>>> isinstance(obj, tuple)
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000284False
285\end{verbatim}
286
287Python's Booleans were added with the primary goal of making code
288clearer. For example, if you're reading a function and encounter the
289statement \code{return 1}, you might wonder whether the \samp{1}
290represents a truth value, or whether it's an index, or whether it's a
291coefficient that multiplies some other quantity. If the statement is
292\code{return True}, however, the meaning of the return value is quite
293clearly a truth value.
294
295Python's Booleans were not added for the sake of strict type-checking.
296A very strict language such as Pascal
297% XXX is Pascal the right example here?
298would also prevent you performing arithmetic with Booleans, and would
299require that the expression in an \keyword{if} statement always
300evaluate to a Boolean. Python is not this strict, and it never will
301be. (\pep{285} explicitly says this.) So you can still use any
302expression in an \keyword{if}, even ones that evaluate to a list or
303tuple or some random object, and the Boolean type is a subclass of the
304\class{int} class, so arithmetic using a Boolean still works.
305
306\begin{verbatim}
307>>> True + 1
3082
309>>> False + 1
3101
311>>> False * 75
3120
313>>> True * 75
31475
315\end{verbatim}
316
317To sum up \constant{True} and \constant{False} in a sentence: they're
318alternative ways to spell the integer values 1 and 0, with the single
319difference that \function{str()} and \function{repr()} return the
320strings \samp{True} and \samp{False} instead of \samp{1} and \samp{0}.
Andrew M. Kuchling3a52ff62002-04-03 22:44:47 +0000321
322\begin{seealso}
323
324\seepep{285}{Adding a bool type}{Written and implemented by GvR.}
325
326\end{seealso}
327
328
329%======================================================================
Andrew M. Kuchlingfad2f592002-05-10 21:00:05 +0000330%\section{Other Language Changes}
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000331
Andrew M. Kuchlingfad2f592002-05-10 21:00:05 +0000332%Here are the changes that Python 2.3 makes to the core language.
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000333
Andrew M. Kuchlingfad2f592002-05-10 21:00:05 +0000334%\begin{itemize}
335%\item The \keyword{yield} statement is now always a keyword, as
336%described in section~\ref{section-generators}.
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000337
Andrew M. Kuchlingfad2f592002-05-10 21:00:05 +0000338%\item Two new constants, \constant{True} and \constant{False} were
339%added along with the built-in \class{bool} type, as described in
340%section~\ref{section-bool}.
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000341
Andrew M. Kuchlingfad2f592002-05-10 21:00:05 +0000342%\item
343%\end{itemize}
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000344
345
346%======================================================================
347\section{Specialized Object Allocator (pymalloc)\label{section-pymalloc}}
348
349An experimental feature added to Python 2.1 was a specialized object
350allocator called pymalloc, written by Vladimir Marangozov. Pymalloc
351was intended to be faster than the system \function{malloc()} and have
352less memory overhead. The allocator uses C's \function{malloc()}
353function to get large pools of memory, and then fulfills smaller
354memory requests from these pools.
355
356In 2.1 and 2.2, pymalloc was an experimental feature and wasn't
357enabled by default; you had to explicitly turn it on by providing the
358\longprogramopt{with-pymalloc} option to the \program{configure}
359script. In 2.3, pymalloc has had further enhancements and is now
360enabled by default; you'll have to supply
361\longprogramopt{without-pymalloc} to disable it.
362
363This change is transparent to code written in Python; however,
364pymalloc may expose bugs in C extensions. Authors of C extension
365modules should test their code with the object allocator enabled,
366because some incorrect code may cause core dumps at runtime. There
367are a bunch of memory allocation functions in Python's C API that have
368previously been just aliases for the C library's \function{malloc()}
369and \function{free()}, meaning that if you accidentally called
370mismatched functions, the error wouldn't be noticeable. When the
371object allocator is enabled, these functions aren't aliases of
372\function{malloc()} and \function{free()} any more, and calling the
373wrong function to free memory will get you a core dump. For example,
374if memory was allocated using \function{PyMem_New()}, it has to be
375freed using \function{PyMem_Del()}, not \function{free()}. A few
376modules included with Python fell afoul of this and had to be fixed;
377doubtless there are more third-party modules that will have the same
378problem.
379
380As part of this change, the confusing multiple interfaces for
381allocating memory have been consolidated down into two APIs.
382Memory allocated with one API must not be freed with the other API.
383
384\begin{itemize}
385 \item To allocate and free an undistinguished chunk of memory, use
386 \cfunction{PyMem_Malloc()}, \cfunction{PyMem_Realloc()},
387 \cfunction{PyMem_Free()}, and the other \cfunction{PyMem_*}
388 functions.
389
390 \item To allocate and free Python objects,
391 use \cfunction{PyObject_New()}, \cfunction{PyObject_NewVar()}, and
392 \cfunction{PyObject_Del()}.
393\end{itemize}
394
395Thanks to lots of work by Tim Peters, pymalloc in 2.3 also provides
396debugging features to catch memory overwrites and doubled frees in
397both extension modules and in the interpreter itself. To enable this
398support, turn on the Python interpreter's debugging code by running
399\program{configure} with \longprogramopt{with-pydebug}.
400
401\begin{seealso}
402
Andrew M. Kuchlingfad2f592002-05-10 21:00:05 +0000403\seeurl{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/dist/src/Objects/obmalloc.c}
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000404{For the full details of the pymalloc implementation, see
405the comments at the top of the file \file{Objects/obmalloc.c} in the
406Python source code. The above link points to the file within the
407SourceForge CVS browser.}
408
409\end{seealso}
410
411%======================================================================
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +0000412\section{New and Improved Modules}
413
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000414As usual, Python's standard modules had a number of enhancements and
415bug fixes. Here's a partial list; consult the \file{Misc/NEWS} file
416in the source tree, or the CVS logs, for a more complete list.
417
418\begin{itemize}
419
420\item One minor but far-reaching change is that the names of extension
421types defined by the modules included with Python now contain the
422module and a \samp{.} in front of the type name. For example, in
423Python 2.2, if you created a socket and printed its
424\member{__class__}, you'd get this output:
425
426\begin{verbatim}
427>>> s = socket.socket()
428>>> s.__class__
429<type 'socket'>
430\end{verbatim}
431
432In 2.3, you get this:
433\begin{verbatim}
434>>> s.__class__
435<type '_socket.socket'>
436\end{verbatim}
437
438\item The \method{strip()}, \method{lstrip()}, and \method{rstrip()}
439string methods now have an optional argument for specifying the
440characters to strip. The default is still to remove all whitespace
441characters:
442
443\begin{verbatim}
444>>> ' abc '.strip()
445'abc'
446>>> '><><abc<><><>'.strip('<>')
447'abc'
448>>> '><><abc<><><>\n'.strip('<>')
449'abc<><><>\n'
450>>> u'\u4000\u4001abc\u4000'.strip(u'\u4000')
451u'\u4001abc'
452>>>
453\end{verbatim}
454
455\item Another new string method is \method{zfill()}, originally a
456function in the \module{string} module. \method{zfill()} pads a
457numeric string with zeros on the left until it's the specified width.
458Note that the \code{\%} operator is still more flexible and powerful
459than \method{zfill()}.
460
461\begin{verbatim}
462>>> '45'.zfill(4)
463'0045'
464>>> '12345'.zfill(4)
465'12345'
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000466>>> 'goofy'.zfill(6)
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000467'0goofy'
468\end{verbatim}
469
470\item Dictionaries have a new method, method{pop(\var{key})}, that
471returns the value corresponding to \var{key} and removes that
472key/value pair from the dictionary. \method{pop()} will raise a
473\exception{KeyError} if the requsted key isn't present in the
474dictionary:
475
476\begin{verbatim}
477>>> d = {1:2}
478>>> d
479{1: 2}
480>>> d.pop(4)
481Traceback (most recent call last):
482 File ``<stdin>'', line 1, in ?
483KeyError: 4
484>>> d.pop(1)
4852
486>>> d.pop(1)
487Traceback (most recent call last):
488 File ``<stdin>'', line 1, in ?
489KeyError: pop(): dictionary is empty
490>>> d
491{}
492>>>
493\end{verbatim}
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +0000494
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000495\item Two new functions, \function{killpg()} and \function{mknod()},
496were added to the \module{posix} module that underlies the \module{os}
497module.
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +0000498
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000499\item Two new binary packagers were added to the Distutils.
500\code{bdist_pkgtool} builds \file{.pkg} files to use with Solaris
501\program{pkgtool}, and \code{bdist_sdux} builds \program{swinstall}
502packages for use on HP-UX. (Contributed by Mark Alexander.)
503
504\item The \module{array} module now supports arrays of Unicode
505characters using the \samp{u} format character. Arrays also
506now support using the \code{+=} assignment operator to add another array's
507contents, and the \code{*=} assignment operator to repeat an array.
Andrew M. Kuchlingfad2f592002-05-10 21:00:05 +0000508(Contributed by Jason Orendorff.)
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +0000509
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000510\item The \module{grp} module now returns enhanced tuples:
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +0000511
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000512\begin{verbatim}
513>>> import grp
514>>> g = grp.getgrnam('amk')
515>>> g.gr_name, g.gr_gid
516('amk', 500)
517\end{verbatim}
Andrew M. Kuchlingf3676512002-04-15 02:27:55 +0000518
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000519\item The \module{readline} module also gained a number of new
520functions: \function{get_history_item()},
521\function{get_current_history_length()}, and \function{redisplay()}.
Andrew M. Kuchling8e8af6e2002-04-15 14:05:59 +0000522
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000523\end{itemize}
524
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +0000525
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000526% ======================================================================
527\section{Build and C API Changes}
528
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000529Changes to Python's build process, and to the C API, include:
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000530
531\begin{itemize}
532
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000533\item Python can now optionally be built as a shared library
534(\file{libpython2.3.so}) by supplying \longprogramopt{enable-shared}
Andrew M. Kuchlingfad2f592002-05-10 21:00:05 +0000535when running Python's \file{configure} script. (Contributed by Ondrej
536Palkovsky.)
Andrew M. Kuchlingf4dd65d2002-04-01 19:28:09 +0000537
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000538\item The \cfunction{PyArg_NoArgs()} macro is now deprecated, and code
539that
540uses it should be changed to use \code{PyArg_ParseTuple(args, "")}
541instead.
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +0000542
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000543\item A new function, \cfunction{PyObject_DelItemString(\var{mapping},
544char *\var{key})} was added
545as shorthand for
546\code{PyObject_DelItem(\var{mapping}, PyString_New(\var{key})}.
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +0000547
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000548\item The source code for the Expat XML parser is now included with
549the Python source, so the \module{pyexpat} module is no longer
550dependent on having a system library containing Expat.
551
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000552\item File objects now manage their internal string buffer
553differently by increasing it exponentially when needed.
554This results in the benchmark tests in \file{Lib/test/test_bufio.py}
555speeding up from 57 seconds to 1.7 seconds, according to one
556measurement.
557
558\item XXX Introduce two new flag bits that can be set in a PyMethodDef method
Andrew M. Kuchling45afd542002-04-02 14:25:25 +0000559descriptor, as used for the tp_methods slot of a type. These new flag
560bits are both optional, and mutually exclusive. Most methods will not
561use either. These flags are used to create special method types which
562exist in the same namespace as normal methods without having to use
563tedious construction code to insert the new special method objects in
564the type's tp_dict after PyType_Ready() has been called.
565
566If METH_CLASS is specified, the method will represent a class method
567like that returned by the classmethod() built-in.
568
569If METH_STATIC is specified, the method will represent a static method
570like that returned by the staticmethod() built-in.
571
572These flags may not be used in the PyMethodDef table for modules since
573these special method types are not meaningful in that case; a
574ValueError will be raised if these flags are found in that context.
Andrew M. Kuchling45afd542002-04-02 14:25:25 +0000575
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000576\end{itemize}
577
578\subsection{Port-Specific Changes}
579
580XXX write this
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +0000581
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000582XXX OS/2 EMX port
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +0000583
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000584XXX MacOS: Weaklink most toolbox modules, improving backward
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +0000585compatibility. Modules will no longer fail to load if a single routine
586is missing on the curent OS version, in stead calling the missing
587routine will raise an exception. Should finally fix 531398. 2.2.1
588candidate. Also blacklisted some constants with definitions that
589were not Python-compatible.
590
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000591XXX Checked in Sean Reifschneider's RPM spec file and patches.
Fred Drake03e10312002-03-26 19:17:43 +0000592
593
594%======================================================================
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000595\section{Other Changes and Fixes}
596
597Finally, there are various miscellaneous fixes:
598
599\begin{itemize}
600
601\item The tools used to build the documentation now work under Cygwin
602as well as \UNIX.
603
604\end{itemize}
605
606%======================================================================
Fred Drake03e10312002-03-26 19:17:43 +0000607\section{Acknowledgements \label{acks}}
608
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +0000609The author would like to thank the following people for offering
610suggestions, corrections and assistance with various drafts of this
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000611article: Fred~L. Drake, Jr., Detlef Lannert.
Fred Drake03e10312002-03-26 19:17:43 +0000612
613\end{document}