[Python-checkins] python/dist/src/Doc/ref ref6.tex,1.47.4.2,1.47.4.3

rhettinger@users.sourceforge.net rhettinger@users.sourceforge.net
Fri, 04 Oct 2002 23:12:12 -0700


Update of /cvsroot/python/python/dist/src/Doc/ref
In directory usw-pr-cvs1:/tmp/cvs-serv30079

Modified Files:
      Tag: release22-maint
	ref6.tex 
Log Message:
Backport 1.54 1.53 1.52 1.51 1.50 and 1.49:


Try to improve the explanation of the "raise" statement and how its arguments
are interpreted.
This closes SF bug #532467.


Fix Typo.


Reword explanation of global statement since an undeclared global is a
free variable and is subject to those rules.


Note the sole case in which the ban on "from ... import *" within a
function is enforced.


Remove the following restriction:
    Names bound by import statements may not occur in global
    statements in the same scope.
Why not?



Note that it is illegal to delete a cell variable.
Note that deleteing an unbound local will raise a NameError.




Index: ref6.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/ref/ref6.tex,v
retrieving revision 1.47.4.2
retrieving revision 1.47.4.3
diff -C2 -d -r1.47.4.2 -r1.47.4.3
*** ref6.tex	25 Jun 2002 13:39:49 -0000	1.47.4.2
--- ref6.tex	5 Oct 2002 06:12:08 -0000	1.47.4.3
***************
*** 353,362 ****
  to right.
  
! Deletion of a name removes the binding of that name (which must exist)
  from the local or global namespace, depending on whether the name
! occurs in a \keyword{global} statement in the same code block.
  \stindex{global}
  \indexii{unbinding}{name}
  
  Deletion of attribute references, subscriptions and slicings
  is passed to the primary object involved; deletion of a slicing
--- 353,366 ----
  to right.
  
! Deletion of a name removes the binding of that name 
  from the local or global namespace, depending on whether the name
! occurs in a \keyword{global} statement in the same code block.  If the
! name is unbound, a \exception{NameError} exception will be raised.
  \stindex{global}
  \indexii{unbinding}{name}
  
+ It is illegal to delete a name from the local namespace if it occurs
+ as a free variable\indexii{free}{variable} in a nested block.
+ 
  Deletion of attribute references, subscriptions and slicings
  is passed to the primary object involved; deletion of a slicing
***************
*** 518,552 ****
  
  If no expressions are present, \keyword{raise} re-raises the last
! expression that was raised in the current scope.
! 
! Otherwise, \keyword{raise} evaluates its first expression, which must yield
! a string, class, or instance object.  If there is a second expression,
! this is evaluated, else \code{None} is substituted.  If the first
! expression is a class object, then the second expression may be an
! instance of that class or one of its derivatives, and then that
! instance is raised.  If the second expression is not such an instance,
! the given class is instantiated.  The argument list for the
! instantiation is determined as follows: if the second expression is a
! tuple, it is used as the argument list; if it is \code{None}, the
! argument list is empty; otherwise, the argument list consists of a
! single argument which is the second expression.  If the first
! expression is an instance object, the second expression must be
! \code{None}.
  \index{exception}
  \indexii{raising}{exception}
  
! If the first object is a string, it then raises the exception
! identified by the first object, with the second one (or \code{None})
! as its parameter.  If the first object is a class or instance,
! it raises the exception identified by the class of the instance
! determined in the previous step, with the instance as
! its parameter.
  
- If a third object is present, and it is not \code{None}, it should be
- a traceback object (see section~\ref{traceback}), and it is
- substituted instead of the current location as the place where the
- exception occurred.  This is useful to re-raise an exception
- transparently in an except clause.
- \obindex{traceback}
  
  
--- 522,563 ----
  
  If no expressions are present, \keyword{raise} re-raises the last
! expression that was active in the current scope.  If no exception has
! been active in the current scope, an exception is raised that
! indicates indicates that this is the error.
  \index{exception}
  \indexii{raising}{exception}
  
! Otherwise, \keyword{raise} evaluates the expressions to get three
! objects, using \code{None} as the value of omitted expressions.  The
! first two objects are used to determine the \emph{type} and
! \emph{value} of the exception.
! 
! If the first object is an instance, the type of the exception is the
! class of the instance, the instance itself if the value, and the
! second object must be \code{None}.
! 
! If the first object is a class, it becomes the type of the exception.
! The second object is used to determine the exception value: If it is
! an instance of the class, the instance becomes the exception value.
! If the second object is a tuple, it is used as the argument list for
! the class constructor; if it is \code{None}, an empty argument list is
! used, and any other object is treated as a single argument to the
! constructor.  The instance so created by calling the constructor is
! used as the exception value.
! 
! If the first object is a string, the string object is the exception
! type, and the second object becomes the exception value.
! 
! If a third object is present and not \code{None}, it must be a
! traceback\obindex{traceback} object (see section~\ref{traceback}), and
! it is substituted instead of the current location as the place where
! the exception occurred.  If the third object is present and not a
! traceback object or \code{None}, a \exception{TypeError} exception is
! raised.  The three-expression form of \keyword{raise} is useful to
! re-raise an exception transparently in an except clause, but
! \keyword{raise} with no expressions should be preferred if the
! exception to be re-raised was the most recently active exception in
! the current scope.
  
  
  
***************
*** 691,699 ****
  (\character{_}).
  
! Names bound by \keyword{import} statements may not occur in
! \keyword{global} statements in the same scope.
! \stindex{global}
  
- The \keyword{from} form with \samp{*} may only occur in a module scope.
  \kwindex{from}
  \stindex{from}
--- 702,710 ----
  (\character{_}).
  
! The \keyword{from} form with \samp{*} may only occur in a module
! scope.  If the wild card form of import --- \samp{import *} --- is
! used in a function and the function contains or is a nested block with
! free variables, the compiler will raise a \exception{SyntaxError}.
  
  \kwindex{from}
  \stindex{from}
***************
*** 730,736 ****
  The \keyword{global} statement is a declaration which holds for the
  entire current code block.  It means that the listed identifiers are to be
! interpreted as globals.  While \emph{using} global names is automatic
! if they are not defined in the local scope, \emph{assigning} to global
! names would be impossible without \keyword{global}.
  \indexiii{global}{name}{binding}
  
--- 741,747 ----
  The \keyword{global} statement is a declaration which holds for the
  entire current code block.  It means that the listed identifiers are to be
! interpreted as globals.  It would be impossible to assign to a global
! variable without \keyword{global}, although free variables may refer
! to globals without being declared global.
  \indexiii{global}{name}{binding}