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

Skip to content

Commit ef85cc8

Browse files
committed
Add section for PEP 241
Add PyUnit and sys.excepthook
1 parent b5c5132 commit ef85cc8

1 file changed

Lines changed: 109 additions & 5 deletions

File tree

Doc/whatsnew/whatsnew21.tex

Lines changed: 109 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
\documentclass{howto}
22

3+
\usepackage{distutils}
4+
35
% $Id$
46

57
\title{What's New in Python 2.1}
6-
\release{0.06}
8+
\release{0.07}
79
\author{A.M. Kuchling}
810
\authoraddress{\email{[email protected]}}
911
\begin{document}
@@ -454,6 +456,48 @@ \section{PEP 205: Weak References}
454456
\end{seealso}
455457
456458
%======================================================================
459+
\section{PEP 232: Function Attributes}
460+
461+
In Python 2.1, functions can now have arbitrary information attached
462+
to them. People were often using docstrings to hold information about
463+
functions and methods, because the \code{__doc__} attribute was the
464+
only way of attaching any information to a function. For example, in
465+
the Zope Web application server, functions are marked as safe for
466+
public access by having a docstring, and in John Aycock's SPARK
467+
parsing framework, docstrings hold parts of the BNF grammar to be
468+
parsed. This overloading is unfortunate, since docstrings are really
469+
intended to hold a function's documentation; for example, it means you
470+
can't properly document functions intended for private use in Zope.
471+
472+
Arbitrary attributes can now be set and retrieved on functions using the
473+
regular Python syntax:
474+
475+
\begin{verbatim}
476+
def f(): pass
477+
478+
f.publish = 1
479+
f.secure = 1
480+
f.grammar = "A ::= B (C D)*"
481+
\end{verbatim}
482+
483+
The dictionary containing attributes can be accessed as the function's
484+
\member{__dict__}. Unlike the \member{__dict__} attribute of class
485+
instances, in functions you can actually assign a new dictionary to
486+
\member{__dict__}, though the new value is restricted to a regular
487+
Python dictionary; you \emph{can't} be tricky and set it to a
488+
\class{UserDict} instance, or any other random object that behaves
489+
like a mapping.
490+
491+
\begin{seealso}
492+
493+
\seepep{232}{Function Attributes}{Written and implemented by Barry
494+
Warsaw.}
495+
496+
\end{seealso}
497+
498+
499+
%======================================================================
500+
457501
\section{PEP 235: Case-Insensitive Platforms and \keyword{import}}
458502
459503
Some operating systems have filesystems that are case-insensitive,
@@ -475,7 +519,7 @@ \section{PEP 217: Interactive Display Hook}
475519
476520
When using the Python interpreter interactively, the output of
477521
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
522+
In Python 2.1, the variable \function{sys.displayhook} can be set to a
479523
callable object which will be called instead of \function{repr()}.
480524
For example, you can set it to a special pretty-printing function:
481525
@@ -533,6 +577,50 @@ \section{PEP 208: New Coercion Model}
533577
534578
\end{seealso}
535579
580+
%======================================================================
581+
\section{PEP 241: Metadata in Python Packages}
582+
583+
A common complaint from Python users is that there's no single catalog
584+
of all the Python modules in existence. T.~Middleton's Vaults of
585+
Parnassus at \url{http://www.vex.net/parnassus} are the largest
586+
catalog of Python modules, but registering software at the Vaults is
587+
optional, and many people don't bother.
588+
589+
As a first small step toward fixing the problem, Python software
590+
packaged using the Distutils \command{sdist} command will include a
591+
file named \file{PKG-INFO} containing information about the package
592+
such as its name, version, and author (metadata, in cataloguing
593+
terminology). PEP 241 contains the full list of fields that can be
594+
present in the \file{PKG-INFO} file. As people began to package their
595+
software using Python 2.1, more and more packages will include
596+
metadata, making it possible to build automated cataloguing systems
597+
and experiment with them. With the result experience, perhaps it'll
598+
be possible to design a really good catalog and then build support for
599+
it into Python 2.2. For example, the Distutils \command{sdist}
600+
and \command{bdist_*} commands could support a \option{upload} option
601+
that would automatically upload your package to a catalog server.
602+
603+
You can start creating packages containing \file{PKG-INFO} even if
604+
you're not using Python 2.1, since a new release of the Distutils will
605+
be made for users of earlier Python versions. Version 1.0.2 of the
606+
Distutils includes the changes described in PEP 241, as well as
607+
various bugfixes and enhancements. It will be available from
608+
the Distutils SIG at \url{http://www.python.org/sigs/distutils-sig}.
609+
610+
% XXX update when I actually release 1.0.2
611+
612+
\begin{seealso}
613+
614+
\seepep{241}{Metadata for Python Software Packages}{Written and
615+
implemented by A.M. Kuchling.}
616+
617+
\seepep{243}{Module Repository Upload Mechanism}{Written by Sean
618+
Reifschneider, this draft PEP describes a proposed mechanism for uploading
619+
Python packages to a central server.
620+
}
621+
622+
\end{seealso}
623+
536624
%======================================================================
537625
\section{New and Improved Modules}
538626
@@ -564,9 +652,15 @@ \section{New and Improved Modules}
564652
565653
\file{pydoc} quickly becomes addictive; try it out!
566654
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.
655+
\item Two different modules for unit testing were added to the
656+
standard library. The \module{doctest} module, contributed by Tim
657+
Peters, provides a testing framework based on running embedded
658+
examples in docstrings and comparing the results against the expected
659+
output. PyUnit, contributed by Steve Purcell, is a unit testing
660+
framework inspired by JUnit, which was in turn an adaptation of Kent
661+
Beck's Smalltalk testing framework. See
662+
\url{http://pyunit.sourceforge.net/} for more information about
663+
PyUnit.
570664
571665
\item The \module{difflib} module contains a class,
572666
\class{SequenceMatcher}, which compares two sequences and computes the
@@ -589,6 +683,16 @@ \section{New and Improved Modules}
589683
any encoding supported by Python, and various bugfixes for SAX, DOM,
590684
and the \module{minidom} module.
591685
686+
\item Ping also contributed another hook for handling uncaught
687+
exceptions. \function{sys.excepthook} can be set to a callable
688+
object. When an exception isn't caught by any
689+
\keyword{try}...\keyword{except} blocks, the exception will be passed
690+
to \function{sys.excepthook}, which can then do whatever it likes. At
691+
the Ninth Python Conference, Ping demonstrated an application for this
692+
hook: printing an extended traceback that not only lists the stack
693+
frames, but also lists the function arguments and the local variables
694+
for each frame.
695+
592696
\item Various functions in the \module{time} module, such as
593697
\function{asctime()} and \function{localtime()}, require a floating
594698
point argument containing the time in seconds since the epoch. The

0 commit comments

Comments
 (0)