Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5b8311e

Browse files
committed
Filled out the "Core Changes" section.
1 parent d8dfb4c commit 5b8311e

1 file changed

Lines changed: 81 additions & 24 deletions

File tree

Doc/whatsnew/whatsnew20.tex

Lines changed: 81 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -118,42 +118,99 @@ \section{Porting to 1.6}
118118
\function{str()} uses ``%.12g'' as before. The effect is that
119119
\function{repr()} may occasionally show more decimal places than
120120
\function{str()}, for numbers
121-
XXX need example value here.
121+
122+
XXX need example value here to demonstrate problem.
122123
123124
124125
% ======================================================================
125126
\section{Core Changes}
126127
127-
Deleting objects is safe even for deeply nested data structures.
128-
Comparing recursive objects is now safe (doesn't dump core).
129-
130-
Builds on NT Alpha, and work on Win64 (NT Itanium -- sys.platform is
131-
still 'win32') is ongoing. Supports Windows CE (confirm with Mark
132-
Hammond)
133-
134-
UnboundLocalError is raised when a local variable is undefined
135-
long, int take optional "base" parameter
136-
137-
string objects now have methods (though they are still immutable)
138-
139-
sys.version_info is a tuple: (major, minor, micro, level, serial); level
140-
is a string "a2", "b1", "c1", or '' for a final release.
141-
142-
New format style '%r' inserts repr(arg) instead of str(arg).
143-
144-
"in" operator can now be overriden in user-defined classes to mean anything:
145-
it calls the magic method __contains__
146-
147-
New calling syntax: f(*args, **kw) equivalent to apply(f, args, kw)
128+
Various minor changes have been made to Python's syntax and built-in
129+
functions. None of the changes are very far-reaching, but they're
130+
handy conveniences.
131+
132+
A change to syntax makes it more convenient to call a given function
133+
with a tuple of arguments and/or a dictionary of keyword arguments.
134+
In Python 1.5 and earlier, you do this with the \builtin{apply()}
135+
built-in function: \code{apply(f, \var{args}, \var{kw})} calls the
136+
function \function{f()} with the argument tuple \var{args} and the
137+
keyword arguments in the dictionary \var{kw}. Thanks to a patch from
138+
Greg Ewing, 1.6 adds \code{f(*\var{args}, **\var{kw})} as a shorter
139+
and clearer way to achieve the same effect. This syntax is
140+
symmetrical with the syntax for defining functions:
141+
142+
\begin{verbatim}
143+
def f(*args, **kw):
144+
# args is a tuple of positional args,
145+
# kw is a dictionary of keyword args
146+
...
147+
\end{verbatim}
148+
149+
A new format style is available when using the \operator{\%} operator.
150+
'\%r' will insert the \function{repr()} of its argument. This was
151+
also added from symmetry considerations, this time for symmetry with
152+
the existing '\%s' format style which inserts the \function{str()} of
153+
its argument. For example, \code{'%r %s' % ('abc', 'abc')} returns a
154+
string containing \verb|'abc' abc|.
155+
156+
The \builtin{int()} and \builtin{long()} functions now accept an
157+
optional ``base'' parameter when the first argument is a string.
158+
\code{int('123', 10)} returns 123, while \code{int('123', 16)} returns
159+
291. \code{int(123, 16)} raises a \exception{TypeError} exception
160+
with the message ``can't convert non-string with explicit base''.
161+
162+
Previously there was no way to implement a class that overrode
163+
Python's built-in \operator{in} operator and implemented a custom
164+
version. \code{\var{obj} in \var{seq}} returns true if \var{obj} is
165+
present in the sequence \var{seq}; Python computes this by simply
166+
trying every index of the sequence until either \var{obj} is found or
167+
an \exception{IndexError} is encountered. Moshe Zadka contributed a
168+
patch which adds a \method{__contains__} magic method for providing a
169+
custom implementation for \operator{in}.
170+
171+
Earlier versions of Python used a recursive algorithm for deleting
172+
objects. Deeply nested data structures could cause the interpreter to
173+
fill up the C stack and crash; Christian Tismer rewrote the deletion
174+
logic to fix this problem. On a related note, comparing recursive
175+
objects recursed infinitely and crashed; Jeremy Hylton rewrote the
176+
code to no longer crash, producing a useful result instead. For
177+
example, after this code:
178+
179+
\begin{verbatim}
180+
a = []
181+
b = []
182+
a.append(a)
183+
b.append(b)
184+
\end{verbatim}
185+
186+
The comparison \code{a==b} returns true, because the two recursive
187+
data structures are isomorphic.
188+
\footnote{See the thread ``trashcan and PR\#7'' in the April 2000 archives of the python-dev mailing list for the discussion leading up to this implementation, and some useful relevant links.
189+
%http://www.python.org/pipermail/python-dev/2000-April/004834.html
190+
}
191+
192+
Work has been done on porting Python to 64-bit Windows on the Itanium
193+
processor, mostly by Trent Mick of ActiveState. (Confusingly, for
194+
complicated reasons \code{sys.platform} is still \code{'win32'} on
195+
Win64.) PythonWin also supports Windows CE; see the Python CE page at
196+
\url{http://www.python.net/crew/mhammond/ce/} for more information.
197+
198+
XXX UnboundLocalError is raised when a local variable is undefined
199+
200+
A new variable holding more detailed version information has been
201+
added to the \module{sys} module. \code{sys.version_info} is a tuple
202+
\code{(\var{major}, \var{minor}, \var{micro}, \var{level},
203+
\var{serial})} For example, in 1.6a2 \code{sys.version_info} is
204+
\code{(1, 6, 0, 'alpha', 2)}. \var{level} is a string such as
205+
"alpha", "beta", or '' for a final release.
148206
149207
% ======================================================================
150208
\section{Extending/embedding Changes}
151209
152210
Some of the changes are under the covers, and will only be apparent to
153211
people writing C extension modules, or embedding a Python interpreter
154212
in a larger application. If you aren't dealing with Python's C API,
155-
you can safely skip this section since it won't contain anything of
156-
interest to you.
213+
you can safely skip this section.
157214
158215
Users of Jim Fulton's ExtensionClass module will be pleased to find
159216
out that hooks have been added so that ExtensionClasses are now

0 commit comments

Comments
 (0)