Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 1 | \documentclass{howto} |
| 2 | \usepackage{distutils} |
| 3 | % $Id$ |
| 4 | |
Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 5 | |
| 6 | \title{What's New in Python 2.5} |
| 7 | \release{0.0} |
Andrew M. Kuchling | 92e2495 | 2004-12-03 13:54:09 +0000 | [diff] [blame] | 8 | \author{A.M. Kuchling} |
| 9 | \authoraddress{\email{amk@amk.ca}} |
Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 10 | |
| 11 | \begin{document} |
| 12 | \maketitle |
| 13 | \tableofcontents |
| 14 | |
| 15 | This article explains the new features in Python 2.5. No release date |
Andrew M. Kuchling | 92e2495 | 2004-12-03 13:54:09 +0000 | [diff] [blame] | 16 | for Python 2.5 has been set; it will probably be released in late 2005. |
Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 17 | |
| 18 | % Compare with previous release in 2 - 3 sentences here. |
| 19 | |
| 20 | This article doesn't attempt to provide a complete specification of |
| 21 | the new features, but instead provides a convenient overview. For |
| 22 | full details, you should refer to the documentation for Python 2.5. |
| 23 | % add hyperlink when the documentation becomes available online. |
| 24 | If you want to understand the complete implementation and design |
| 25 | rationale, refer to the PEP for a particular new feature. |
| 26 | |
| 27 | |
| 28 | %====================================================================== |
Andrew M. Kuchling | 3e41b05 | 2005-03-01 00:53:46 +0000 | [diff] [blame] | 29 | \section{PEP 309: Partial Function Application} |
Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 30 | |
Andrew M. Kuchling | b1c96fd | 2005-03-20 21:42:04 +0000 | [diff] [blame] | 31 | For programs written in a functional style, it can be useful to |
| 32 | construct variants of existing functions that have some of the |
| 33 | parameters filled in. This is called ``partial function application''. |
| 34 | The new \module{functional} module contains a \class{partial} class |
| 35 | that provides partial application. |
| 36 | |
| 37 | The \module{functional} module is intended to contain tools for |
| 38 | functional-style programming. Currently it only contains |
| 39 | \class{partial}, but new functions will probably be added in future |
| 40 | versions of Python. |
| 41 | |
| 42 | % XXX write rest of this |
| 43 | % XXX add example from my GTk programming |
| 44 | |
| 45 | |
| 46 | \begin{seealso} |
| 47 | |
| 48 | \seepep{309}{Partial Function Application}{PEP proposed and written by |
| 49 | Peter Harris; implemented by Hye-Shik Chang, with adaptations by |
| 50 | Raymond Hettinger.} |
| 51 | |
| 52 | \end{seealso} |
Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 53 | |
| 54 | |
| 55 | %====================================================================== |
Fred Drake | db7b002 | 2005-03-20 22:19:47 +0000 | [diff] [blame^] | 56 | \section{PEP 314: Metadata for Python Software Packages v1.1} |
| 57 | |
| 58 | XXX describe this PEP. |
| 59 | distutils \function{setup()} now supports the \var{provides}, |
| 60 | \var{requires}, \var{obsoletes} keywords. |
| 61 | |
| 62 | |
| 63 | %====================================================================== |
Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 64 | \section{Other Language Changes} |
| 65 | |
| 66 | Here are all of the changes that Python 2.5 makes to the core Python |
| 67 | language. |
| 68 | |
| 69 | \begin{itemize} |
Andrew M. Kuchling | 1cae3f5 | 2004-12-03 14:57:21 +0000 | [diff] [blame] | 70 | |
| 71 | \item The \function{min()} and \function{max()} built-in functions |
| 72 | gained a \code{key} keyword argument analogous to the \code{key} |
Andrew M. Kuchling | e9b1bf4 | 2005-03-20 19:26:30 +0000 | [diff] [blame] | 73 | argument for \method{sort()}. This argument supplies a function |
Andrew M. Kuchling | 1cae3f5 | 2004-12-03 14:57:21 +0000 | [diff] [blame] | 74 | that takes a single argument and is called for every value in the list; |
| 75 | \function{min()}/\function{max()} will return the element with the |
| 76 | smallest/largest return value from this function. |
| 77 | For example, to find the longest string in a list, you can do: |
| 78 | |
| 79 | \begin{verbatim} |
| 80 | L = ['medium', 'longest', 'short'] |
| 81 | # Prints 'longest' |
| 82 | print max(L, key=len) |
| 83 | # Prints 'short', because lexicographically 'short' has the largest value |
| 84 | print max(L) |
| 85 | \end{verbatim} |
| 86 | |
| 87 | (Contributed by Steven Bethard and Raymond Hettinger.) |
Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 88 | |
Andrew M. Kuchling | e9b1bf4 | 2005-03-20 19:26:30 +0000 | [diff] [blame] | 89 | \item The list of base classes in a class definition can now be empty. |
| 90 | As an example, this is now legal: |
| 91 | |
| 92 | \begin{verbatim} |
| 93 | class C(): |
| 94 | pass |
| 95 | \end{verbatim} |
| 96 | (Implemented by Brett Cannon.) |
| 97 | |
Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 98 | \end{itemize} |
| 99 | |
| 100 | |
| 101 | %====================================================================== |
| 102 | \subsection{Optimizations} |
| 103 | |
| 104 | \begin{itemize} |
| 105 | |
| 106 | \item Optimizations should be described here. |
| 107 | |
| 108 | \end{itemize} |
| 109 | |
| 110 | The net result of the 2.5 optimizations is that Python 2.5 runs the |
Andrew M. Kuchling | 92e2495 | 2004-12-03 13:54:09 +0000 | [diff] [blame] | 111 | pystone benchmark around XX\% faster than Python 2.4. |
Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 112 | |
| 113 | |
| 114 | %====================================================================== |
| 115 | \section{New, Improved, and Deprecated Modules} |
| 116 | |
| 117 | As usual, Python's standard library received a number of enhancements and |
| 118 | bug fixes. Here's a partial list of the most notable changes, sorted |
| 119 | alphabetically by module name. Consult the |
| 120 | \file{Misc/NEWS} file in the source tree for a more |
| 121 | complete list of changes, or look through the CVS logs for all the |
| 122 | details. |
| 123 | |
| 124 | \begin{itemize} |
| 125 | |
Andrew M. Kuchling | 3e41b05 | 2005-03-01 00:53:46 +0000 | [diff] [blame] | 126 | % the cPickle module no longer accepts the deprecated None option in the |
| 127 | % args tuple returned by __reduce__(). |
| 128 | |
| 129 | % csv module improvements |
| 130 | |
| 131 | % datetime.datetime() now has a strptime class method which can be used to |
| 132 | % create datetime object using a string and format. |
| 133 | |
Andrew M. Kuchling | e9b1bf4 | 2005-03-20 19:26:30 +0000 | [diff] [blame] | 134 | \item The \function{nsmallest()} and |
| 135 | \function{nlargest()} functions in the \module{heapq} module |
| 136 | now support a \code{key} keyword argument similar to the one |
| 137 | provided by the \function{min()}/\function{max()} functions |
| 138 | and the \method{sort()} methods. For example: |
| 139 | Example: |
| 140 | |
| 141 | \begin{verbatim} |
| 142 | >>> import heapq |
| 143 | >>> L = ["short", 'medium', 'longest', 'longer still'] |
| 144 | >>> heapq.nsmallest(2, L) # Return two lowest elements, lexicographically |
| 145 | ['longer still', 'longest'] |
| 146 | >>> heapq.nsmallest(2, L, key=len) # Return two shortest elements |
| 147 | ['short', 'medium'] |
| 148 | \end{verbatim} |
| 149 | |
| 150 | (Contributed by Raymond Hettinger.) |
| 151 | |
Andrew M. Kuchling | 511a3a8 | 2005-03-20 19:52:18 +0000 | [diff] [blame] | 152 | \item The \function{itertools.islice()} function now accepts |
| 153 | \code{None} for the start and step arguments. This makes it more |
| 154 | compatible with the attributes of slice objects, so that you can now write |
| 155 | the following: |
| 156 | |
| 157 | \begin{verbatim} |
| 158 | s = slice(5) # Create slice object |
| 159 | itertools.islice(iterable, s.start, s.stop, s.step) |
| 160 | \end{verbatim} |
| 161 | |
| 162 | (Contributed by Raymond Hettinger.) |
Andrew M. Kuchling | 3e41b05 | 2005-03-01 00:53:46 +0000 | [diff] [blame] | 163 | |
| 164 | \item New module: \module{spwd} provides functions for accessing the |
| 165 | shadow password database on systems that support it. |
| 166 | % XXX give example |
| 167 | |
Andrew M. Kuchling | e9b1bf4 | 2005-03-20 19:26:30 +0000 | [diff] [blame] | 168 | \item The \module{os} module underwent a number of changes. The |
| 169 | \member{stat_float_times} variable now defaults to true, meaning that |
| 170 | \function{os.stat()} will now return time values as floats. (This |
| 171 | doesn't necessarily mean that \function{os.stat()} will return times |
| 172 | that are precise to fractions of a second; not all systems support |
| 173 | such precision.) |
Andrew M. Kuchling | 3e41b05 | 2005-03-01 00:53:46 +0000 | [diff] [blame] | 174 | |
Andrew M. Kuchling | e9b1bf4 | 2005-03-20 19:26:30 +0000 | [diff] [blame] | 175 | Also, constants named \member{os.SEEK_SET}, \member{os.SEEK_CUR}, and |
| 176 | \member{os.SEEK_END} have been added; these are the parameters to the |
| 177 | \function{os.lseek()} function. |
Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 178 | |
Andrew M. Kuchling | e9b1bf4 | 2005-03-20 19:26:30 +0000 | [diff] [blame] | 179 | \item The \class{TarFile} class in the \module{tarfile} module now has |
| 180 | a \method{extractall()} method that extracts all members from the |
| 181 | archive into the current working directory. It's also possible to set |
| 182 | a different directory as the extraction target, and to unpack only a |
| 183 | subset of the archive's members. (Contributed by Lars Gust\"abel.) |
| 184 | |
| 185 | |
Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 186 | |
| 187 | |
| 188 | %====================================================================== |
| 189 | % whole new modules get described in \subsections here |
| 190 | |
| 191 | |
| 192 | % ====================================================================== |
| 193 | \section{Build and C API Changes} |
| 194 | |
| 195 | Changes to Python's build process and to the C API include: |
| 196 | |
| 197 | \begin{itemize} |
| 198 | |
Andrew M. Kuchling | 2238fc6 | 2004-12-03 15:16:40 +0000 | [diff] [blame] | 199 | \item The \cfunction{PyRange_New()} function was removed. It was never documented, |
| 200 | never used in the core code, and had dangerously lax error checking. |
Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 201 | |
| 202 | \end{itemize} |
| 203 | |
| 204 | |
| 205 | %====================================================================== |
| 206 | \subsection{Port-Specific Changes} |
| 207 | |
| 208 | Platform-specific changes go here. |
| 209 | |
| 210 | |
| 211 | %====================================================================== |
| 212 | \section{Other Changes and Fixes \label{section-other}} |
| 213 | |
| 214 | As usual, there were a bunch of other improvements and bugfixes |
| 215 | scattered throughout the source tree. A search through the CVS change |
| 216 | logs finds there were XXX patches applied and YYY bugs fixed between |
Andrew M. Kuchling | 92e2495 | 2004-12-03 13:54:09 +0000 | [diff] [blame] | 217 | Python 2.4 and 2.5. Both figures are likely to be underestimates. |
Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 218 | |
| 219 | Some of the more notable changes are: |
| 220 | |
| 221 | \begin{itemize} |
| 222 | |
| 223 | \item Details go here. |
| 224 | |
| 225 | \end{itemize} |
| 226 | |
| 227 | |
| 228 | %====================================================================== |
| 229 | \section{Porting to Python 2.5} |
| 230 | |
| 231 | This section lists previously described changes that may require |
| 232 | changes to your code: |
| 233 | |
| 234 | \begin{itemize} |
| 235 | |
Andrew M. Kuchling | 3e41b05 | 2005-03-01 00:53:46 +0000 | [diff] [blame] | 236 | \item Some old deprecated modules (\module{statcache}, \module{tzparse}, |
| 237 | \module{whrandom}) have been moved to \file{Lib/lib-old}. |
Andrew M. Kuchling | 0c35db9 | 2005-03-20 20:06:49 +0000 | [diff] [blame] | 238 | You can get access to these modules again by adding the directory |
| 239 | to your \code{sys.path}: |
| 240 | |
| 241 | \begin{verbatim} |
| 242 | import os |
| 243 | from distutils import sysconfig |
| 244 | |
| 245 | lib_dir = sysconfig.get_python_lib(standard_lib=True) |
| 246 | old_dir = os.path.join(lib_dir, 'lib-old') |
| 247 | sys.path.append(old_dir) |
| 248 | \end{verbatim} |
| 249 | |
| 250 | Doing so is discouraged, however; it's better to update any code that |
| 251 | still uses these modules. |
Andrew M. Kuchling | 3e41b05 | 2005-03-01 00:53:46 +0000 | [diff] [blame] | 252 | |
| 253 | % the pickle module no longer uses the deprecated bin parameter. |
Fred Drake | 2db7680 | 2004-12-01 05:05:47 +0000 | [diff] [blame] | 254 | |
| 255 | \end{itemize} |
| 256 | |
| 257 | |
| 258 | %====================================================================== |
| 259 | \section{Acknowledgements \label{acks}} |
| 260 | |
| 261 | The author would like to thank the following people for offering |
| 262 | suggestions, corrections and assistance with various drafts of this |
| 263 | article: . |
| 264 | |
| 265 | \end{document} |