blob: 2b5fb5043b210e22beb0a7b613e9ab29a9151d0c [file] [log] [blame]
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +00001\documentclass{howto}
2
3% $Id$
4
5\title{What's New in Python 2.2}
Andrew M. Kuchling2cd712b2001-07-16 13:39:08 +00006\release{0.02}
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +00007\author{A.M. Kuchling}
Andrew M. Kuchling7bf82772001-07-11 18:54:26 +00008\authoraddress{\email{akuchlin@mems-exchange.org}}
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +00009\begin{document}
10\maketitle\tableofcontents
11
12\section{Introduction}
13
14{\large This document is a draft, and is subject to change until the
15final version of Python 2.2 is released. Currently it's not up to
16date at all. Please send any comments, bug reports, or questions, no
Andrew M. Kuchling7bf82772001-07-11 18:54:26 +000017matter how minor, to \email{akuchlin@mems-exchange.org}. }
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +000018
Andrew M. Kuchling7bf82772001-07-11 18:54:26 +000019This article explains the new features in Python 2.2. Python 2.2
20includes some significant changes that go far toward cleaning up the
21language's darkest corners, and some exciting new features.
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +000022
23This article doesn't attempt to provide a complete specification for
24the new features, but instead provides a convenient overview of the
25new features. For full details, you should refer to 2.2 documentation
26such as the Library Reference and the Reference Guide, or to the PEP
27for a particular new feature.
28
29The final release of Python 2.2 is planned for October 2001.
30
31%======================================================================
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +000032% It looks like this set of changes will likely get into 2.2,
33% so I need to read and digest the relevant PEPs.
Andrew M. Kuchling7bf82772001-07-11 18:54:26 +000034%\section{PEP 252: Type and Class Changes}
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +000035
Andrew M. Kuchling7bf82772001-07-11 18:54:26 +000036%XXX
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +000037
Andrew M. Kuchling7bf82772001-07-11 18:54:26 +000038%\begin{seealso}
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +000039
Andrew M. Kuchling7bf82772001-07-11 18:54:26 +000040%\seepep{252}{Making Types Look More Like Classes}{Written and implemented
41%by GvR.}
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +000042
Andrew M. Kuchling7bf82772001-07-11 18:54:26 +000043%\end{seealso}
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +000044
45%======================================================================
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +000046\section{PEP 234: Iterators}
47
48A significant addition to 2.2 is an iteration interface at both the C
49and Python levels. Objects can define how they can be looped over by
50callers.
51
52In Python versions up to 2.1, the usual way to make \code{for item in
53obj} work is to define a \method{__getitem__()} method that looks
54something like this:
55
56\begin{verbatim}
57 def __getitem__(self, index):
58 return <next item>
59\end{verbatim}
60
61\method{__getitem__()} is more properly used to define an indexing
62operation on an object so that you can write \code{obj[5]} to retrieve
63the fifth element. It's a bit misleading when you're using this only
64to support \keyword{for} loops. Consider some file-like object that
65wants to be looped over; the \var{index} parameter is essentially
66meaningless, as the class probably assumes that a series of
67\method{__getitem__()} calls will be made, with \var{index}
68incrementing by one each time. In other words, the presence of the
69\method{__getitem__()} method doesn't mean that \code{file[5]} will
70work, though it really should.
71
72In Python 2.2, iteration can be implemented separately, and
73\method{__getitem__()} methods can be limited to classes that really
74do support random access. The basic idea of iterators is quite
75simple. A new built-in function, \function{iter(obj)}, returns an
76iterator for the object \var{obj}. (It can also take two arguments:
77\code{iter(\var{C}, \var{sentinel})} will call the callable \var{C}, until it
78returns \var{sentinel}, which will signal that the iterator is done. This form probably won't be used very often.)
79
80Python classes can define an \method{__iter__()} method, which should
81create and return a new iterator for the object; if the object is its
82own iterator, this method can just return \code{self}. In particular,
83iterators will usually be their own iterators. Extension types
84implemented in C can implement a \code{tp_iter} function in order to
Andrew M. Kuchling4cf52a92001-07-17 12:48:48 +000085return an iterator, and extension types that want to behave as
86iterators can define a \code{tp_iternext} function.
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +000087
88So what do iterators do? They have one required method,
89\method{next()}, which takes no arguments and returns the next value.
90When there are no more values to be returned, calling \method{next()}
91should raise the \exception{StopIteration} exception.
92
93\begin{verbatim}
94>>> L = [1,2,3]
95>>> i = iter(L)
96>>> print i
97<iterator object at 0x8116870>
98>>> i.next()
991
100>>> i.next()
1012
102>>> i.next()
1033
104>>> i.next()
105Traceback (most recent call last):
106 File "<stdin>", line 1, in ?
107StopIteration
108>>>
109\end{verbatim}
110
111In 2.2, Python's \keyword{for} statement no longer expects a sequence;
112it expects something for which \function{iter()} will return something.
113For backward compatibility, and convenience, an iterator is
114automatically constructed for sequences that don't implement
115\method{__iter__()} or a \code{tp_iter} slot, so \code{for i in
116[1,2,3]} will still work. Wherever the Python interpreter loops over
117a sequence, it's been changed to use the iterator protocol. This
118means you can do things like this:
119
120\begin{verbatim}
121>>> i = iter(L)
122>>> a,b,c = i
123>>> a,b,c
124(1, 2, 3)
125>>>
126\end{verbatim}
127
128Iterator support has been added to some of Python's basic types. The
129\keyword{in} operator now works on dictionaries, so \code{\var{key} in
130dict} is now equivalent to \code{dict.has_key(\var{key})}.
131Calling \function{iter()} on a dictionary will return an iterator which loops over their keys:
132
133\begin{verbatim}
134>>> m = {'Jan': 1, 'Feb': 2, 'Mar': 3, 'Apr': 4, 'May': 5, 'Jun': 6,
135... 'Jul': 7, 'Aug': 8, 'Sep': 9, 'Oct': 10, 'Nov': 11, 'Dec': 12}
136>>> for key in m: print key, m[key]
137...
138Mar 3
139Feb 2
140Aug 8
141Sep 9
142May 5
143Jun 6
144Jul 7
145Jan 1
146Apr 4
147Nov 11
148Dec 12
149Oct 10
150>>>
151\end{verbatim}
152
153That's just the default behaviour. If you want to iterate over keys,
154values, or key/value pairs, you can explicitly call the
155\method{iterkeys()}, \method{itervalues()}, or \method{iteritems()}
156methods to get an appropriate iterator.
157
158Files also provide an iterator, which calls its \method{readline()}
159method until there are no more lines in the file. This means you can
160now read each line of a file using code like this:
161
162\begin{verbatim}
163for line in file:
164 # do something for each line
165\end{verbatim}
166
167Note that you can only go forward in an iterator; there's no way to
168get the previous element, reset the iterator, or make a copy of it.
169An iterator object could provide such additional capabilities, but the iterator protocol only requires a \method{next()} method.
170
171\begin{seealso}
172
173\seepep{234}{Iterators}{Written by Ka-Ping Yee and GvR; implemented
174by the Python Labs crew, mostly by GvR and Tim Peters.}
175
176\end{seealso}
177
178%======================================================================
179\section{PEP 255: Simple Generators}
180
181Generators are another new feature, one that interacts with the
182introduction of iterators.
183
184You're doubtless familiar with how function calls work in Python or
185C. When you call a function, it gets a private area where its local
186variables are created. When the function reaches a \keyword{return}
187statement, the local variables are destroyed and the resulting value
188is returned to the caller. A later call to the same function will get
189a fresh new set of local variables. But, what if the local variables
190weren't destroyed on exiting a function? What if you could later
191resume the function where it left off? This is what generators
192provide; they can be thought of as resumable functions.
193
194Here's the simplest example of a generator function:
195
196\begin{verbatim}
197def generate_ints(N):
198 for i in range(N):
199 yield i
200\end{verbatim}
201
202A new keyword, \keyword{yield}, was introduced for generators. Any
203function containing a \keyword{yield} statement is a generator
204function; this is detected by Python's bytecode compiler which
Andrew M. Kuchling4cf52a92001-07-17 12:48:48 +0000205compiles the function specially. Because a new keyword was
206introduced, generators must be explicitly enabled in a module by
207including a \code{from __future__ import generators} statement near
208the top of the module's source code. In Python 2.3 this statement
209will become unnecessary.
210
211When you call a generator function, it doesn't return a single value;
212instead it returns a generator object that supports the iterator
213interface. On executing the \keyword{yield} statement, the generator
214outputs the value of \code{i}, similar to a \keyword{return}
215statement. The big difference between \keyword{yield} and a
216\keyword{return} statement is that, on reaching a \keyword{yield} the
217generator's state of execution is suspended and local variables are
218preserved. On the next call to the generator's \code{.next()} method,
219the function will resume executing immediately after the
220\keyword{yield} statement. (For complicated reasons, the
221\keyword{yield} statement isn't allowed inside the \keyword{try} block
222of a \code{try...finally} statement; read PEP 255 for a full
223explanation of the interaction between \keyword{yield} and
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +0000224exceptions.)
225
226Here's a sample usage of the \function{generate_ints} generator:
227
228\begin{verbatim}
229>>> gen = generate_ints(3)
230>>> gen
231<generator object at 0x8117f90>
232>>> gen.next()
2330
234>>> gen.next()
2351
236>>> gen.next()
2372
238>>> gen.next()
239Traceback (most recent call last):
240 File "<stdin>", line 1, in ?
241 File "<stdin>", line 2, in generate_ints
242StopIteration
243>>>
244\end{verbatim}
245
246You could equally write \code{for i in generate_ints(5)}, or
247\code{a,b,c = generate_ints(3)}.
248
249Inside a generator function, the \keyword{return} statement can only
Andrew M. Kuchling4cf52a92001-07-17 12:48:48 +0000250be used without a value, and signals the end of the procession of
251values; afterwards the generator cannot return any further values.
252\keyword{return} with a value, such as \code{return 5}, is a syntax
253error inside a generator function. The end of the generator's results
254can also be indicated by raising \exception{StopIteration} manually,
255or by just letting the flow of execution fall off the bottom of the
256function.
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +0000257
258You could achieve the effect of generators manually by writing your
Andrew M. Kuchling4cf52a92001-07-17 12:48:48 +0000259own class and storing all the local variables of the generator as
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +0000260instance variables. For example, returning a list of integers could
261be done by setting \code{self.count} to 0, and having the
262\method{next()} method increment \code{self.count} and return it.
263because it would be easy to write a Python class. However, for a
264moderately complicated generator, writing a corresponding class would
265be much messier. \file{Lib/test/test_generators.py} contains a number
266of more interesting examples. The simplest one implements an in-order
267traversal of a tree using generators recursively.
268
269\begin{verbatim}
270# A recursive generator that generates Tree leaves in in-order.
271def inorder(t):
272 if t:
273 for x in inorder(t.left):
274 yield x
275 yield t.label
276 for x in inorder(t.right):
277 yield x
278\end{verbatim}
279
280Two other examples in \file{Lib/test/test_generators.py} produce
281solutions for the N-Queens problem (placing $N$ queens on an $NxN$
282chess board so that no queen threatens another) and the Knight's Tour
283(a route that takes a knight to every square of an $NxN$ chessboard
284without visiting any square twice).
285
286The idea of generators comes from other programming languages,
287especially Icon (\url{http://www.cs.arizona.edu/icon/}), where the
288idea of generators is central to the language. In Icon, every
289expression and function call behaves like a generator. One example
290from ``An Overview of the Icon Programming Language'' at
291\url{http://www.cs.arizona.edu/icon/docs/ipd266.htm} gives an idea of
292what this looks like:
293
294\begin{verbatim}
295sentence := "Store it in the neighboring harbor"
296if (i := find("or", sentence)) > 5 then write(i)
297\end{verbatim}
298
299The \function{find()} function returns the indexes at which the
300substring ``or'' is found: 3, 23, 33. In the \keyword{if} statement,
301\code{i} is first assigned a value of 3, but 3 is less than 5, so the
302comparison fails, and Icon retries it with the second value of 23. 23
303is greater than 5, so the comparison now succeeds, and the code prints
304the value 23 to the screen.
305
306Python doesn't go nearly as far as Icon in adopting generators as a
307central concept. Generators are considered a new part of the core
308Python language, but learning or using them isn't compulsory; if they
309don't solve any problems that you have, feel free to ignore them.
310This is different from Icon where the idea of generators is a basic
311concept. One novel feature of Python's interface as compared to
312Icon's is that a generator's state is represented as a concrete object
313that can be passed around to other functions or stored in a data
314structure.
315
316\begin{seealso}
317
Andrew M. Kuchling4cf52a92001-07-17 12:48:48 +0000318\seepep{255}{Simple Generators}{Written by Neil Schemenauer, Tim
319Peters, Magnus Lie Hetland. Implemented mostly by Neil Schemenauer
320and Tim Peters, with other fixes from the Python Labs crew.}
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +0000321
322\end{seealso}
323
324%======================================================================
Andrew M. Kuchlinga43e7032001-06-27 20:32:12 +0000325\section{Unicode Changes}
326
Andrew M. Kuchling2cd712b2001-07-16 13:39:08 +0000327Python's Unicode support has been enhanced a bit in 2.2. Unicode
328strings are usually stored as UCS-2, as 16-bit unsigned integers.
329Python 2.2 can also be compiled to use UCS-4, 32-bit unsigned integers
Andrew M. Kuchlingddeb1352001-07-16 14:35:52 +0000330by supplying \longprogramopt{enable-unicode=ucs4} to the configure script.
Andrew M. Kuchling2cd712b2001-07-16 13:39:08 +0000331
332XXX explain surrogates? I have to figure out what the changes mean to users.
333
334Since their introduction, Unicode strings (XXX and regular strings in
3352.1?) have supported an \method{encode()} method to convert the
336string to a selected encoding such as UTF-8 or Latin-1. A symmetric
337\method{decode(\optional{\var{encoding}})} method has been added to
338both 8-bit and Unicode strings in 2.2, which assumes that the string
339is in the specified encoding and decodes it. This means that
340\method{encode()} and \method{decode()} can be called on both types of
341strings, and can be used for tasks not directly related to Unicode.
342For example, codecs have been added for UUencoding, MIME's base-64
343encoding, and compression with the \module{zlib} module.
344
345\begin{verbatim}
346>>> s = """Here is a lengthy piece of redundant, overly verbose,
347... and repetitive text.
348... """
349>>> data = s.encode('zlib')
350>>> data
351'x\x9c\r\xc9\xc1\r\x80 \x10\x04\xc0?Ul...'
352>>> data.decode('zlib')
353'Here is a lengthy piece of redundant, overly verbose,\nand repetitive text.\n'
354>>> print s.encode('uu')
355begin 666 <data>
356M2&5R92!I<R!A(&QE;F=T:'D@<&EE8V4@;V8@<F5D=6YD86YT+"!O=F5R;'D@
357>=F5R8F]S92P*86YD(')E<&5T:71I=F4@=&5X="X*
358
359end
360>>> "sheesh".encode('rot-13')
361'furrfu'
362\end{verbatim}
Andrew M. Kuchlinga43e7032001-06-27 20:32:12 +0000363
364References: http://mail.python.org/pipermail/i18n-sig/2001-June/001107.html
365and following thread.
366
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +0000367%======================================================================
368\section{PEP 227: Nested Scopes}
369
370In Python 2.1, statically nested scopes were added as an optional
371feature, to be enabled by a \code{from __future__ import
372nested_scopes} directive. In 2.2 nested scopes no longer need to be
373specially enabled, but are always enabled. The rest of this section
374is a copy of the description of nested scopes from my ``What's New in
375Python 2.1'' document; if you read it when 2.1 came out, you can skip
376the rest of this section.
377
378The largest change introduced in Python 2.1, and made complete in 2.2,
379is to Python's scoping rules. In Python 2.0, at any given time there
380are at most three namespaces used to look up variable names: local,
381module-level, and the built-in namespace. This often surprised people
382because it didn't match their intuitive expectations. For example, a
383nested recursive function definition doesn't work:
384
385\begin{verbatim}
386def f():
387 ...
388 def g(value):
389 ...
390 return g(value-1) + 1
391 ...
392\end{verbatim}
393
394The function \function{g()} will always raise a \exception{NameError}
395exception, because the binding of the name \samp{g} isn't in either
396its local namespace or in the module-level namespace. This isn't much
397of a problem in practice (how often do you recursively define interior
398functions like this?), but this also made using the \keyword{lambda}
399statement clumsier, and this was a problem in practice. In code which
400uses \keyword{lambda} you can often find local variables being copied
401by passing them as the default values of arguments.
402
403\begin{verbatim}
404def find(self, name):
405 "Return list of any entries equal to 'name'"
406 L = filter(lambda x, name=name: x == name,
407 self.list_attribute)
408 return L
409\end{verbatim}
410
411The readability of Python code written in a strongly functional style
412suffers greatly as a result.
413
414The most significant change to Python 2.2 is that static scoping has
415been added to the language to fix this problem. As a first effect,
416the \code{name=name} default argument is now unnecessary in the above
417example. Put simply, when a given variable name is not assigned a
418value within a function (by an assignment, or the \keyword{def},
419\keyword{class}, or \keyword{import} statements), references to the
420variable will be looked up in the local namespace of the enclosing
421scope. A more detailed explanation of the rules, and a dissection of
422the implementation, can be found in the PEP.
423
424This change may cause some compatibility problems for code where the
425same variable name is used both at the module level and as a local
426variable within a function that contains further function definitions.
427This seems rather unlikely though, since such code would have been
428pretty confusing to read in the first place.
429
430One side effect of the change is that the \code{from \var{module}
431import *} and \keyword{exec} statements have been made illegal inside
432a function scope under certain conditions. The Python reference
433manual has said all along that \code{from \var{module} import *} is
434only legal at the top level of a module, but the CPython interpreter
435has never enforced this before. As part of the implementation of
436nested scopes, the compiler which turns Python source into bytecodes
437has to generate different code to access variables in a containing
438scope. \code{from \var{module} import *} and \keyword{exec} make it
439impossible for the compiler to figure this out, because they add names
440to the local namespace that are unknowable at compile time.
441Therefore, if a function contains function definitions or
442\keyword{lambda} expressions with free variables, the compiler will
443flag this by raising a \exception{SyntaxError} exception.
444
445To make the preceding explanation a bit clearer, here's an example:
446
447\begin{verbatim}
448x = 1
449def f():
450 # The next line is a syntax error
451 exec 'x=2'
452 def g():
453 return x
454\end{verbatim}
455
456Line 4 containing the \keyword{exec} statement is a syntax error,
457since \keyword{exec} would define a new local variable named \samp{x}
458whose value should be accessed by \function{g()}.
459
460This shouldn't be much of a limitation, since \keyword{exec} is rarely
461used in most Python code (and when it is used, it's often a sign of a
462poor design anyway).
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +0000463%\end{seealso}
464
465\begin{seealso}
466
467\seepep{227}{Statically Nested Scopes}{Written and implemented by
468Jeremy Hylton.}
469
470\end{seealso}
471
Andrew M. Kuchlinga43e7032001-06-27 20:32:12 +0000472
473%======================================================================
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +0000474\section{New and Improved Modules}
475
476\begin{itemize}
477
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +0000478 \item The \module{xmlrpclib} module was contributed to the standard
479library by Fredrik Lundh. It provides support for writing XML-RPC
480clients; XML-RPC is a simple remote procedure call protocol built on
481top of HTTP and XML. For example, the following snippet retrieves a
482list of RSS channels from the O'Reilly Network, and then retrieves a
483list of the recent headlines for one channel:
484
485\begin{verbatim}
486import xmlrpclib
487s = xmlrpclib.Server(
488 'http://www.oreillynet.com/meerkat/xml-rpc/server.php')
489channels = s.meerkat.getChannels()
490# channels is a list of dictionaries, like this:
491# [{'id': 4, 'title': 'Freshmeat Daily News'}
492# {'id': 190, 'title': '32Bits Online'},
493# {'id': 4549, 'title': '3DGamers'}, ... ]
494
495# Get the items for one channel
496items = s.meerkat.getItems( {'channel': 4} )
497
498# 'items' is another list of dictionaries, like this:
499# [{'link': 'http://freshmeat.net/releases/52719/',
500# 'description': 'A utility which converts HTML to XSL FO.',
501# 'title': 'html2fo 0.3 (Default)'}, ... ]
502\end{verbatim}
503
504See \url{http://www.xmlrpc.com} for more information about XML-RPC.
505
506 \item The \module{socket} module can be compiled to support IPv6;
Andrew M. Kuchlingddeb1352001-07-16 14:35:52 +0000507 specify the \longprogramopt{enable-ipv6} option to Python's configure
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +0000508 script. (Contributed by Jun-ichiro ``itojun'' Hagino.)
509
510 \item Two new format characters were added to the \module{struct}
511 module for 64-bit integers on platforms that support the C
512 \ctype{long long} type. \samp{q} is for a signed 64-bit integer,
513 and \samp{Q} is for an unsigned one. The value is returned in
514 Python's long integer type. (Contributed by Tim Peters.)
515
516 \item In the interpreter's interactive mode, there's a new built-in
517 function \function{help()}, that uses the \module{pydoc} module
518 introduced in Python 2.1 to provide interactive.
519 \code{help(\var{object})} displays any available help text about
520 \var{object}. \code{help()} with no argument puts you in an online
521 help utility, where you can enter the names of functions, classes,
522 or modules to read their help text.
523 (Contributed by Guido van Rossum, using Ka-Ping Yee's \module{pydoc} module.)
524
525 \item Various bugfixes and performance improvements have been made
Andrew M. Kuchling4cf52a92001-07-17 12:48:48 +0000526 to the SRE engine underlying the \module{re} module. For example,
527 \function{re.sub()} will now use \function{string.replace()}
528 automatically when the pattern and its replacement are both just
529 literal strings without regex metacharacters. Another contributed
530 patch speeds up certain Unicode character ranges by a factor of
531 two. (SRE is maintained by Fredrik Lundh. The BIGCHARSET patch was
532 contributed by Martin von L\"owis.)
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +0000533
534 \item The \module{imaplib} module now has support for the IMAP
Andrew M. Kuchling4cf52a92001-07-17 12:48:48 +0000535 NAMESPACE extension defined in \rfc{2342}. (Contributed by Michel
536 Pelletier.)
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +0000537
Andrew M. Kuchling4cf52a92001-07-17 12:48:48 +0000538 \item The \module{rfc822} module's parsing of e-mail addresses is
539 now compliant with \rfc{2822}, an update to \rfc{822}. The module's
540 name is \emph{not} going to be changed to \samp{rfc2822}.
541 (Contributed by Barry Warsaw.)
542
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +0000543\end{itemize}
544
545
546%======================================================================
547\section{Other Changes and Fixes}
548
Andrew M. Kuchling4dbf8712001-07-16 02:17:14 +0000549As usual there were a bunch of other improvements and bugfixes
550scattered throughout the source tree. A search through the CVS change
551logs finds there were XXX patches applied, and XXX bugs fixed; both
552figures are likely to be underestimates. Some of the more notable
553changes are:
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +0000554
555\begin{itemize}
556
Andrew M. Kuchling2cd712b2001-07-16 13:39:08 +0000557 \item Keyword arguments passed to builtin functions that don't take them
558 now cause a \exception{TypeError} exception to be raised, with the
559 message "\var{function} takes no keyword arguments".
560
561 \item The code for the MacOS port for Python, maintained by Jack
562 Jansen, is now kept in the main Python CVS tree.
563
564 \item The new license introduced with Python 1.6 wasn't
565 GPL-compatible. This is fixed by some minor textual changes to the
566 2.2 license, so Python can now be embedded inside a GPLed program
567 again. The license changes were also applied to the Python 2.0.1
568 and 2.1.1 releases.
569
Andrew M. Kuchling4cf52a92001-07-17 12:48:48 +0000570 \item Profiling and tracing functions can now be implemented in C,
571 which can operate at much higher speeds than Python-based functions
572 and should reduce the overhead of enabling profiling and tracing, so
573 it will be of interest to authors of development environments for
574 Python. Two new C functions were added to Python's API,
575 \cfunction{PyEval_SetProfile()} and \cfunction{PyEval_SetTrace()}.
576 The existing \function{sys.setprofile()} and
577 \function{sys.settrace()} functions still exist, and have simply
578 been changed to use the new C-level interface.
Andrew M. Kuchling2cd712b2001-07-16 13:39:08 +0000579
580 \item The \file{Tools/scripts/ftpmirror.py} script
581 now parses a \file{.netrc} file, if you have one.
Andrew M. Kuchling4cf52a92001-07-17 12:48:48 +0000582 (Contributed by Mike Romberg.)
Andrew M. Kuchling2cd712b2001-07-16 13:39:08 +0000583
Andrew M. Kuchling4cf52a92001-07-17 12:48:48 +0000584 \item Some features of the object returned by the
585 \function{xrange()} function are now deprecated, and trigger
586 warnings when they're accessed; they'll disappear in Python 2.3.
587 \class{xrange} objects tried to pretend they were full sequence
588 types by supporting slicing, sequence multiplication, and the
589 \keyword{in} operator, but these features were rarely used and
590 therefore buggy. The \method{tolist()} method and the
591 \member{start}, \member{stop}, and \member{step} attributes are also
592 being deprecated. At the C level, the fourth argument to the
593 \cfunction{PyRange_New()} function, \samp{repeat}, has also been
594 deprecated.
595
596 \item On Windows, Python can now be compiled with Borland C thanks
597 to a number of patches contribued by Stephen Hansen.
Andrew M. Kuchling2cd712b2001-07-16 13:39:08 +0000598
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +0000599 \item XXX C API: Reorganization of object calling
600
Andrew M. Kuchling2cd712b2001-07-16 13:39:08 +0000601The call_object()
602function, originally in ceval.c, begins a new life as the official
603API PyObject_Call(). It is also much simplified: all it does is call
604the tp_call slot, or raise an exception if that's NULL.
Andrew M. Kuchling3b923fc2001-05-19 19:35:46 +0000605
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +0000606%The subsidiary functions (call_eval_code2(), call_cfunction(),
607%call_instance(), and call_method()) have all been moved to the file
608%implementing their particular object type, renamed according to the
609%local convention, and added to the type's tp_call slot. Note that
610%call_eval_code2() became function_call(); the tp_slot for class
611%objects now simply points to PyInstance_New(), which already has the
612%correct signature.
613
614%Because of these moves, there are some more new APIs that expose
615%helpers in ceval.c that are now needed outside: PyEval_GetFuncName(),
616%PyEval_GetFuncDesc(), PyEval_EvalCodeEx() (formerly get_func_name(),
617%get_func_desc(), and eval_code2().
618
Andrew M. Kuchling4cf52a92001-07-17 12:48:48 +0000619 \item XXX Add support for Windows using "mbcs" as the default
620 Unicode encoding when dealing with the file system. As discussed on
621 python-dev and in patch 410465.
Andrew M. Kuchling2cd712b2001-07-16 13:39:08 +0000622
623 \item XXX Lots of patches to dictionaries; measure performance improvement, if any.
624
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +0000625\end{itemize}
626
627
628
629%======================================================================
630\section{Acknowledgements}
631
632The author would like to thank the following people for offering
Andrew M. Kuchling4cf52a92001-07-17 12:48:48 +0000633suggestions on various drafts of this article: Tim Peters, Neil Schemenauer.
Andrew M. Kuchlinga8defaa2001-05-05 16:37:29 +0000634
635\end{document}