Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 1 | \documentclass{howto} |
| 2 | |
| 3 | % $Id$ |
| 4 | |
| 5 | \title{What's New in Python 2.1} |
Andrew M. Kuchling | 81b6ae7 | 2001-02-11 16:55:39 +0000 | [diff] [blame] | 6 | \release{0.06} |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 7 | \author{A.M. Kuchling} |
| 8 | \authoraddress{\email{amk1@bigfoot.com}} |
| 9 | \begin{document} |
| 10 | \maketitle\tableofcontents |
| 11 | |
| 12 | \section{Introduction} |
| 13 | |
Andrew M. Kuchling | f33c118 | 2001-01-23 02:48:26 +0000 | [diff] [blame] | 14 | {\large This document is a draft, and is subject to change until |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 15 | the final version of Python 2.1 is released. Currently it is up to date |
Andrew M. Kuchling | 74d18ed | 2001-02-28 22:22:40 +0000 | [diff] [blame] | 16 | for Python 2.1 beta 1. Please send any comments, bug reports, or |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 17 | questions, no matter how minor, to \email{amk1@bigfoot.com}. } |
Andrew M. Kuchling | f33c118 | 2001-01-23 02:48:26 +0000 | [diff] [blame] | 18 | |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 19 | It's that time again... time for a new Python release, version 2.1. |
| 20 | One recent goal of the Python development team has been to accelerate |
| 21 | the pace of new releases, with a new release coming every 6 to 9 |
| 22 | months. 2.1 is the first release to come out at this faster pace, with |
| 23 | the first alpha appearing in January, 3 months after the final version |
| 24 | of 2.0 was released. |
| 25 | |
| 26 | This article explains the new features in 2.1. While there aren't as |
| 27 | many changes in 2.1 as there were in Python 2.0, there are still some |
| 28 | pleasant surprises in store. 2.1 is the first release to be steered |
| 29 | through the use of Python Enhancement Proposals, or PEPs, so most of |
| 30 | the sizable changes have accompanying PEPs that provide more complete |
| 31 | documentation and a design rationale for the change. This article |
| 32 | doesn't attempt to document the new features completely, but simply |
| 33 | provides an overview of the new features for Python programmers. |
| 34 | Refer to the Python 2.1 documentation, or to the specific PEP, for |
| 35 | more details about any new feature that particularly interests you. |
| 36 | |
Andrew M. Kuchling | 8bad993 | 2001-02-28 22:39:15 +0000 | [diff] [blame] | 37 | Currently 2.1 is available in a beta release, and the final release is |
| 38 | planned for April 2001. |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 39 | |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 40 | %====================================================================== |
| 41 | \section{PEP 227: Nested Scopes} |
| 42 | |
| 43 | The largest change in Python 2.1 is to Python's scoping rules. In |
| 44 | Python 2.0, at any given time there are at most three namespaces used |
| 45 | to look up variable names: local, module-level, and the built-in |
| 46 | namespace. This often surprised people because it didn't match their |
| 47 | intuitive expectations. For example, a nested recursive function |
| 48 | definition doesn't work: |
| 49 | |
| 50 | \begin{verbatim} |
| 51 | def f(): |
| 52 | ... |
| 53 | def g(value): |
| 54 | ... |
| 55 | return g(value-1) + 1 |
| 56 | ... |
| 57 | \end{verbatim} |
| 58 | |
| 59 | The function \function{g()} will always raise a \exception{NameError} |
| 60 | exception, because the binding of the name \samp{g} isn't in either |
| 61 | its local namespace or in the module-level namespace. This isn't much |
| 62 | of a problem in practice (how often do you recursively define interior |
| 63 | functions like this?), but this also made using the \keyword{lambda} |
| 64 | statement clumsier, and this was a problem in practice. In code which |
| 65 | uses \keyword{lambda} you can often find local variables being copied |
| 66 | by passing them as the default values of arguments. |
| 67 | |
| 68 | \begin{verbatim} |
| 69 | def find(self, name): |
| 70 | "Return list of any entries equal to 'name'" |
| 71 | L = filter(lambda x, name=name: x == name, |
| 72 | self.list_attribute) |
| 73 | return L |
| 74 | \end{verbatim} |
| 75 | |
| 76 | The readability of Python code written in a strongly functional style |
| 77 | suffers greatly as a result. |
| 78 | |
| 79 | The most significant change to Python 2.1 is that static scoping has |
| 80 | been added to the language to fix this problem. As a first effect, |
| 81 | the \code{name=name} default argument is now unnecessary in the above |
| 82 | example. Put simply, when a given variable name is not assigned a |
| 83 | value within a function (by an assignment, or the \keyword{def}, |
| 84 | \keyword{class}, or \keyword{import} statements), references to the |
| 85 | variable will be looked up in the local namespace of the enclosing |
| 86 | scope. A more detailed explanation of the rules, and a dissection of |
| 87 | the implementation, can be found in the PEP. |
| 88 | |
| 89 | This change may cause some compatibility problems for code where the |
| 90 | same variable name is used both at the module level and as a local |
| 91 | variable within a function that contains further function definitions. |
| 92 | This seems rather unlikely though, since such code would have been |
Andrew M. Kuchling | 61af560 | 2001-03-03 03:25:04 +0000 | [diff] [blame] | 93 | pretty confusing to read in the first place. |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 94 | |
Andrew M. Kuchling | 15ad28c | 2001-02-14 02:44:18 +0000 | [diff] [blame] | 95 | One side effect of the change is that the \code{from \var{module} |
| 96 | import *} and \keyword{exec} statements have been made illegal inside |
| 97 | a function scope under certain conditions. The Python reference |
| 98 | manual has said all along that \code{from \var{module} import *} is |
| 99 | only legal at the top level of a module, but the CPython interpreter |
| 100 | has never enforced this before. As part of the implementation of |
| 101 | nested scopes, the compiler which turns Python source into bytecodes |
| 102 | has to generate different code to access variables in a containing |
| 103 | scope. \code{from \var{module} import *} and \keyword{exec} make it |
| 104 | impossible for the compiler to figure this out, because they add names |
| 105 | to the local namespace that are unknowable at compile time. |
| 106 | Therefore, if a function contains function definitions or |
| 107 | \keyword{lambda} expressions with free variables, the compiler will |
| 108 | flag this by raising a \exception{SyntaxError} exception. |
| 109 | |
| 110 | To make the preceding explanation a bit clearer, here's an example: |
| 111 | |
| 112 | \begin{verbatim} |
| 113 | x = 1 |
| 114 | def f(): |
| 115 | # The next line is a syntax error |
| 116 | exec 'x=2' |
| 117 | def g(): |
| 118 | return x |
| 119 | \end{verbatim} |
| 120 | |
| 121 | Line 4 containing the \keyword{exec} statement is a syntax error, |
| 122 | since \keyword{exec} would define a new local variable named \samp{x} |
| 123 | whose value should be accessed by \function{g()}. |
| 124 | |
| 125 | This shouldn't be much of a limitation, since \keyword{exec} is rarely |
| 126 | used in most Python code (and when it is used, it's often a sign of a |
| 127 | poor design anyway). |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 128 | |
Andrew M. Kuchling | 61af560 | 2001-03-03 03:25:04 +0000 | [diff] [blame] | 129 | Compatibility concerns have led to nested scopes being introduced |
| 130 | gradually; in Python 2.1, they aren't enabled by default, but can be |
| 131 | turned on within a module by using a future statement as described in |
| 132 | PEP 236. (See the following section for further discussion of PEP |
| 133 | 236.) In Python 2.2, nested scopes will become the default and there |
| 134 | will be no way to turn them off, but users will have had all of 2.1's |
| 135 | lifetime to fix any breakage resulting from their introduction. |
| 136 | |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 137 | \begin{seealso} |
| 138 | |
| 139 | \seepep{227}{Statically Nested Scopes}{Written and implemented by |
| 140 | Jeremy Hylton.} |
| 141 | |
| 142 | \end{seealso} |
| 143 | |
| 144 | |
| 145 | %====================================================================== |
Andrew M. Kuchling | 74d18ed | 2001-02-28 22:22:40 +0000 | [diff] [blame] | 146 | \section{PEP 236: \module{__future__} Directives} |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 147 | |
Andrew M. Kuchling | 61af560 | 2001-03-03 03:25:04 +0000 | [diff] [blame] | 148 | The reaction to nested scopes was widespread concern about the dangers |
| 149 | of breaking code with the 2.1 release, and it was strong enough to |
| 150 | make the Pythoneers take a more conservative approach. This approach |
| 151 | consists of introducing a convention for enabling optional |
| 152 | functionality in release N that will become compulsory in release N+1. |
| 153 | |
| 154 | The syntax uses a \code{from...import} statement using the reserved |
| 155 | module name \module{__future__}. Nested scopes can be enabled by the |
| 156 | following statement: |
| 157 | |
| 158 | \begin{verbatim} |
| 159 | from __future__ import nested_scopes |
| 160 | \end{verbatim} |
| 161 | |
| 162 | While it looks like a normal \keyword{import} statement, it's not; |
| 163 | there are strict rules on where such a future statement can be put. |
| 164 | They can only be at the top of a module, and must precede any Python |
| 165 | code or regular \keyword{import} statements. This is because such |
| 166 | statements can affect how the Python bytecode compiler parses code and |
| 167 | generates bytecode, so they must precede any statement that will |
| 168 | result in bytecodes being produced. |
| 169 | |
| 170 | \begin{seealso} |
| 171 | |
| 172 | \seepep{236}{Back to the \module{__future__}}{Written by Tim Peters, |
| 173 | and primarily implemented by Jeremy Hylton.} |
| 174 | |
| 175 | \end{seealso} |
Andrew M. Kuchling | f228fd1 | 2001-01-22 17:52:19 +0000 | [diff] [blame] | 176 | |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 177 | %====================================================================== |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 178 | \section{PEP 207: Rich Comparisons} |
| 179 | |
Andrew M. Kuchling | b216ab6 | 2001-01-22 16:15:44 +0000 | [diff] [blame] | 180 | In earlier versions, Python's support for implementing comparisons on |
| 181 | user-defined classes and extension types was quite simple. Classes |
| 182 | could implement a \method{__cmp__} method that was given two instances |
| 183 | of a class, and could only return 0 if they were equal or +1 or -1 if |
| 184 | they weren't; the method couldn't raise an exception or return |
| 185 | anything other than a Boolean value. Users of Numeric Python often |
| 186 | found this model too weak and restrictive, because in the |
| 187 | number-crunching programs that numeric Python is used for, it would be |
| 188 | more useful to be able to perform elementwise comparisons of two |
| 189 | matrices, returning a matrix containing the results of a given |
| 190 | comparison for each element. If the two matrices are of different |
| 191 | sizes, then the compare has to be able to raise an exception to signal |
| 192 | the error. |
| 193 | |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 194 | In Python 2.1, rich comparisons were added in order to support this |
| 195 | need. Python classes can now individually overload each of the |
| 196 | \code{<}, \code{<=}, \code{>}, \code{>=}, \code{==}, and \code{!=} |
| 197 | operations. The new magic method names are: |
Andrew M. Kuchling | b216ab6 | 2001-01-22 16:15:44 +0000 | [diff] [blame] | 198 | |
| 199 | \begin{tableii}{c|l}{code}{Operation}{Method name} |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 200 | \lineii{<}{\method{__lt__}} \lineii{<=}{\method{__le__}} |
| 201 | \lineii{>}{\method{__gt__}} \lineii{>=}{\method{__ge__}} |
| 202 | \lineii{==}{\method{__eq__}} \lineii{!=}{\method{__ne__}} |
| 203 | \end{tableii} |
Andrew M. Kuchling | b216ab6 | 2001-01-22 16:15:44 +0000 | [diff] [blame] | 204 | |
| 205 | (The magic methods are named after the corresponding Fortran operators |
| 206 | \code{.LT.}. \code{.LE.}, \&c. Numeric programmers are almost |
| 207 | certainly quite familar with these names and will find them easy to |
| 208 | remember.) |
| 209 | |
| 210 | Each of these magic methods is of the form \code{\var{method}(self, |
| 211 | other)}, where \code{self} will be the object on the left-hand side of |
| 212 | the operator, while \code{other} will be the object on the right-hand |
| 213 | side. For example, the expression \code{A < B} will cause |
| 214 | \code{A.__lt__(B)} to be called. |
| 215 | |
| 216 | Each of these magic methods can return anything at all: a Boolean, a |
| 217 | matrix, a list, or any other Python object. Alternatively they can |
| 218 | raise an exception if the comparison is impossible, inconsistent, or |
| 219 | otherwise meaningless. |
| 220 | |
| 221 | The built-in \function{cmp(A,B)} function can use the rich comparison |
| 222 | machinery, and now accepts an optional argument specifying which |
| 223 | comparison operation to use; this is given as one of the strings |
| 224 | \code{"<"}, \code{"<="}, \code{">"}, \code{">="}, \code{"=="}, or |
| 225 | \code{"!="}. If called without the optional third argument, |
| 226 | \function{cmp()} will only return -1, 0, or +1 as in previous versions |
| 227 | of Python; otherwise it will call the appropriate method and can |
| 228 | return any Python object. |
| 229 | |
| 230 | There are also corresponding changes of interest to C programmers; |
| 231 | there's a new slot \code{tp_richcmp} in type objects and an API for |
| 232 | performing a given rich comparison. I won't cover the C API here, but |
Andrew M. Kuchling | bf14014 | 2001-02-28 22:10:07 +0000 | [diff] [blame] | 233 | will refer you to PEP 207, or to 2.1's C API documentation, for the |
| 234 | full list of related functions. |
Andrew M. Kuchling | b216ab6 | 2001-01-22 16:15:44 +0000 | [diff] [blame] | 235 | |
| 236 | \begin{seealso} |
| 237 | |
| 238 | \seepep{207}{Rich Comparisions}{Written by Guido van Rossum, heavily |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 239 | based on earlier work by David Ascher, and implemented by Guido van |
| 240 | Rossum.} |
Andrew M. Kuchling | b216ab6 | 2001-01-22 16:15:44 +0000 | [diff] [blame] | 241 | |
| 242 | \end{seealso} |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 243 | |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 244 | %====================================================================== |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 245 | \section{PEP 230: Warning Framework} |
| 246 | |
| 247 | Over its 10 years of existence, Python has accumulated a certain |
| 248 | number of obsolete modules and features along the way. It's difficult |
| 249 | to know when a feature is safe to remove, since there's no way of |
Andrew M. Kuchling | f33c118 | 2001-01-23 02:48:26 +0000 | [diff] [blame] | 250 | knowing how much code uses it --- perhaps no programs depend on the |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 251 | feature, or perhaps many do. To enable removing old features in a |
| 252 | more structured way, a warning framework was added. When the Python |
| 253 | developers want to get rid of a feature, it will first trigger a |
| 254 | warning in the next version of Python. The following Python version |
| 255 | can then drop the feature, and users will have had a full release |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 256 | cycle to remove uses of the old feature. |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 257 | |
| 258 | Python 2.1 adds the warning framework to be used in this scheme. It |
| 259 | adds a \module{warnings} module that provide functions to issue |
| 260 | warnings, and to filter out warnings that you don't want to be |
| 261 | displayed. Third-party modules can also use this framework to |
| 262 | deprecate old features that they no longer wish to support. |
| 263 | |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 264 | For example, in Python 2.1 the \module{regex} module is deprecated, so |
| 265 | importing it causes a warning to be printed: |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 266 | |
| 267 | \begin{verbatim} |
| 268 | >>> import regex |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 269 | __main__:1: DeprecationWarning: the regex module |
| 270 | is deprecated; please use the re module |
| 271 | >>> |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 272 | \end{verbatim} |
| 273 | |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 274 | Warnings can be issued by calling the \function{warnings.warn} |
| 275 | function: |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 276 | |
| 277 | \begin{verbatim} |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 278 | warnings.warn("feature X no longer supported") |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 279 | \end{verbatim} |
| 280 | |
| 281 | The first parameter is the warning message; an additional optional |
| 282 | parameters can be used to specify a particular warning category. |
| 283 | |
| 284 | Filters can be added to disable certain warnings; a regular expression |
| 285 | pattern can be applied to the message or to the module name in order |
| 286 | to suppress a warning. For example, you may have a program that uses |
| 287 | the \module{regex} module and not want to spare the time to convert it |
Andrew M. Kuchling | b216ab6 | 2001-01-22 16:15:44 +0000 | [diff] [blame] | 288 | to use the \module{re} module right now. The warning can be |
| 289 | suppressed by calling |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 290 | |
| 291 | \begin{verbatim} |
Andrew M. Kuchling | b216ab6 | 2001-01-22 16:15:44 +0000 | [diff] [blame] | 292 | import warnings |
| 293 | warnings.filterwarnings(action = 'ignore', |
| 294 | message='.*regex module is deprecated', |
| 295 | category=DeprecationWarning, |
| 296 | module = '__main__') |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 297 | \end{verbatim} |
| 298 | |
Andrew M. Kuchling | b216ab6 | 2001-01-22 16:15:44 +0000 | [diff] [blame] | 299 | This adds a filter that will apply only to warnings of the class |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 300 | \class{DeprecationWarning} triggered in the \module{__main__} module, |
| 301 | and applies a regular expression to only match the message about the |
| 302 | \module{regex} module being deprecated, and will cause such warnings |
| 303 | to be ignored. Warnings can also be printed only once, printed every |
| 304 | time the offending code is executed, or turned into exceptions that |
| 305 | will cause the program to stop (unless the exceptions are caught in |
| 306 | the usual way, of course). |
Andrew M. Kuchling | b216ab6 | 2001-01-22 16:15:44 +0000 | [diff] [blame] | 307 | |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 308 | Functions were also added to Python's C API for issuing warnings; |
Andrew M. Kuchling | b216ab6 | 2001-01-22 16:15:44 +0000 | [diff] [blame] | 309 | refer to PEP 230 or to Python's API documentation for the details. |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 310 | |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 311 | \begin{seealso} |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 312 | |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 313 | \seepep{5}{Guidelines for Language Evolution}{Written |
| 314 | by Paul Prescod, to specify procedures to be followed when removing |
| 315 | old features from Python. The policy described in this PEP hasn't |
| 316 | been officially adopted, but the eventual policy probably won't be too |
| 317 | different from Prescod's proposal.} |
| 318 | |
| 319 | \seepep{230}{Warning Framework}{Written and implemented by Guido van |
| 320 | Rossum.} |
| 321 | |
Andrew M. Kuchling | b216ab6 | 2001-01-22 16:15:44 +0000 | [diff] [blame] | 322 | \end{seealso} |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 323 | |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 324 | %====================================================================== |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 325 | \section{PEP 229: New Build System} |
| 326 | |
| 327 | When compiling Python, the user had to go in and edit the |
| 328 | \file{Modules/Setup} file in order to enable various additional |
| 329 | modules; the default set is relatively small and limited to modules |
| 330 | that compile on most Unix platforms. This means that on Unix |
| 331 | platforms with many more features, most notably Linux, Python |
| 332 | installations often don't contain all useful modules they could. |
| 333 | |
| 334 | Python 2.0 added the Distutils, a set of modules for distributing and |
| 335 | installing extensions. In Python 2.1, the Distutils are used to |
| 336 | compile much of the standard library of extension modules, |
Andrew M. Kuchling | f33c118 | 2001-01-23 02:48:26 +0000 | [diff] [blame] | 337 | autodetecting which ones are supported on the current machine. It's |
| 338 | hoped that this will make Python installations easier and more |
| 339 | featureful. |
| 340 | |
| 341 | Instead of having to edit the \file{Modules/Setup} file in order to |
| 342 | enable modules, a \file{setup.py} script in the top directory of the |
| 343 | Python source distribution is run at build time, and attempts to |
| 344 | discover which modules can be enabled by examining the modules and |
Andrew M. Kuchling | 8bad993 | 2001-02-28 22:39:15 +0000 | [diff] [blame] | 345 | header files on the system. If a module is configured in |
| 346 | \file{Modules/Setup}, the \file{setup.py} script won't attempt to |
| 347 | compile that module and will defer to the \file{Modules/Setup} file's |
| 348 | contents. This provides a way to specific any strange command-line |
| 349 | flags or libraries that are required for a specific platform. |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 350 | |
Andrew M. Kuchling | 4308d3c | 2001-01-29 17:36:53 +0000 | [diff] [blame] | 351 | In another far-reaching change to the build mechanism, Neil |
| 352 | Schemenauer restructured things so Python now uses a single makefile |
| 353 | that isn't recursive, instead of makefiles in the top directory and in |
Andrew M. Kuchling | 8bad993 | 2001-02-28 22:39:15 +0000 | [diff] [blame] | 354 | each of the \file{Python/}, \file{Parser/}, \file{Objects/}, and |
| 355 | \file{Modules/} subdirectories. This makes building Python faster |
| 356 | and also makes hacking the Makefiles clearer and simpler. |
Andrew M. Kuchling | 4308d3c | 2001-01-29 17:36:53 +0000 | [diff] [blame] | 357 | |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 358 | \begin{seealso} |
| 359 | |
| 360 | \seepep{229}{Using Distutils to Build Python}{Written |
| 361 | and implemented by A.M. Kuchling.} |
| 362 | |
Andrew M. Kuchling | b216ab6 | 2001-01-22 16:15:44 +0000 | [diff] [blame] | 363 | \end{seealso} |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 364 | |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 365 | %====================================================================== |
Andrew M. Kuchling | 15ad28c | 2001-02-14 02:44:18 +0000 | [diff] [blame] | 366 | \section{PEP 205: Weak References} |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 367 | |
Andrew M. Kuchling | 15ad28c | 2001-02-14 02:44:18 +0000 | [diff] [blame] | 368 | Weak references, available through the \module{weakref} module, are a |
| 369 | minor but useful new data type in the Python programmer's toolbox. |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 370 | |
Andrew M. Kuchling | 15ad28c | 2001-02-14 02:44:18 +0000 | [diff] [blame] | 371 | Storing a reference to an object (say, in a dictionary or a list) has |
| 372 | the side effect of keeping that object alive forever. There are a few |
| 373 | specific cases where this behaviour is undesirable, object caches |
| 374 | being the most common one, and another being circular references in |
| 375 | data structures such as trees. |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 376 | |
Andrew M. Kuchling | 15ad28c | 2001-02-14 02:44:18 +0000 | [diff] [blame] | 377 | For example, consider a memoizing function that caches the results of |
| 378 | another function \function{f(\var{x})} by storing the function's |
| 379 | argument and its result in a dictionary: |
| 380 | |
| 381 | \begin{verbatim} |
| 382 | _cache = {} |
| 383 | def memoize(x): |
| 384 | if _cache.has_key(x): |
| 385 | return _cache[x] |
| 386 | |
| 387 | retval = f(x) |
| 388 | |
| 389 | # Cache the returned object |
| 390 | _cache[x] = retval |
| 391 | |
| 392 | return retval |
| 393 | \end{verbatim} |
| 394 | |
| 395 | This version works for simple things such as integers, but it has a |
| 396 | side effect; the \code{_cache} dictionary holds a reference to the |
| 397 | return values, so they'll never be deallocated until the Python |
| 398 | process exits and cleans up This isn't very noticeable for integers, |
| 399 | but if \function{f()} returns an object, or a data structure that |
| 400 | takes up a lot of memory, this can be a problem. |
| 401 | |
| 402 | Weak references provide a way to implement a cache that won't keep |
| 403 | objects alive beyond their time. If an object is only accessible |
| 404 | through weak references, the object will be deallocated and the weak |
| 405 | references will now indicate that the object it referred to no longer |
| 406 | exists. A weak reference to an object \var{obj} is created by calling |
| 407 | \code{wr = weakref.ref(\var{obj})}. The object being referred to is |
| 408 | returned by calling the weak reference as if it were a function: |
| 409 | \code{wr()}. It will return the referenced object, or \code{None} if |
| 410 | the object no longer exists. |
| 411 | |
| 412 | This makes it possible to write a \function{memoize()} function whose |
| 413 | cache doesn't keep objects alive, by storing weak references in the |
| 414 | cache. |
| 415 | |
| 416 | \begin{verbatim} |
| 417 | _cache = {} |
| 418 | def memoize(x): |
| 419 | if _cache.has_key(x): |
| 420 | obj = _cache[x]() |
| 421 | # If weak reference object still exists, |
| 422 | # return it |
| 423 | if obj is not None: return obj |
| 424 | |
| 425 | retval = f(x) |
| 426 | |
| 427 | # Cache a weak reference |
| 428 | _cache[x] = weakref.ref(retval) |
| 429 | |
| 430 | return retval |
| 431 | \end{verbatim} |
| 432 | |
| 433 | The \module{weakref} module also allows creating proxy objects which |
| 434 | behave like weak references --- an object referenced only by proxy |
| 435 | objects is deallocated -- but instead of requiring an explicit call to |
| 436 | retrieve the object, the proxy transparently forwards all operations |
| 437 | to the object as long as the object still exists. If the object is |
| 438 | deallocated, attempting to use a proxy will cause a |
| 439 | \exception{weakref.ReferenceError} exception to be raised. |
| 440 | |
| 441 | \begin{verbatim} |
| 442 | proxy = weakref.proxy(obj) |
| 443 | proxy.attr # Equivalent to obj.attr |
| 444 | proxy.meth() # Equivalent to obj.meth() |
| 445 | del obj |
| 446 | proxy.attr # raises weakref.ReferenceError |
| 447 | \end{verbatim} |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 448 | |
| 449 | \begin{seealso} |
| 450 | |
| 451 | \seepep{205}{Weak References}{Written and implemented by |
| 452 | Fred~L. Drake,~Jr.} |
| 453 | |
| 454 | \end{seealso} |
| 455 | |
| 456 | %====================================================================== |
Andrew M. Kuchling | 74d18ed | 2001-02-28 22:22:40 +0000 | [diff] [blame] | 457 | \section{PEP 235: Case-Insensitive Platforms and \keyword{import}} |
| 458 | |
Andrew M. Kuchling | 8bad993 | 2001-02-28 22:39:15 +0000 | [diff] [blame] | 459 | Some operating systems have filesystems that are case-insensitive, |
| 460 | MacOS and Windows being the primary examples; on these systems, it's |
| 461 | impossible to distinguish the filenames \samp{FILE.PY} and |
| 462 | \samp{file.py}, even though they do store the file's name |
| 463 | in its original case (they're case-preserving, too). |
| 464 | |
| 465 | In Python 2.1, the \keyword{import} statement will work to simulate |
| 466 | case-sensitivity on case-insensitive platforms. Python will now |
| 467 | search for the first case-sensitive match by default, raising an |
| 468 | \exception{ImportError} if no such file is found, so \code{import file} |
| 469 | will not import a module named \samp{FILE.PY}. Case-insensitive |
| 470 | matching can be requested by setting the PYTHONCASEOK environment |
| 471 | variable before starting the Python interpreter. |
Andrew M. Kuchling | 74d18ed | 2001-02-28 22:22:40 +0000 | [diff] [blame] | 472 | |
| 473 | %====================================================================== |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 474 | \section{PEP 217: Interactive Display Hook} |
| 475 | |
| 476 | When using the Python interpreter interactively, the output of |
| 477 | commands is displayed using the built-in \function{repr()} function. |
| 478 | In Python 2.1, the variable \module{sys.displayhook} can be set to a |
| 479 | callable object which will be called instead of \function{repr()}. |
| 480 | For example, you can set it to a special pretty-printing function: |
| 481 | |
| 482 | \begin{verbatim} |
Andrew M. Kuchling | b216ab6 | 2001-01-22 16:15:44 +0000 | [diff] [blame] | 483 | >>> # Create a recursive data structure |
| 484 | ... L = [1,2,3] |
| 485 | >>> L.append(L) |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 486 | >>> L # Show Python's default output |
Andrew M. Kuchling | b216ab6 | 2001-01-22 16:15:44 +0000 | [diff] [blame] | 487 | [1, 2, 3, [...]] |
| 488 | >>> # Use pprint.pprint() as the display function |
| 489 | ... import sys, pprint |
| 490 | >>> sys.displayhook = pprint.pprint |
| 491 | >>> L |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 492 | [1, 2, 3, <Recursion on list with id=135143996>] |
| 493 | >>> |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 494 | \end{verbatim} |
| 495 | |
Andrew M. Kuchling | b216ab6 | 2001-01-22 16:15:44 +0000 | [diff] [blame] | 496 | \begin{seealso} |
| 497 | |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 498 | \seepep{217}{Display Hook for Interactive Use}{Written and implemented |
| 499 | by Moshe Zadka.} |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 500 | |
Andrew M. Kuchling | b216ab6 | 2001-01-22 16:15:44 +0000 | [diff] [blame] | 501 | \end{seealso} |
| 502 | |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 503 | %====================================================================== |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 504 | \section{PEP 208: New Coercion Model} |
| 505 | |
| 506 | How numeric coercion is done at the C level was significantly |
| 507 | modified. This will only affect the authors of C extensions to |
| 508 | Python, allowing them more flexibility in writing extension types that |
| 509 | support numeric operations. |
| 510 | |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 511 | Extension types can now set the type flag \code{Py_TPFLAGS_CHECKTYPES} |
| 512 | in their \code{PyTypeObject} structure to indicate that they support |
| 513 | the new coercion model. In such extension types, the numeric slot |
| 514 | functions can no longer assume that they'll be passed two arguments of |
| 515 | the same type; instead they may be passed two arguments of differing |
| 516 | types, and can then perform their own internal coercion. If the slot |
| 517 | function is passed a type it can't handle, it can indicate the failure |
| 518 | by returning a reference to the \code{Py_NotImplemented} singleton |
| 519 | value. The numeric functions of the other type will then be tried, |
| 520 | and perhaps they can handle the operation; if the other type also |
| 521 | returns \code{Py_NotImplemented}, then a \exception{TypeError} will be |
| 522 | raised. Numeric methods written in Python can also return |
| 523 | \code{Py_NotImplemented}, causing the interpreter to act as if the |
| 524 | method did not exist (perhaps raising a \exception{TypeError}, perhaps |
| 525 | trying another object's numeric methods). |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 526 | |
Andrew M. Kuchling | b216ab6 | 2001-01-22 16:15:44 +0000 | [diff] [blame] | 527 | \begin{seealso} |
| 528 | |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 529 | \seepep{208}{Reworking the Coercion Model}{Written and implemented by |
| 530 | Neil Schemenauer, heavily based upon earlier work by Marc-Andr\'e |
| 531 | Lemburg. Read this to understand the fine points of how numeric |
| 532 | operations will now be processed at the C level.} |
| 533 | |
Andrew M. Kuchling | b216ab6 | 2001-01-22 16:15:44 +0000 | [diff] [blame] | 534 | \end{seealso} |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 535 | |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 536 | %====================================================================== |
Andrew M. Kuchling | 81b6ae7 | 2001-02-11 16:55:39 +0000 | [diff] [blame] | 537 | \section{New and Improved Modules} |
| 538 | |
| 539 | \begin{itemize} |
| 540 | |
Andrew M. Kuchling | 74d18ed | 2001-02-28 22:22:40 +0000 | [diff] [blame] | 541 | \item Ka-Ping Yee contributed two new modules: \module{inspect.py}, a module for |
| 542 | getting information about live Python code, and \module{pydoc.py}, a |
| 543 | module for interactively converting docstrings to HTML or text. |
| 544 | As a bonus, \file{Tools/scripts/pydoc}, which is now automatically |
| 545 | installed, uses \module{pydoc.py} to display documentation given a Python module, package, or class name. For example, |
| 546 | \samp{pydoc xml.dom} displays the following: |
| 547 | |
| 548 | \begin{verbatim} |
| 549 | Python Library Documentation: package xml.dom in xml |
| 550 | |
| 551 | NAME |
| 552 | xml.dom - W3C Document Object Model implementation for Python. |
| 553 | |
| 554 | FILE |
| 555 | /usr/local/lib/python2.1/xml/dom/__init__.pyc |
| 556 | |
| 557 | DESCRIPTION |
| 558 | The Python mapping of the Document Object Model is documented in the |
| 559 | Python Library Reference in the section on the xml.dom package. |
| 560 | |
| 561 | This package contains the following modules: |
| 562 | ... |
| 563 | \end{verbatim} |
| 564 | |
| 565 | \file{pydoc} quickly becomes addictive; try it out! |
| 566 | |
Andrew M. Kuchling | 15ad28c | 2001-02-14 02:44:18 +0000 | [diff] [blame] | 567 | \item The \module{doctest} module provides a testing framework based |
| 568 | on running embedded examples in docstrings and comparing the results |
| 569 | against the expected output. Contributed by Tim Peters. |
| 570 | |
| 571 | \item The \module{difflib} module contains a class, |
| 572 | \class{SequenceMatcher}, which compares two sequences and computes the |
| 573 | changes required to transform one sequence into the other. For |
| 574 | example, this module can be used to write a tool similar to the Unix |
| 575 | \program{diff} program, and in fact the sample program |
| 576 | \file{Tools/scripts/ndiff.py} demonstrates how to write such a script. |
| 577 | |
Andrew M. Kuchling | 81b6ae7 | 2001-02-11 16:55:39 +0000 | [diff] [blame] | 578 | \item \module{curses.panel}, a wrapper for the panel library, part of |
| 579 | ncurses and of SYSV curses, was contributed by Thomas Gellekum. The |
| 580 | panel library provides windows with the additional feature of depth. |
| 581 | Windows can be moved higher or lower in the depth ordering, and the |
| 582 | panel library figures out where panels overlap and which sections are |
| 583 | visible. |
| 584 | |
| 585 | \item The PyXML package has gone through a few releases since Python |
| 586 | 2.0, and Python 2.1 includes an updated version of the \module{xml} |
Andrew M. Kuchling | 74d18ed | 2001-02-28 22:22:40 +0000 | [diff] [blame] | 587 | package. Some of the noteworthy changes include support for Expat 1.2 |
| 588 | and later versions, the ability for Expat parsers to handle files in |
| 589 | any encoding supported by Python, and various bugfixes for SAX, DOM, |
| 590 | and the \module{minidom} module. |
Andrew M. Kuchling | 81b6ae7 | 2001-02-11 16:55:39 +0000 | [diff] [blame] | 591 | |
| 592 | \item Various functions in the \module{time} module, such as |
| 593 | \function{asctime()} and \function{localtime()}, require a floating |
| 594 | point argument containing the time in seconds since the epoch. The |
| 595 | most common use of these functions is to work with the current time, |
| 596 | so the floating point argument has been made optional; when a value |
| 597 | isn't provided, the current time will be used. For example, log file |
| 598 | entries usually need a string containing the current time; in Python |
| 599 | 2.1, \code{time.asctime()} can be used, instead of the lengthier |
| 600 | \code{time.asctime(time.localtime(time.time()))} that was previously |
| 601 | required. |
| 602 | |
| 603 | This change was proposed and implemented by Thomas Wouters. |
| 604 | |
| 605 | \item The \module{ftplib} module now defaults to retrieving files in |
| 606 | passive mode, because passive mode is more likely to work from behind |
| 607 | a firewall. This request came from the Debian bug tracking system, |
| 608 | since other Debian packages use \module{ftplib} to retrieve files and |
| 609 | then don't work from behind a firewall. It's deemed unlikely that |
| 610 | this will cause problems for anyone, because Netscape defaults to |
| 611 | passive mode and few people complain, but if passive mode is |
| 612 | unsuitable for your application or network setup, call |
| 613 | \method{set_pasv(0)} on FTP objects to disable passive mode. |
| 614 | |
| 615 | \item Support for raw socket access has been added to the |
| 616 | \module{socket} module, contributed by Grant Edwards. |
| 617 | |
Andrew M. Kuchling | 15ad28c | 2001-02-14 02:44:18 +0000 | [diff] [blame] | 618 | \item A new implementation-dependent function, \function{sys._getframe(\optional{depth})}, |
| 619 | has been added to return a given frame object from the current call stack. |
| 620 | \function{sys._getframe()} returns the frame at the top of the call stack; |
| 621 | if the optional integer argument \var{depth} is supplied, the function returns the frame |
| 622 | that is \var{depth} calls below the top of the stack. For example, \code{sys._getframe(1)} |
| 623 | returns the caller's frame object. |
| 624 | |
| 625 | This function is only present in CPython, not in Jython or the .NET |
| 626 | implementation. Use it for debugging, and resist the temptation to |
| 627 | put it into production code. |
| 628 | |
| 629 | |
Andrew M. Kuchling | 81b6ae7 | 2001-02-11 16:55:39 +0000 | [diff] [blame] | 630 | |
| 631 | \end{itemize} |
| 632 | |
| 633 | %====================================================================== |
Andrew M. Kuchling | 74d18ed | 2001-02-28 22:22:40 +0000 | [diff] [blame] | 634 | \section{Other Changes and Fixes} |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 635 | |
| 636 | There were relatively few smaller changes made in Python 2.1 due to |
| 637 | the shorter release cycle. A search through the CVS change logs turns |
Andrew M. Kuchling | 81df7be | 2001-03-02 21:19:38 +0000 | [diff] [blame] | 638 | up 117 patches applied, and 136 bugs fixed; both figures are likely to |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 639 | be underestimates. Some of the more notable changes are: |
| 640 | |
| 641 | \begin{itemize} |
| 642 | |
Andrew M. Kuchling | bf14014 | 2001-02-28 22:10:07 +0000 | [diff] [blame] | 643 | |
| 644 | \item A specialized object allocator is now optionally available, that |
| 645 | should be faster than the system \function{malloc()} and have less |
| 646 | memory overhead. The allocator uses C's \function{malloc()} function |
| 647 | to get large pools of memory, and then fulfills smaller memory |
| 648 | requests from these pools. It can be enabled by providing the |
Andrew M. Kuchling | 45bbda2 | 2001-03-10 16:49:07 +0000 | [diff] [blame^] | 649 | \longprogramopt{with-pymalloc} option to the \program{configure} script; see |
Andrew M. Kuchling | 74d18ed | 2001-02-28 22:22:40 +0000 | [diff] [blame] | 650 | \file{Objects/obmalloc.c} for the implementation details. |
Andrew M. Kuchling | bf14014 | 2001-02-28 22:10:07 +0000 | [diff] [blame] | 651 | Contributed by Vladimir Marangozov. |
| 652 | |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 653 | \item The speed of line-oriented file I/O has been improved because |
| 654 | people often complain about its lack of speed, and because it's often |
| 655 | been used as a na\"ive benchmark. The \method{readline()} method of |
| 656 | file objects has therefore been rewritten to be much faster. The |
| 657 | exact amount of the speedup will vary from platform to platform |
| 658 | depending on how slow the C library's \function{getc()} was, but is |
| 659 | around 66\%, and potentially much faster on some particular operating |
Andrew M. Kuchling | f228fd1 | 2001-01-22 17:52:19 +0000 | [diff] [blame] | 660 | systems. Tim Peters did much of the benchmarking and coding for this |
| 661 | change, motivated by a discussion in comp.lang.python. |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 662 | |
| 663 | A new module and method for file objects was also added, contributed |
| 664 | by Jeff Epler. The new method, \method{xreadlines()}, is similar to |
| 665 | the existing \function{xrange()} built-in. \function{xreadlines()} |
| 666 | returns an opaque sequence object that only supports being iterated |
Andrew M. Kuchling | f228fd1 | 2001-01-22 17:52:19 +0000 | [diff] [blame] | 667 | over, reading a line on every iteration but not reading the entire |
Andrew M. Kuchling | f33c118 | 2001-01-23 02:48:26 +0000 | [diff] [blame] | 668 | file into memory as the existing \method{readlines()} method does. |
| 669 | You'd use it like this: |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 670 | |
| 671 | \begin{verbatim} |
| 672 | for line in sys.stdin.xreadlines(): |
| 673 | # ... do something for each line ... |
| 674 | ... |
| 675 | \end{verbatim} |
| 676 | |
Andrew M. Kuchling | f228fd1 | 2001-01-22 17:52:19 +0000 | [diff] [blame] | 677 | For a fuller discussion of the line I/O changes, see the python-dev |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 678 | summary for January 1-15, 2001. |
Andrew M. Kuchling | 91834c6 | 2001-01-22 19:51:13 +0000 | [diff] [blame] | 679 | |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 680 | \item A new method, \method{popitem()}, was added to dictionaries to |
| 681 | enable destructively iterating through the contents of a dictionary; |
| 682 | this can be faster for large dictionaries because . |
| 683 | \code{D.popitem()} removes a random \code{(\var{key}, \var{value})} |
| 684 | pair from the dictionary and returns it as a 2-tuple. This was |
| 685 | implemented mostly by Tim Peters and Guido van Rossum, after a |
| 686 | suggestion and preliminary patch by Moshe Zadka. |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 687 | |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 688 | \item Modules can now control which names are imported when \code{from |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 689 | \var{module} import *} is used, by defining an \code{__all__} |
| 690 | attribute containing a list of names that will be imported. One |
| 691 | common complaint is that if the module imports other modules such as |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 692 | \module{sys} or \module{string}, \code{from \var{module} import *} |
| 693 | will add them to the importing module's namespace. To fix this, |
| 694 | simply list the public names in \code{__all__}: |
| 695 | |
| 696 | \begin{verbatim} |
| 697 | # List public names |
| 698 | __all__ = ['Database', 'open'] |
| 699 | \end{verbatim} |
| 700 | |
Andrew M. Kuchling | b216ab6 | 2001-01-22 16:15:44 +0000 | [diff] [blame] | 701 | A stricter version of this patch was first suggested and implemented |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 702 | by Ben Wolfson, but after some python-dev discussion, a weaker final |
| 703 | version was checked in. |
Andrew M. Kuchling | b216ab6 | 2001-01-22 16:15:44 +0000 | [diff] [blame] | 704 | |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 705 | \item Applying \function{repr()} to strings previously used octal |
| 706 | escapes for non-printable characters; for example, a newline was |
| 707 | \code{'\e 012'}. This was a vestigial trace of Python's C ancestry, but |
| 708 | today octal is of very little practical use. Ka-Ping Yee suggested |
| 709 | using hex escapes instead of octal ones, and using the \code{\e n}, |
| 710 | \code{\e t}, \code{\e r} escapes for the appropriate characters, and |
| 711 | implemented this new formatting. |
Andrew M. Kuchling | 4308d3c | 2001-01-29 17:36:53 +0000 | [diff] [blame] | 712 | |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 713 | \item Syntax errors detected at compile-time can now raise exceptions |
| 714 | containing the filename and line number of the error, a pleasant side |
| 715 | effect of the compiler reorganization done by Jeremy Hylton. |
| 716 | |
Andrew M. Kuchling | 15ad28c | 2001-02-14 02:44:18 +0000 | [diff] [blame] | 717 | \item C extensions which import other modules have been changed to use |
| 718 | \function{PyImport_ImportModule()}, which means that they will use any |
| 719 | import hooks that have been installed. This is also encouraged for |
| 720 | third-party extensions that need to import some other module from C |
| 721 | code. |
| 722 | |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 723 | \item The size of the Unicode character database was shrunk by another |
| 724 | 340K thanks to Fredrik Lundh. |
Andrew M. Kuchling | 91834c6 | 2001-01-22 19:51:13 +0000 | [diff] [blame] | 725 | |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 726 | \end{itemize} |
| 727 | |
Andrew M. Kuchling | 74d18ed | 2001-02-28 22:22:40 +0000 | [diff] [blame] | 728 | And there's the usual list of minor bugfixes, minor memory leaks, |
| 729 | docstring edits, and other tweaks, too lengthy to be worth itemizing; |
| 730 | see the CVS logs for the full details if you want them. |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 731 | |
| 732 | |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 733 | %====================================================================== |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 734 | \section{Acknowledgements} |
| 735 | |
Andrew M. Kuchling | 6a360bd | 2001-02-05 02:47:52 +0000 | [diff] [blame] | 736 | The author would like to thank the following people for offering |
| 737 | suggestions on various drafts of this article: Graeme Cross, David |
| 738 | Goodger, Jay Graves, Michael Hudson, Marc-Andr\'e Lemburg, Fredrik |
| 739 | Lundh, Neil Schemenauer, Thomas Wouters. |
Andrew M. Kuchling | 90cecee | 2001-01-22 04:02:09 +0000 | [diff] [blame] | 740 | |
| 741 | \end{document} |