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