blob: 9ef18ec7b1c062d1b0610e5aeb293604d2f7a288 [file] [log] [blame]
Fred Drake03e10312002-03-26 19:17:43 +00001\documentclass{howto}
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +00002% $Id$
3
4\title{What's New in Python 2.3}
Andrew M. Kuchling20e5abc2002-07-11 20:50:34 +00005\release{0.03}
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +00006\author{A.M. Kuchling}
7\authoraddress{\email{akuchlin@mems-exchange.org}}
Fred Drake03e10312002-03-26 19:17:43 +00008
9\begin{document}
10\maketitle
11\tableofcontents
12
Andrew M. Kuchlingf70a0a82002-06-10 13:22:46 +000013% Optik (or whatever it gets called)
14%
Andrew M. Kuchlingc61ec522002-08-04 01:20:05 +000015% MacOS framework-related changes (section of its own, probably)
16%
Andrew M. Kuchling950725f2002-08-06 01:40:48 +000017% New sorting code
Andrew M. Kuchling90e9a792002-08-15 00:40:21 +000018%
Andrew M. Kuchling90e9a792002-08-15 00:40:21 +000019% xreadlines obsolete; files are their own iterator
Andrew M. Kuchlingf70a0a82002-06-10 13:22:46 +000020
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +000021%\section{Introduction \label{intro}}
22
23{\large This article is a draft, and is currently up to date for some
Andrew M. Kuchling20e5abc2002-07-11 20:50:34 +000024random version of the CVS tree around mid-July 2002. Please send any
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +000025additions, comments or errata to the author.}
26
27This article explains the new features in Python 2.3. The tentative
Andrew M. Kuchling20e5abc2002-07-11 20:50:34 +000028release date of Python 2.3 is currently scheduled for some undefined
29time before the end of 2002.
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +000030
31This article doesn't attempt to provide a complete specification of
32the new features, but instead provides a convenient overview. For
33full details, you should refer to the documentation for Python 2.3,
34such as the
35\citetitle[http://www.python.org/doc/2.3/lib/lib.html]{Python Library
36Reference} and the
37\citetitle[http://www.python.org/doc/2.3/ref/ref.html]{Python
38Reference Manual}. If you want to understand the complete
39implementation and design rationale for a change, refer to the PEP for
40a particular new feature.
Fred Drake03e10312002-03-26 19:17:43 +000041
42
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +000043%======================================================================
Andrew M. Kuchling517109b2002-05-07 21:01:16 +000044\section{PEP 255: Simple Generators\label{section-generators}}
Andrew M. Kuchlingf4dd65d2002-04-01 19:28:09 +000045
46In Python 2.2, generators were added as an optional feature, to be
47enabled by a \code{from __future__ import generators} directive. In
482.3 generators no longer need to be specially enabled, and are now
49always present; this means that \keyword{yield} is now always a
50keyword. The rest of this section is a copy of the description of
51generators from the ``What's New in Python 2.2'' document; if you read
52it when 2.2 came out, you can skip the rest of this section.
53
Andrew M. Kuchling517109b2002-05-07 21:01:16 +000054You're doubtless familiar with how function calls work in Python or C.
55When you call a function, it gets a private namespace where its local
Andrew M. Kuchlingf4dd65d2002-04-01 19:28:09 +000056variables are created. When the function reaches a \keyword{return}
57statement, the local variables are destroyed and the resulting value
58is returned to the caller. A later call to the same function will get
Andrew M. Kuchling517109b2002-05-07 21:01:16 +000059a fresh new set of local variables. But, what if the local variables
Andrew M. Kuchlingf4dd65d2002-04-01 19:28:09 +000060weren't thrown away on exiting a function? What if you could later
61resume the function where it left off? This is what generators
62provide; they can be thought of as resumable functions.
63
64Here's the simplest example of a generator function:
65
66\begin{verbatim}
67def generate_ints(N):
68 for i in range(N):
69 yield i
70\end{verbatim}
71
72A new keyword, \keyword{yield}, was introduced for generators. Any
73function containing a \keyword{yield} statement is a generator
74function; this is detected by Python's bytecode compiler which
75compiles the function specially as a result.
76
77When you call a generator function, it doesn't return a single value;
78instead it returns a generator object that supports the iterator
79protocol. On executing the \keyword{yield} statement, the generator
80outputs the value of \code{i}, similar to a \keyword{return}
81statement. The big difference between \keyword{yield} and a
82\keyword{return} statement is that on reaching a \keyword{yield} the
83generator's state of execution is suspended and local variables are
84preserved. On the next call to the generator's \code{.next()} method,
85the function will resume executing immediately after the
86\keyword{yield} statement. (For complicated reasons, the
87\keyword{yield} statement isn't allowed inside the \keyword{try} block
88of a \code{try...finally} statement; read \pep{255} for a full
89explanation of the interaction between \keyword{yield} and
90exceptions.)
91
92Here's a sample usage of the \function{generate_ints} generator:
93
94\begin{verbatim}
95>>> gen = generate_ints(3)
96>>> gen
97<generator object at 0x8117f90>
98>>> gen.next()
990
100>>> gen.next()
1011
102>>> gen.next()
1032
104>>> gen.next()
105Traceback (most recent call last):
Andrew M. Kuchling9f6e1042002-06-17 13:40:04 +0000106 File "stdin", line 1, in ?
107 File "stdin", line 2, in generate_ints
Andrew M. Kuchlingf4dd65d2002-04-01 19:28:09 +0000108StopIteration
109\end{verbatim}
110
111You could equally write \code{for i in generate_ints(5)}, or
112\code{a,b,c = generate_ints(3)}.
113
114Inside a generator function, the \keyword{return} statement can only
115be used without a value, and signals the end of the procession of
116values; afterwards the generator cannot return any further values.
117\keyword{return} with a value, such as \code{return 5}, is a syntax
118error inside a generator function. The end of the generator's results
119can also be indicated by raising \exception{StopIteration} manually,
120or by just letting the flow of execution fall off the bottom of the
121function.
122
123You could achieve the effect of generators manually by writing your
124own class and storing all the local variables of the generator as
125instance variables. For example, returning a list of integers could
126be done by setting \code{self.count} to 0, and having the
127\method{next()} method increment \code{self.count} and return it.
128However, for a moderately complicated generator, writing a
129corresponding class would be much messier.
130\file{Lib/test/test_generators.py} contains a number of more
131interesting examples. The simplest one implements an in-order
132traversal of a tree using generators recursively.
133
134\begin{verbatim}
135# A recursive generator that generates Tree leaves in in-order.
136def inorder(t):
137 if t:
138 for x in inorder(t.left):
139 yield x
140 yield t.label
141 for x in inorder(t.right):
142 yield x
143\end{verbatim}
144
145Two other examples in \file{Lib/test/test_generators.py} produce
146solutions for the N-Queens problem (placing $N$ queens on an $NxN$
147chess board so that no queen threatens another) and the Knight's Tour
148(a route that takes a knight to every square of an $NxN$ chessboard
149without visiting any square twice).
150
151The idea of generators comes from other programming languages,
152especially Icon (\url{http://www.cs.arizona.edu/icon/}), where the
153idea of generators is central. In Icon, every
154expression and function call behaves like a generator. One example
155from ``An Overview of the Icon Programming Language'' at
156\url{http://www.cs.arizona.edu/icon/docs/ipd266.htm} gives an idea of
157what this looks like:
158
159\begin{verbatim}
160sentence := "Store it in the neighboring harbor"
161if (i := find("or", sentence)) > 5 then write(i)
162\end{verbatim}
163
164In Icon the \function{find()} function returns the indexes at which the
165substring ``or'' is found: 3, 23, 33. In the \keyword{if} statement,
166\code{i} is first assigned a value of 3, but 3 is less than 5, so the
167comparison fails, and Icon retries it with the second value of 23. 23
168is greater than 5, so the comparison now succeeds, and the code prints
169the value 23 to the screen.
170
171Python doesn't go nearly as far as Icon in adopting generators as a
172central concept. Generators are considered a new part of the core
173Python language, but learning or using them isn't compulsory; if they
174don't solve any problems that you have, feel free to ignore them.
175One novel feature of Python's interface as compared to
176Icon's is that a generator's state is represented as a concrete object
177(the iterator) that can be passed around to other functions or stored
178in a data structure.
179
180\begin{seealso}
181
182\seepep{255}{Simple Generators}{Written by Neil Schemenauer, Tim
183Peters, Magnus Lie Hetland. Implemented mostly by Neil Schemenauer
184and Tim Peters, with other fixes from the Python Labs crew.}
185
186\end{seealso}
187
188
189%======================================================================
Andrew M. Kuchling950725f2002-08-06 01:40:48 +0000190\section{PEP 263: \label{section-encodings}}
191
192Python source files can now be declared as being in different
193character set encodings. Encodings are declared by including a
194specially formatted comment in the first or second line of the source
195file. For example, a UTF-8 file can be declared with:
196
197\begin{verbatim}
198#!/usr/bin/env python
199# -*- coding: UTF-8 -*-
200\end{verbatim}
201
202Without such an encoding declaration, the default encoding used is
203ISO-8859-1, also known as Latin1.
204
205The encoding declaration only affects Unicode string literals; the
206text in the source code will be converted to Unicode using the
207specified encoding. Note that Python identifiers are still restricted
208to ASCII characters, so you can't have variable names that use
209characters outside of the usual alphanumerics.
210
211\begin{seealso}
212
213\seepep{263}{Defining Python Source Code Encodings}{Written by
214Marc-Andr\'e Lemburg and Martin von L\"owis; implemented by Martin von
215L\"owis.}
216
217\end{seealso}
218
219
220%======================================================================
Andrew M. Kuchlingf3676512002-04-15 02:27:55 +0000221\section{PEP 278: Universal Newline Support}
222
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000223The three major operating systems used today are Microsoft Windows,
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000224Apple's Macintosh OS, and the various \UNIX\ derivatives. A minor
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000225irritation is that these three platforms all use different characters
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000226to mark the ends of lines in text files. \UNIX\ uses character 10,
227the ASCII linefeed, while MacOS uses character 13, the ASCII carriage
228return, and Windows uses a two-character sequence of a carriage return
229plus a newline.
Andrew M. Kuchlingf3676512002-04-15 02:27:55 +0000230
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000231Python's file objects can now support end of line conventions other
232than the one followed by the platform on which Python is running.
233Opening a file with the mode \samp{U} or \samp{rU} will open a file
234for reading in universal newline mode. All three line ending
235conventions will be translated to a \samp{\e n} in the strings
236returned by the various file methods such as \method{read()} and
237\method{readline()}.
Andrew M. Kuchlingf3676512002-04-15 02:27:55 +0000238
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000239Universal newline support is also used when importing modules and when
240executing a file with the \function{execfile()} function. This means
241that Python modules can be shared between all three operating systems
242without needing to convert the line-endings.
243
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000244This feature can be disabled at compile-time by specifying
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000245\longprogramopt{without-universal-newlines} when running Python's
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000246\file{configure} script.
Andrew M. Kuchlingf3676512002-04-15 02:27:55 +0000247
248\begin{seealso}
249
250\seepep{278}{Universal Newline Support}{Written
251and implemented by Jack Jansen.}
252
253\end{seealso}
254
Andrew M. Kuchlingfad2f592002-05-10 21:00:05 +0000255
256%======================================================================
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +0000257\section{PEP 279: The \function{enumerate()} Built-in Function\label{section-enumerate}}
Andrew M. Kuchlingfad2f592002-05-10 21:00:05 +0000258
259A new built-in function, \function{enumerate()}, will make
260certain loops a bit clearer. \code{enumerate(thing)}, where
261\var{thing} is either an iterator or a sequence, returns a iterator
262that will return \code{(0, \var{thing[0]})}, \code{(1,
263\var{thing[1]})}, \code{(2, \var{thing[2]})}, and so forth. Fairly
264often you'll see code to change every element of a list that looks
265like this:
266
267\begin{verbatim}
268for i in range(len(L)):
269 item = L[i]
270 # ... compute some result based on item ...
271 L[i] = result
272\end{verbatim}
273
274This can be rewritten using \function{enumerate()} as:
275
276\begin{verbatim}
277for i, item in enumerate(L):
278 # ... compute some result based on item ...
279 L[i] = result
280\end{verbatim}
281
282
283\begin{seealso}
284
285\seepep{279}{The enumerate() built-in function}{Written
286by Raymond D. Hettinger.}
287
288\end{seealso}
289
290
Andrew M. Kuchlingf3676512002-04-15 02:27:55 +0000291%======================================================================
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000292\section{PEP 285: The \class{bool} Type\label{section-bool}}
293
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000294A Boolean type was added to Python 2.3. Two new constants were added
295to the \module{__builtin__} module, \constant{True} and
296\constant{False}. The type object for this new type is named
297\class{bool}; the constructor for it takes any Python value and
298converts it to \constant{True} or \constant{False}.
299
300\begin{verbatim}
301>>> bool(1)
302True
303>>> bool(0)
304False
305>>> bool([])
306False
307>>> bool( (1,) )
308True
309\end{verbatim}
310
311Most of the standard library modules and built-in functions have been
312changed to return Booleans.
313
314\begin{verbatim}
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000315>>> obj = []
316>>> hasattr(obj, 'append')
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000317True
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000318>>> isinstance(obj, list)
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000319True
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000320>>> isinstance(obj, tuple)
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000321False
322\end{verbatim}
323
324Python's Booleans were added with the primary goal of making code
325clearer. For example, if you're reading a function and encounter the
326statement \code{return 1}, you might wonder whether the \samp{1}
327represents a truth value, or whether it's an index, or whether it's a
328coefficient that multiplies some other quantity. If the statement is
329\code{return True}, however, the meaning of the return value is quite
330clearly a truth value.
331
332Python's Booleans were not added for the sake of strict type-checking.
Andrew M. Kuchlinga2a206b2002-05-24 21:08:58 +0000333A very strict language such as Pascal would also prevent you
334performing arithmetic with Booleans, and would require that the
335expression in an \keyword{if} statement always evaluate to a Boolean.
336Python is not this strict, and it never will be. (\pep{285}
337explicitly says so.) So you can still use any expression in an
338\keyword{if}, even ones that evaluate to a list or tuple or some
339random object, and the Boolean type is a subclass of the
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000340\class{int} class, so arithmetic using a Boolean still works.
341
342\begin{verbatim}
343>>> True + 1
3442
345>>> False + 1
3461
347>>> False * 75
3480
349>>> True * 75
35075
351\end{verbatim}
352
353To sum up \constant{True} and \constant{False} in a sentence: they're
354alternative ways to spell the integer values 1 and 0, with the single
355difference that \function{str()} and \function{repr()} return the
356strings \samp{True} and \samp{False} instead of \samp{1} and \samp{0}.
Andrew M. Kuchling3a52ff62002-04-03 22:44:47 +0000357
358\begin{seealso}
359
360\seepep{285}{Adding a bool type}{Written and implemented by GvR.}
361
362\end{seealso}
363
Michael W. Hudson5efaf7e2002-06-11 10:55:12 +0000364
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +0000365\section{Extended Slices\label{section-slices}}
Michael W. Hudson5efaf7e2002-06-11 10:55:12 +0000366
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +0000367Ever since Python 1.4, the slicing syntax has supported an optional
368third ``step'' or ``stride'' argument. For example, these are all
369legal Python syntax: \code{L[1:10:2]}, \code{L[:-1:1]},
370\code{L[::-1]}. This was added to Python included at the request of
371the developers of Numerical Python. However, the built-in sequence
372types of lists, tuples, and strings have never supported this feature,
373and you got a \exception{TypeError} if you tried it. Michael Hudson
374contributed a patch that was applied to Python 2.3 and fixed this
375shortcoming.
376
377For example, you can now easily extract the elements of a list that
378have even indexes:
Fred Drakedf872a22002-07-03 12:02:01 +0000379
380\begin{verbatim}
381>>> L = range(10)
382>>> L[::2]
383[0, 2, 4, 6, 8]
384\end{verbatim}
385
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +0000386Negative values also work, so you can make a copy of the same list in
387reverse order:
Fred Drakedf872a22002-07-03 12:02:01 +0000388
389\begin{verbatim}
390>>> L[::-1]
391[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
392\end{verbatim}
Andrew M. Kuchling3a52ff62002-04-03 22:44:47 +0000393
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +0000394This also works for strings:
395
396\begin{verbatim}
397>>> s='abcd'
398>>> s[::2]
399'ac'
400>>> s[::-1]
401'dcba'
402\end{verbatim}
403
Michael W. Hudson4da01ed2002-07-19 15:48:56 +0000404as well as tuples and arrays.
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +0000405
Michael W. Hudson4da01ed2002-07-19 15:48:56 +0000406If you have a mutable sequence (i.e. a list or an array) you can
407assign to or delete an extended slice, but there are some differences
408in assignment to extended and regular slices. Assignment to a regular
409slice can be used to change the length of the sequence:
410
411\begin{verbatim}
412>>> a = range(3)
413>>> a
414[0, 1, 2]
415>>> a[1:3] = [4, 5, 6]
416>>> a
417[0, 4, 5, 6]
418\end{verbatim}
419
420but when assigning to an extended slice the list on the right hand
421side of the statement must contain the same number of items as the
422slice it is replacing:
423
424\begin{verbatim}
425>>> a = range(4)
426>>> a
427[0, 1, 2, 3]
428>>> a[::2]
429[0, 2]
430>>> a[::2] = range(0, -2, -1)
431>>> a
432[0, 1, -1, 3]
433>>> a[::2] = range(3)
434Traceback (most recent call last):
435 File "<stdin>", line 1, in ?
436ValueError: attempt to assign list of size 3 to extended slice of size 2
437\end{verbatim}
438
439Deletion is more straightforward:
440
441\begin{verbatim}
442>>> a = range(4)
443>>> a[::2]
444[0, 2]
445>>> del a[::2]
446>>> a
447[1, 3]
448\end{verbatim}
449
450One can also now pass slice objects to builtin sequences
451\method{__getitem__} methods:
452
453\begin{verbatim}
454>>> range(10).__getitem__(slice(0, 5, 2))
455[0, 2, 4]
456\end{verbatim}
457
458or use them directly in subscripts:
459
460\begin{verbatim}
461>>> range(10)[slice(0, 5, 2)]
462[0, 2, 4]
463\end{verbatim}
464
465To make implementing sequences that support extended slicing in Python
466easier, slice ojects now have a method \method{indices} which given
467the length of a sequence returns \code{(start, stop, step)} handling
468omitted and out-of-bounds indices in a manner consistent with regular
469slices (and this innocuous phrase hides a welter of confusing
470details!). The method is intended to be used like this:
471
472\begin{verbatim}
473class FakeSeq:
474 ...
475 def calc_item(self, i):
476 ...
477 def __getitem__(self, item):
478 if isinstance(item, slice):
479 return FakeSeq([self.calc_item(i)
480 in range(*item.indices(len(self)))])
481 else:
482 return self.calc_item(i)
483\end{verbatim}
484
Andrew M. Kuchling90e9a792002-08-15 00:40:21 +0000485From this example you can also see that the builtin ``\class{slice}''
486object is now the type object for the slice type, and is no longer a
487function. This is consistent with Python 2.2, where \class{int},
488\class{str}, etc., underwent the same change.
489
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +0000490
Andrew M. Kuchling3a52ff62002-04-03 22:44:47 +0000491%======================================================================
Fred Drakedf872a22002-07-03 12:02:01 +0000492\section{Other Language Changes}
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000493
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +0000494Here are all of the changes that Python 2.3 makes to the core Python
495language.
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000496
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +0000497\begin{itemize}
498\item The \keyword{yield} statement is now always a keyword, as
499described in section~\ref{section-generators} of this document.
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000500
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +0000501\item A new built-in function \function{enumerate()}
502was added, as described in section~\ref{section-enumerate} of this
503document.
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000504
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +0000505\item Two new constants, \constant{True} and \constant{False} were
506added along with the built-in \class{bool} type, as described in
507section~\ref{section-bool} of this document.
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000508
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +0000509\item Built-in types now support the extended slicing syntax,
510as described in section~\ref{section-slices} of this document.
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000511
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +0000512\item Dictionaries have a new method, \method{pop(\var{key})}, that
513returns the value corresponding to \var{key} and removes that
514key/value pair from the dictionary. \method{pop()} will raise a
515\exception{KeyError} if the requested key isn't present in the
516dictionary:
517
518\begin{verbatim}
519>>> d = {1:2}
520>>> d
521{1: 2}
522>>> d.pop(4)
523Traceback (most recent call last):
524 File ``stdin'', line 1, in ?
525KeyError: 4
526>>> d.pop(1)
5272
528>>> d.pop(1)
529Traceback (most recent call last):
530 File ``stdin'', line 1, in ?
531KeyError: pop(): dictionary is empty
532>>> d
533{}
534>>>
535\end{verbatim}
536
537(Patch contributed by Raymond Hettinger.)
538
Andrew M. Kuchling6974aa92002-08-20 00:54:36 +0000539\item The \keyword{assert} statement no longer checks the \code{__debug__}
540flag, so you can no longer disable assertions by assigning to \code{__debug__}.
541Running Python with the \programopt{-O} switch will still generate
542code that doesn't execute any assertions.
543
544\item Most type objects are now callable, so you can use them
545to create new objects such as functions, classes, and modules. (This
546means that the \module{new} module can be deprecated in a future
547Python version, because you can now use the type objects available
548in the \module{types} module.)
549% XXX should new.py use PendingDeprecationWarning?
550For example, you can create a new module object with the following code:
551
552\begin{verbatim}
553>>> import types
554>>> m = types.ModuleType('abc','docstring')
555>>> m
556<module 'abc' (built-in)>
557>>> m.__doc__
558'docstring'
559\end{verbatim}
560
561\item
562A new warning, \exception{PendingDeprecationWarning} was added to
563indicate features which are in the process of being
564deprecated. The warning will \emph{not} be printed by default. To
565check for use of features that will be deprecated in the future,
566supply \programopt{-Walways::PendingDeprecationWarning::} on the
567command line or use \function{warnings.filterwarnings()}.
568
569\item Using \code{None} as a variable name will now result in a
570\exception{SyntaxWarning} warning. In a future version of Python,
571\code{None} may finally become a keyword.
572
573\item One minor but far-reaching change is that the names of extension
574types defined by the modules included with Python now contain the
575module and a \samp{.} in front of the type name. For example, in
576Python 2.2, if you created a socket and printed its
577\member{__class__}, you'd get this output:
578
579\begin{verbatim}
580>>> s = socket.socket()
581>>> s.__class__
582<type 'socket'>
583\end{verbatim}
584
585In 2.3, you get this:
586\begin{verbatim}
587>>> s.__class__
588<type '_socket.socket'>
589\end{verbatim}
590
591\end{itemize}
592
593
594\subsection{String Changes}
595
596\begin{itemize}
597
598\item The \code{in} operator now works differently for strings.
599Previously, when evaluating \code{\var{X} in \var{Y}} where \var{X}
600and \var{Y} are strings, \var{X} could only be a single character.
601That's now changed; \var{X} can be a string of any length, and
602\code{\var{X} in \var{Y}} will return \constant{True} if \var{X} is a
603substring of \var{Y}. If \var{X} is the empty string, the result is
604always \constant{True}.
605
606\begin{verbatim}
607>>> 'ab' in 'abcd'
608True
609>>> 'ad' in 'abcd'
610False
611>>> '' in 'abcd'
612True
613\end{verbatim}
614
615Note that this doesn't tell you where the substring starts; the
616\method{find()} method is still necessary to figure that out.
617
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +0000618\item The \method{strip()}, \method{lstrip()}, and \method{rstrip()}
619string methods now have an optional argument for specifying the
620characters to strip. The default is still to remove all whitespace
621characters:
622
623\begin{verbatim}
624>>> ' abc '.strip()
625'abc'
626>>> '><><abc<><><>'.strip('<>')
627'abc'
628>>> '><><abc<><><>\n'.strip('<>')
629'abc<><><>\n'
630>>> u'\u4000\u4001abc\u4000'.strip(u'\u4000')
631u'\u4001abc'
632>>>
633\end{verbatim}
634
Andrew M. Kuchling346386f2002-07-12 20:24:42 +0000635(Contributed by Simon Brunning.)
636
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +0000637\item The \method{startswith()} and \method{endswith()}
638string methods now accept negative numbers for the start and end
639parameters.
640
641\item Another new string method is \method{zfill()}, originally a
642function in the \module{string} module. \method{zfill()} pads a
643numeric string with zeros on the left until it's the specified width.
644Note that the \code{\%} operator is still more flexible and powerful
645than \method{zfill()}.
646
647\begin{verbatim}
648>>> '45'.zfill(4)
649'0045'
650>>> '12345'.zfill(4)
651'12345'
652>>> 'goofy'.zfill(6)
653'0goofy'
654\end{verbatim}
655
Andrew M. Kuchling346386f2002-07-12 20:24:42 +0000656(Contributed by Walter D\"orwald.)
657
Andrew M. Kuchling20e5abc2002-07-11 20:50:34 +0000658\item A new type object, \class{basestring}, has been added.
659 Both 8-bit strings and Unicode strings inherit from this type, so
660 \code{isinstance(obj, basestring)} will return \constant{True} for
661 either kind of string. It's a completely abstract type, so you
662 can't create \class{basestring} instances.
663
Andrew M. Kuchling6974aa92002-08-20 00:54:36 +0000664\item Interned strings are no longer immortal. Interned will now be
665garbage-collected in the usual way when the only reference to them is
666from the internal dictionary of interned strings. (Implemented by
667Oren Tirosh.)
668
669\end{itemize}
670
671
672\subsection{Optimizations}
673
674\begin{itemize}
675
Andrew M. Kuchling950725f2002-08-06 01:40:48 +0000676\item The \method{sort()} method of list objects has been extensively
677rewritten by Tim Peters, and the implementation is significantly
678faster.
679
Andrew M. Kuchling6974aa92002-08-20 00:54:36 +0000680\item Multiplication of large long integers is now much faster thanks
681to an implementation of Karatsuba multiplication, an algorithm that
682scales better than the O(n*n) required for the grade-school
683multiplication algorithm. (Original patch by Christopher A. Craig,
684and significantly reworked by Tim Peters.)
Andrew M. Kuchling20e5abc2002-07-11 20:50:34 +0000685
Andrew M. Kuchling6974aa92002-08-20 00:54:36 +0000686\item The \code{SET_LINENO} opcode is now gone. This may provide a
687small speed increase, subject to your compiler's idiosyncrasies.
688(Removed by Michael Hudson.)
Andrew M. Kuchling20e5abc2002-07-11 20:50:34 +0000689
Andrew M. Kuchling6974aa92002-08-20 00:54:36 +0000690\item A number of small rearrangements have been made in various
691hotspots to improve performance, inlining a function here, removing
692some code there. (Implemented mostly by GvR, but lots of people have
693contributed to one change or another.)
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +0000694
695\end{itemize}
Neal Norwitzd68f5172002-05-29 15:54:55 +0000696
Andrew M. Kuchling6974aa92002-08-20 00:54:36 +0000697
Andrew M. Kuchling517109b2002-05-07 21:01:16 +0000698%======================================================================
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +0000699\section{New and Improved Modules}
700
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000701As usual, Python's standard modules had a number of enhancements and
Andrew M. Kuchlinga982eb12002-07-22 18:57:36 +0000702bug fixes. Here's a partial list of the most notable changes, sorted
703alphabetically by module name. Consult the
704\file{Misc/NEWS} file in the source tree for a more
705complete list of changes, or look through the CVS logs for all the
706details.
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000707
708\begin{itemize}
709
Andrew M. Kuchlinga982eb12002-07-22 18:57:36 +0000710\item The \module{array} module now supports arrays of Unicode
711characters using the \samp{u} format character. Arrays also now
712support using the \code{+=} assignment operator to add another array's
713contents, and the \code{*=} assignment operator to repeat an array.
714(Contributed by Jason Orendorff.)
715
716\item The Distutils \class{Extension} class now supports
717an extra constructor argument named \samp{depends} for listing
718additional source files that an extension depends on. This lets
719Distutils recompile the module if any of the dependency files are
720modified. For example, if \samp{sampmodule.c} includes the header
721file \file{sample.h}, you would create the \class{Extension} object like
722this:
723
724\begin{verbatim}
725ext = Extension("samp",
726 sources=["sampmodule.c"],
727 depends=["sample.h"])
728\end{verbatim}
729
730Modifying \file{sample.h} would then cause the module to be recompiled.
731(Contributed by Jeremy Hylton.)
732
733\item Two new binary packagers were added to the Distutils.
734\code{bdist_pkgtool} builds \file{.pkg} files to use with Solaris
735\program{pkgtool}, and \code{bdist_sdux} builds \program{swinstall}
736packages for use on HP-UX.
737An abstract binary packager class,
738\module{distutils.command.bdist_packager}, was added; this may make it
739easier to write binary packaging commands. (Contributed by Mark
740Alexander.)
741
742\item The \module{getopt} module gained a new function,
743\function{gnu_getopt()}, that supports the same arguments as the existing
744\function{getopt()} function but uses GNU-style scanning mode.
745The existing \function{getopt()} stops processing options as soon as a
746non-option argument is encountered, but in GNU-style mode processing
747continues, meaning that options and arguments can be mixed. For
748example:
749
750\begin{verbatim}
751>>> getopt.getopt(['-f', 'filename', 'output', '-v'], 'f:v')
752([('-f', 'filename')], ['output', '-v'])
753>>> getopt.gnu_getopt(['-f', 'filename', 'output', '-v'], 'f:v')
754([('-f', 'filename'), ('-v', '')], ['output'])
755\end{verbatim}
756
757(Contributed by Peter \AA{strand}.)
758
759\item The \module{grp}, \module{pwd}, and \module{resource} modules
760now return enhanced tuples:
761
762\begin{verbatim}
763>>> import grp
764>>> g = grp.getgrnam('amk')
765>>> g.gr_name, g.gr_gid
766('amk', 500)
767\end{verbatim}
768
Andrew M. Kuchling950725f2002-08-06 01:40:48 +0000769\item The new \module{heapq} module contains an implementation of a
770heap queue algorithm. A heap is an array-like data structure that
771keeps items in a sorted order such that, for every index k, heap[k] <=
772heap[2*k+1] and heap[k] <= heap[2*k+2]. This makes it quick to remove
773the smallest item, and inserting a new item while maintaining the heap
774property is O(lg~n). (See
775\url{http://www.nist.gov/dads/HTML/priorityque.html} for more
776information about the priority queue data structure.)
777
778The Python \module{heapq} module provides \function{heappush()} and
779\function{heappop()} functions for adding and removing items while
780maintaining the heap property on top of some other mutable Python
781sequence type. For example:
782
783\begin{verbatim}
784>>> import heapq
785>>> heap = []
786>>> for item in [3, 7, 5, 11, 1]:
787... heapq.heappush(heap, item)
788...
789>>> heap
790[1, 3, 5, 11, 7]
791>>> heapq.heappop(heap)
7921
793>>> heapq.heappop(heap)
7943
795>>> heap
796[5, 7, 11]
797>>>
798>>> heapq.heappush(heap, 5)
799>>> heap = []
800>>> for item in [3, 7, 5, 11, 1]:
801... heapq.heappush(heap, item)
802...
803>>> heap
804[1, 3, 5, 11, 7]
805>>> heapq.heappop(heap)
8061
807>>> heapq.heappop(heap)
8083
809>>> heap
810[5, 7, 11]
811>>>
812\end{verbatim}
813
814(Contributed by Kevin O'Connor.)
Andrew M. Kuchlinga982eb12002-07-22 18:57:36 +0000815
816\item Two new functions in the \module{math} module,
817\function{degrees(\var{rads})} and \function{radians(\var{degs})},
818convert between radians and degrees. Other functions in the
819\module{math} module such as
820\function{math.sin()} and \function{math.cos()} have always required
821input values measured in radians. (Contributed by Raymond Hettinger.)
822
Andrew M. Kuchling52f1b762002-07-28 20:29:03 +0000823\item Four new functions, \function{getpgid()}, \function{killpg()}, \function{lchown()}, and \function{mknod()}, were added to the \module{posix} module that
Andrew M. Kuchlinga982eb12002-07-22 18:57:36 +0000824underlies the \module{os} module. (Contributed by Gustavo Niemeyer
825and Geert Jansen.)
826
827\item The parser objects provided by the \module{pyexpat} module
828can now optionally buffer character data, resulting in fewer calls to
829your character data handler and therefore faster performance. Setting
830the parser object's \member{buffer_text} attribute to \constant{True}
831will enable buffering.
832
833\item The \module{readline} module also gained a number of new
834functions: \function{get_history_item()},
835\function{get_current_history_length()}, and \function{redisplay()}.
836
837\item Support for more advanced POSIX signal handling was added
838to the \module{signal} module by adding the \function{sigpending},
839\function{sigprocmask} and \function{sigsuspend} functions, where supported
840by the platform. These functions make it possible to avoid some previously
841unavoidable race conditions.
842
843\item The \module{socket} module now supports timeouts. You
844can call the \method{settimeout(\var{t})} method on a socket object to
845set a timeout of \var{t} seconds. Subsequent socket operations that
846take longer than \var{t} seconds to complete will abort and raise a
847\exception{socket.error} exception.
848
849The original timeout implementation was by Tim O'Malley. Michael
850Gilfix integrated it into the Python \module{socket} module, after the
851patch had undergone a lengthy review. After it was checked in, Guido
852van~Rossum rewrote parts of it. This is a good example of the free
853software development process in action.
854
Andrew M. Kuchling20e5abc2002-07-11 20:50:34 +0000855\item The new \module{textwrap} module contains functions for wrapping
Andrew M. Kuchlingd003a2a2002-06-26 13:23:55 +0000856strings containing paragraphs of text. The \function{wrap(\var{text},
857\var{width})} function takes a string and returns a list containing
858the text split into lines of no more than the chosen width. The
859\function{fill(\var{text}, \var{width})} function returns a single
860string, reformatted to fit into lines no longer than the chosen width.
861(As you can guess, \function{fill()} is built on top of
862\function{wrap()}. For example:
863
864\begin{verbatim}
865>>> import textwrap
866>>> paragraph = "Not a whit, we defy augury: ... more text ..."
867>>> textwrap.wrap(paragraph, 60)
868["Not a whit, we defy augury: there's a special providence in",
869 "the fall of a sparrow. If it be now, 'tis not to come; if it",
870 ...]
871>>> print textwrap.fill(paragraph, 35)
872Not a whit, we defy augury: there's
873a special providence in the fall of
874a sparrow. If it be now, 'tis not
875to come; if it be not to come, it
876will be now; if it be not now, yet
877it will come: the readiness is all.
878>>>
879\end{verbatim}
880
881The module also contains a \class{TextWrapper} class that actually
882implements the text wrapping strategy. Both the
883\class{TextWrapper} class and the \function{wrap()} and
884\function{fill()} functions support a number of additional keyword
885arguments for fine-tuning the formatting; consult the module's
886documentation for details.
887% XXX add a link to the module docs?
888(Contributed by Greg Ward.)
889
Andrew M. Kuchlingef5d06b2002-07-22 19:21:06 +0000890\item The \module{time} module's \function{strptime()} function has
891long been an annoyance because it uses the platform C library's
892\function{strptime()} implementation, and different platforms
893sometimes have odd bugs. Brett Cannon contributed a portable
894implementation that's written in pure Python, which should behave
895identically on all platforms.
896
Andrew M. Kuchling20e5abc2002-07-11 20:50:34 +0000897\item The DOM implementation
898in \module{xml.dom.minidom} can now generate XML output in a
899particular encoding, by specifying an optional encoding argument to
900the \method{toxml()} and \method{toprettyxml()} methods of DOM nodes.
901
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000902\end{itemize}
903
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +0000904
Andrew M. Kuchlingef5d06b2002-07-22 19:21:06 +0000905%======================================================================
906\section{Specialized Object Allocator (pymalloc)\label{section-pymalloc}}
907
908An experimental feature added to Python 2.1 was a specialized object
909allocator called pymalloc, written by Vladimir Marangozov. Pymalloc
910was intended to be faster than the system \cfunction{malloc()} and have
911less memory overhead for typical allocation patterns of Python
912programs. The allocator uses C's \cfunction{malloc()} function to get
913large pools of memory, and then fulfills smaller memory requests from
914these pools.
915
916In 2.1 and 2.2, pymalloc was an experimental feature and wasn't
917enabled by default; you had to explicitly turn it on by providing the
918\longprogramopt{with-pymalloc} option to the \program{configure}
919script. In 2.3, pymalloc has had further enhancements and is now
920enabled by default; you'll have to supply
921\longprogramopt{without-pymalloc} to disable it.
922
923This change is transparent to code written in Python; however,
924pymalloc may expose bugs in C extensions. Authors of C extension
925modules should test their code with the object allocator enabled,
926because some incorrect code may cause core dumps at runtime. There
927are a bunch of memory allocation functions in Python's C API that have
928previously been just aliases for the C library's \cfunction{malloc()}
929and \cfunction{free()}, meaning that if you accidentally called
930mismatched functions, the error wouldn't be noticeable. When the
931object allocator is enabled, these functions aren't aliases of
932\cfunction{malloc()} and \cfunction{free()} any more, and calling the
933wrong function to free memory may get you a core dump. For example,
934if memory was allocated using \cfunction{PyObject_Malloc()}, it has to
935be freed using \cfunction{PyObject_Free()}, not \cfunction{free()}. A
936few modules included with Python fell afoul of this and had to be
937fixed; doubtless there are more third-party modules that will have the
938same problem.
939
940As part of this change, the confusing multiple interfaces for
941allocating memory have been consolidated down into two API families.
942Memory allocated with one family must not be manipulated with
943functions from the other family.
944
945There is another family of functions specifically for allocating
946Python \emph{objects} (as opposed to memory).
947
948\begin{itemize}
949 \item To allocate and free an undistinguished chunk of memory use
950 the ``raw memory'' family: \cfunction{PyMem_Malloc()},
951 \cfunction{PyMem_Realloc()}, and \cfunction{PyMem_Free()}.
952
953 \item The ``object memory'' family is the interface to the pymalloc
954 facility described above and is biased towards a large number of
955 ``small'' allocations: \cfunction{PyObject_Malloc},
956 \cfunction{PyObject_Realloc}, and \cfunction{PyObject_Free}.
957
958 \item To allocate and free Python objects, use the ``object'' family
959 \cfunction{PyObject_New()}, \cfunction{PyObject_NewVar()}, and
960 \cfunction{PyObject_Del()}.
961\end{itemize}
962
963Thanks to lots of work by Tim Peters, pymalloc in 2.3 also provides
964debugging features to catch memory overwrites and doubled frees in
965both extension modules and in the interpreter itself. To enable this
966support, turn on the Python interpreter's debugging code by running
967\program{configure} with \longprogramopt{with-pydebug}.
968
969To aid extension writers, a header file \file{Misc/pymemcompat.h} is
970distributed with the source to Python 2.3 that allows Python
971extensions to use the 2.3 interfaces to memory allocation and compile
972against any version of Python since 1.5.2. You would copy the file
973from Python's source distribution and bundle it with the source of
974your extension.
975
976\begin{seealso}
977
978\seeurl{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/dist/src/Objects/obmalloc.c}
979{For the full details of the pymalloc implementation, see
980the comments at the top of the file \file{Objects/obmalloc.c} in the
981Python source code. The above link points to the file within the
982SourceForge CVS browser.}
983
984\end{seealso}
985
986
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000987% ======================================================================
988\section{Build and C API Changes}
989
Andrew M. Kuchling3c305d92002-07-22 18:50:11 +0000990Changes to Python's build process and to the C API include:
Andrew M. Kuchling821013e2002-05-06 17:46:39 +0000991
992\begin{itemize}
993
Andrew M. Kuchlingef5d06b2002-07-22 19:21:06 +0000994\item The C-level interface to the garbage collector has been changed,
995to make it easier to write extension types that support garbage
996collection, and to make it easier to debug misuses of the functions.
997Various functions have slightly different semantics, so a bunch of
998functions had to be renamed. Extensions that use the old API will
999still compile but will \emph{not} participate in garbage collection,
1000so updating them for 2.3 should be considered fairly high priority.
1001
1002To upgrade an extension module to the new API, perform the following
1003steps:
1004
1005\begin{itemize}
1006
1007\item Rename \cfunction{Py_TPFLAGS_GC} to \cfunction{PyTPFLAGS_HAVE_GC}.
1008
1009\item Use \cfunction{PyObject_GC_New} or \cfunction{PyObject_GC_NewVar} to
1010allocate objects, and \cfunction{PyObject_GC_Del} to deallocate them.
1011
1012\item Rename \cfunction{PyObject_GC_Init} to \cfunction{PyObject_GC_Track} and
1013\cfunction{PyObject_GC_Fini} to \cfunction{PyObject_GC_UnTrack}.
1014
1015\item Remove \cfunction{PyGC_HEAD_SIZE} from object size calculations.
1016
1017\item Remove calls to \cfunction{PyObject_AS_GC} and \cfunction{PyObject_FROM_GC}.
1018
1019\end{itemize}
1020
Andrew M. Kuchling517109b2002-05-07 21:01:16 +00001021\item Python can now optionally be built as a shared library
1022(\file{libpython2.3.so}) by supplying \longprogramopt{enable-shared}
Andrew M. Kuchlingfad2f592002-05-10 21:00:05 +00001023when running Python's \file{configure} script. (Contributed by Ondrej
1024Palkovsky.)
Andrew M. Kuchlingf4dd65d2002-04-01 19:28:09 +00001025
Michael W. Hudsondd32a912002-08-15 14:59:02 +00001026\item The \csimplemacro{DL_EXPORT} and \csimplemacro{DL_IMPORT} macros
1027are now deprecated. Initialization functions for Python extension
1028modules should now be declared using the new macro
Andrew M. Kuchling3c305d92002-07-22 18:50:11 +00001029\csimplemacro{PyMODINIT_FUNC}, while the Python core will generally
1030use the \csimplemacro{PyAPI_FUNC} and \csimplemacro{PyAPI_DATA}
1031macros.
Neal Norwitzbba23a82002-07-22 13:18:59 +00001032
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +00001033\item The interpreter can be compiled without any docstrings for
1034the built-in functions and modules by supplying
Andrew M. Kuchling20e5abc2002-07-11 20:50:34 +00001035\longprogramopt{without-doc-strings} to the \file{configure} script.
Andrew M. Kuchlinge995d162002-07-11 20:09:50 +00001036This makes the Python executable about 10\% smaller, but will also
1037mean that you can't get help for Python's built-ins. (Contributed by
1038Gustavo Niemeyer.)
1039
Andrew M. Kuchling20e5abc2002-07-11 20:50:34 +00001040\item The cycle detection implementation used by the garbage collection
1041has proven to be stable, so it's now being made mandatory; you can no
1042longer compile Python without it, and the
1043\longprogramopt{with-cycle-gc} switch to \file{configure} has been removed.
1044
Andrew M. Kuchling517109b2002-05-07 21:01:16 +00001045\item The \cfunction{PyArg_NoArgs()} macro is now deprecated, and code
Andrew M. Kuchling7845e7c2002-07-11 19:27:46 +00001046that uses it should be changed. For Python 2.2 and later, the method
1047definition table can specify the
1048\constant{METH_NOARGS} flag, signalling that there are no arguments, and
1049the argument checking can then be removed. If compatibility with
1050pre-2.2 versions of Python is important, the code could use
1051\code{PyArg_ParseTuple(args, "")} instead, but this will be slower
1052than using \constant{METH_NOARGS}.
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +00001053
Andrew M. Kuchling517109b2002-05-07 21:01:16 +00001054\item A new function, \cfunction{PyObject_DelItemString(\var{mapping},
1055char *\var{key})} was added
1056as shorthand for
1057\code{PyObject_DelItem(\var{mapping}, PyString_New(\var{key})}.
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +00001058
Andrew M. Kuchling821013e2002-05-06 17:46:39 +00001059\item The source code for the Expat XML parser is now included with
1060the Python source, so the \module{pyexpat} module is no longer
1061dependent on having a system library containing Expat.
1062
Andrew M. Kuchling517109b2002-05-07 21:01:16 +00001063\item File objects now manage their internal string buffer
1064differently by increasing it exponentially when needed.
1065This results in the benchmark tests in \file{Lib/test/test_bufio.py}
1066speeding up from 57 seconds to 1.7 seconds, according to one
1067measurement.
1068
Andrew M. Kuchling72b58e02002-05-29 17:30:34 +00001069\item It's now possible to define class and static methods for a C
1070extension type by setting either the \constant{METH_CLASS} or
1071\constant{METH_STATIC} flags in a method's \ctype{PyMethodDef}
1072structure.
Andrew M. Kuchling45afd542002-04-02 14:25:25 +00001073
Andrew M. Kuchling346386f2002-07-12 20:24:42 +00001074\item Python now includes a copy of the Expat XML parser's source code,
1075removing any dependence on a system version or local installation of
1076Expat.
1077
Andrew M. Kuchling821013e2002-05-06 17:46:39 +00001078\end{itemize}
1079
1080\subsection{Port-Specific Changes}
1081
Andrew M. Kuchling187b1d82002-05-29 19:20:57 +00001082Support for a port to IBM's OS/2 using the EMX runtime environment was
1083merged into the main Python source tree. EMX is a POSIX emulation
1084layer over the OS/2 system APIs. The Python port for EMX tries to
1085support all the POSIX-like capability exposed by the EMX runtime, and
1086mostly succeeds; \function{fork()} and \function{fcntl()} are
1087restricted by the limitations of the underlying emulation layer. The
1088standard OS/2 port, which uses IBM's Visual Age compiler, also gained
1089support for case-sensitive import semantics as part of the integration
1090of the EMX port into CVS. (Contributed by Andrew MacIntyre.)
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +00001091
Andrew M. Kuchling72b58e02002-05-29 17:30:34 +00001092On MacOS, most toolbox modules have been weaklinked to improve
1093backward compatibility. This means that modules will no longer fail
1094to load if a single routine is missing on the curent OS version.
Andrew M. Kuchling187b1d82002-05-29 19:20:57 +00001095Instead calling the missing routine will raise an exception.
1096(Contributed by Jack Jansen.)
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +00001097
Andrew M. Kuchling187b1d82002-05-29 19:20:57 +00001098The RPM spec files, found in the \file{Misc/RPM/} directory in the
1099Python source distribution, were updated for 2.3. (Contributed by
1100Sean Reifschneider.)
Fred Drake03e10312002-03-26 19:17:43 +00001101
Andrew M. Kuchling20e5abc2002-07-11 20:50:34 +00001102Python now supports AtheOS (\url{www.atheos.cx}) and GNU/Hurd.
1103
Fred Drake03e10312002-03-26 19:17:43 +00001104
1105%======================================================================
Andrew M. Kuchling517109b2002-05-07 21:01:16 +00001106\section{Other Changes and Fixes}
1107
1108Finally, there are various miscellaneous fixes:
1109
1110\begin{itemize}
1111
1112\item The tools used to build the documentation now work under Cygwin
1113as well as \UNIX.
1114
Michael W. Hudsondd32a912002-08-15 14:59:02 +00001115\item The \code{SET_LINENO} opcode has been removed. Back in the
1116mists of time, this opcode was needed to produce line numbers in
1117tracebacks and support trace functions (for, e.g., \module{pdb}).
1118Since Python 1.5, the line numbers in tracebacks have been computed
1119using a different mechanism that works with ``python -O''. For Python
11202.3 Michael Hudson implemented a similar scheme to determine when to
1121call the trace function, removing the need for \code{SET_LINENO}
1122entirely.
1123
1124Python code will be hard pushed to notice a difference from this
1125change, apart from a slight speed up when python is run without
1126\programopt{-O}.
1127
1128C extensions that access the \member{f_lineno} field of frame objects
1129should instead call \code{PyCode_Addr2Line(f->f_code, f->f_lasti)}.
1130This will have the added effect of making the code work as desired
1131under ``python -O'' in earlier versions of Python.
1132
1133To make tracing work as expected, it was found necessary to add a new
1134opcode, \cdata{RETURN_NONE}, to the VM. If you want to know why, read
1135the comments in the function \cfunction{maybe_call_line_trace} in
1136\file{Python/ceval.c}.
1137
Andrew M. Kuchling517109b2002-05-07 21:01:16 +00001138\end{itemize}
1139
Andrew M. Kuchling187b1d82002-05-29 19:20:57 +00001140
Andrew M. Kuchling517109b2002-05-07 21:01:16 +00001141%======================================================================
Andrew M. Kuchling950725f2002-08-06 01:40:48 +00001142\section{Porting to Python 2.3}
1143
1144XXX write this
1145
1146
1147%======================================================================
Fred Drake03e10312002-03-26 19:17:43 +00001148\section{Acknowledgements \label{acks}}
1149
Andrew M. Kuchling03594bb2002-03-27 02:29:48 +00001150The author would like to thank the following people for offering
1151suggestions, corrections and assistance with various drafts of this
Andrew M. Kuchling7f147a72002-06-10 18:58:19 +00001152article: Michael Chermside, Scott David Daniels, Fred~L. Drake, Jr.,
Andrew M. Kuchling7845e7c2002-07-11 19:27:46 +00001153Michael Hudson, Detlef Lannert, Martin von L\"owis, Andrew MacIntyre,
Andrew M. Kuchling950725f2002-08-06 01:40:48 +00001154Gustavo Niemeyer, Neal Norwitz, Jason Tishler.
Fred Drake03e10312002-03-26 19:17:43 +00001155
1156\end{document}