1212
1313% MacOS framework-related changes (section of its own, probably)
1414
15- % the new set-next-statement functionality of pdb (SF #643835)
16-
1715% \section{Introduction \label{intro}}
1816
19- {\large This article is a draft, and is currently up to date for some
20- random version of the CVS tree from early November 2002. Please send any
21- additions, comments or errata to the author.}
17+ {\large This article is a draft, and is currently up to date for
18+ Python 2.3alpha1. Please send any additions, comments or errata to
19+ the author.}
2220
2321This article explains the new features in Python 2.3. The tentative
2422release date of Python 2.3 is currently scheduled for some undefined
@@ -646,6 +644,128 @@ \section{PEP 293: Codec Error Handling Callbacks}
646644\end {seealso }
647645
648646
647+ % ======================================================================
648+ \section {PEP 273: Importing Modules from Zip Archives }
649+
650+ The new \module {zipimport} module adds support for importing
651+ modules from a ZIP-format archive. You shouldn't need to import the
652+ module explicitly; it will be automatically imported if a ZIP
653+ archive's filename is added to \code {sys.path}. For example:
654+
655+ \begin {verbatim }
656+ amk@nyman:~/src/python$ unzip -l /tmp/example.zip
657+ Archive: /tmp/example.zip
658+ Length Date Time Name
659+ -------- ---- ---- ----
660+ 8467 11-26-02 22:30 jwzthreading.py
661+ -------- -------
662+ 8467 1 file
663+ amk@nyman:~/src/python$ ./python
664+ Python 2.3a0 (#1, Dec 30 2002, 19:54:32)
665+ [GCC 2.96 20000731 (Red Hat Linux 7.3 2.96-113)] on linux2
666+ Type "help", "copyright", "credits" or "license" for more information.
667+ >>> import sys
668+ >>> sys.path.insert(0, '/tmp/example.zip') # Add .zip file to front of path
669+ >>> import jwzthreading
670+ >>> jwzthreading.__file__
671+ '/tmp/example.zip/jwzthreading.py'
672+ >>>
673+ \end {verbatim }
674+
675+ An entry in \code {sys.path} can now be the filename of a ZIP archive.
676+ The ZIP archive can contain any kind of files, but only files named
677+ \code {*.py}, \code {*.pyc}, or \code {*.pyo} can be imported. If an
678+ archive only contains \code {*.py} files, Python will not attempt to
679+ modify the archive by adding the corresponding {*.pyc} file.
680+ Therefore, if a ZIP archive doesn't contain {*.pyc} files, importing
681+ may be rather slow.
682+
683+ A path within the archive can also be specified to only import from a
684+ subdirectory; for example, the path \file {/tmp/example.zip/lib/}
685+ would only import from the \file {lib/} subdirectory within the
686+ archive.
687+
688+ This new feature is implemented using the new import hooks from
689+ \pep {302}; see section~\ref {section-pep302 } for a description.
690+
691+ \begin {seealso }
692+
693+ \seepep {273}{Import Modules from Zip Archives}{Written by James C. Ahlstrom,
694+ who also provided an implementation.
695+ Python 2.3 follows the specification in \pep {273},
696+ but uses an implementation written by Just van Rossum
697+ that uses the import hooks described in \pep {302}.}
698+
699+ \end {seealso }
700+
701+ % ======================================================================
702+ \section {PEP 302: New Import Hooks \label {section-pep302 } }
703+
704+ While it's been possible to write custom import hooks ever since the
705+ \module {ihooks} module was introduced in Python 1.3, no one has ever
706+ been really happy with it, because writing new import hooks is
707+ difficult and messy. There have been various alternative interfaces
708+ proposed, such as the \module {imputil} and \module {iu} modules, but
709+ none has ever gained much acceptance, and none was easily usable from
710+ \C {} code.
711+
712+ \pep {302} borrows ideas from its predecessors, especially from
713+ Gordon McMillan's \module {iu} module. Three new items
714+ are added to the \module {sys} module:
715+
716+ \begin {itemize }
717+ \item [\code {sys.path_hooks}] is a list of functions. Each function
718+ takes a string containing a path and returns either \code {None} or an
719+ importer object that will handle imports from this path.
720+
721+ \item [\code {sys.path_importer_cache}] caches importer objects for
722+ each path, so \code {sys.path_hooks} will only need to be traversed
723+ once for each path.
724+
725+ \item [\code {sys.meta_path}] is a list of importer objects
726+ that will be traversed before \code {sys.path} is checked at all.
727+ This list is initially empty, but can be extended. Additional built-in
728+ and frozen modules can be imported by an object added to this list.
729+
730+ \end {itemize }
731+
732+ Importer objects must have a single method,
733+ \method {find_module(\var {fullname}, \var {path}=None)}. \var {fullname}
734+ will be a module or package name, e.g. \samp {string} or
735+ \samp {spam.ham}. \method {find_module()} must return a loader object
736+ that has a single method, \method {load_module(\var {fullname})}, that
737+ creates and returns the corresponding module object.
738+
739+ Pseudo-code for Python's new import logic, therefore, looks something
740+ like this (simplified a bit; see \pep {302} for the full details):
741+
742+ \begin {verbatim }
743+ for mp in sys.meta_path:
744+ loader = mp(fullname)
745+ if loader is not None:
746+ <module> = loader(fullname)
747+
748+ for path in sys.path:
749+ for hook in sys.path_hooks:
750+ importer = hook(path)
751+ if importer is not None:
752+ loader = importer.find_module(fullname)
753+ return loader.load_module(fullname)
754+
755+ # Not found!
756+ raise ImportError
757+ \end {verbatim }
758+
759+ \begin {seealso }
760+
761+ \seepep {302}{New Import Hooks}{Written by Just van~Rossum and Paul Moore.
762+ Implemented by Just van Rossum.
763+ % XXX is that credit right?
764+ }
765+
766+ \end {seealso }
767+
768+
649769% ======================================================================
650770\section {Extended Slices\label {section-slices } }
651771
@@ -797,7 +917,8 @@ \section{Other Language Changes}
797917integer instead of raising an \exception {OverflowError} when a string
798918or floating-point number is too large to fit into an integer. This
799919can lead to the paradoxical result that
800- \code {isinstance(int(\var {expression}), int)} is false, but that seems unlikely to cause problems in practice.
920+ \code {isinstance(int(\var {expression}), int)} is false, but that seems
921+ unlikely to cause problems in practice.
801922
802923\item Built-in types now support the extended slicing syntax,
803924as described in section~\ref {section-slices } of this document.
@@ -835,7 +956,7 @@ \section{Other Language Changes}
835956
836957(Patches contributed by Raymond Hettinger.)
837958
838- The \function {dict()} constructor now also accepts keyword arguments to
959+ Also, the \function {dict()} constructor now accepts keyword arguments to
839960simplify creating small dictionaries:
840961
841962\begin {verbatim }
@@ -1012,6 +1133,9 @@ \subsection{Optimizations}
10121133
10131134\begin {itemize }
10141135
1136+ \item The creation of new-style class instances has been made much
1137+ faster; they're now faster than classic classes!
1138+
10151139\item The \method {sort()} method of list objects has been extensively
10161140rewritten by Tim Peters, and the implementation is significantly
10171141faster.
@@ -1056,7 +1180,7 @@ \section{New and Improved Modules}
10561180contents, and the \code {*=} assignment operator to repeat an array.
10571181(Contributed by Jason Orendorff.)
10581182
1059- \item The \module {bsddb} module has been updated to version 3.4.0
1183+ \item The \module {bsddb} module has been updated to version 4.1.1
10601184of the \ulink {PyBSDDB}{http://pybsddb.sourceforge.net} package,
10611185providing a more complete interface to the transactional features of
10621186the BerkeleyDB library.
@@ -1118,6 +1242,8 @@ \section{New and Improved Modules}
11181242('amk', 500)
11191243\end {verbatim }
11201244
1245+ \item The \module {gzip} module can now handle files exceeding 2~Gb.
1246+
11211247\item The new \module {heapq} module contains an implementation of a
11221248heap queue algorithm. A heap is an array-like data structure that
11231249keeps items in a partially sorted order such that,
@@ -1218,13 +1344,21 @@ \section{New and Improved Modules}
12181344>>> random.sample(xrange(1,10000,2), 10) # Choose ten odds under 10000
12191345[3407, 3805, 1505, 7023, 2401, 2267, 9733, 3151, 8083, 9195]
12201346\end {verbatim }
1221-
1222- (Contributed by Raymond Hettinger.)
1347+
1348+ The \module {random} module now uses a new algorithm, the Mersenne
1349+ Twister, implemented in C. It's faster and more extensively studied
1350+ than the previous algorithm.
1351+
1352+ (All changes contributed by Raymond Hettinger.)
12231353
12241354\item The \module {readline} module also gained a number of new
12251355functions: \function {get_history_item()},
12261356\function {get_current_history_length()}, and \function {redisplay()}.
12271357
1358+ \item The \module {shutil} module gained a \function {move(\var {src},
1359+ \var {dest})} that recursively moves a file or directory to a new
1360+ location.
1361+
12281362\item Support for more advanced POSIX signal handling was added
12291363to the \module {signal} module by adding the \function {sigpending},
12301364\function {sigprocmask} and \function {sigsuspend} functions, where supported
@@ -1284,6 +1418,28 @@ \section{New and Improved Modules}
12841418% XXX add a link to the module docs?
12851419(Contributed by Greg Ward.)
12861420
1421+ \item The \module {thread} and \module {threading} modules now have
1422+ companion, \module {dummy_thread} and \module {dummy_threading}, that
1423+ provide a do-nothing implementation of the \module {thread} module's
1424+ interface, even if threads are not supported. The intention is to
1425+ simplify thread-aware modules (that \emph {don't } rely on threads to
1426+ run) by putting the following code at the top:
1427+
1428+ % XXX why as _threading?
1429+ \begin {verbatim }
1430+ try:
1431+ import threading as _threading
1432+ except ImportError:
1433+ import dummy_threading as _threading
1434+ \end {verbatim }
1435+
1436+ Code can then call functions and use classes in \module {_threading}
1437+ whether or not threads are supported, avoiding an \keyword {if}
1438+ statement and making the code slightly clearer. This module will not
1439+ magically make multithreaded code run without threads; code that waits
1440+ for another thread to return or to do something will simply hang
1441+ forever.
1442+
12871443\item The \module {time} module's \function {strptime()} function has
12881444long been an annoyance because it uses the platform C library's
12891445\function {strptime()} implementation, and different platforms
@@ -1610,6 +1766,8 @@ \section{Build and C API Changes}
16101766
16111767\end {itemize }
16121768
1769+ It's also no longer possible to build Python without the garbage collector.
1770+
16131771\item Python can now optionally be built as a shared library
16141772(\file {libpython2.3.so}) by supplying \longprogramopt {enable-shared}
16151773when running Python's \program {configure} script. (Contributed by Ondrej
@@ -1672,6 +1830,22 @@ \section{Build and C API Changes}
16721830\end {itemize }
16731831
16741832
1833+ \begin {comment }
1834+ % ======================================================================
1835+ \subsection {Date/Time Type }
1836+
1837+ Date and time types suitable for expressing timestamps were added as
1838+ the \module {datetime} module. The types don't support different
1839+ calendars or many fancy features, and just stick to the basics.
1840+
1841+ The three primary types are: \class {date}, representing a day, month,
1842+ and year; \class {time}, consisting of hour, minute, and second value;
1843+ and \class {datetime}, which contains both a date and a time.
1844+
1845+ XXX finish this section
1846+ \end {comment }
1847+
1848+
16751849% ======================================================================
16761850\subsection {Port-Specific Changes }
16771851
@@ -1695,7 +1869,8 @@ \subsection{Port-Specific Changes}
16951869Python source distribution, were updated for 2.3. (Contributed by
16961870Sean Reifschneider.)
16971871
1698- Python now supports AtheOS (\url {http://www.atheos.cx}) and GNU/Hurd.
1872+ Python now supports AtheOS (\url {http://www.atheos.cx}), GNU/Hurd,
1873+ OpenVMS, and OS/2 with EMX.
16991874
17001875
17011876% ======================================================================
@@ -1738,6 +1913,12 @@ \section{Other Changes and Fixes}
17381913This will have the added effect of making the code work as desired
17391914under `` python -O'' in earlier versions of Python.
17401915
1916+ A nifty new feature is that trace functions can now the
1917+ \member {f_lineno} attribute of frame objects can now be assigned to,
1918+ changing the line that will be executed next. A \samp {jump} command
1919+ has been added to the \module {pdb} debugger taking advantage of this
1920+ new feature. (Implemented by Richie Hindle.)
1921+
17411922\end {itemize }
17421923
17431924
0 commit comments