[Python-checkins] CVS: python/dist/src/Python ceval.c,2.237,2.238
Jeremy Hylton
jhylton@users.sourceforge.net
Fri, 13 Apr 2001 09:51:48 -0700
Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv4675/Python
Modified Files:
ceval.c
Log Message:
Change error message raised when free variable is not yet bound. It
now raises NameError instead of UnboundLocalError, because the var in
question is definitely not local. (This affects test_scope.py)
Also update the recent fix by Ping using get_func_name(). Replace
tests of get_func_name() return value with call to get_func_desc() to
match all the other uses.
Index: ceval.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v
retrieving revision 2.237
retrieving revision 2.238
diff -C2 -r2.237 -r2.238
*** ceval.c 2001/04/13 15:42:40 2.237
--- ceval.c 2001/04/13 16:51:46 2.238
***************
*** 84,87 ****
--- 84,90 ----
#define UNBOUNDLOCAL_ERROR_MSG \
"local variable '%.200s' referenced before assignment"
+ #define UNBOUNDFREE_ERROR_MSG \
+ "free variable '%.200s' referenced before assignment" \
+ " in enclosing scope"
/* Dynamic execution profile */
***************
*** 1694,1709 ****
w = PyCell_Get(x);
if (w == NULL) {
! if (oparg < f->f_ncells)
v = PyTuple_GetItem(co->co_cellvars,
oparg);
! else
v = PyTuple_GetItem(
co->co_freevars,
oparg - f->f_ncells);
!
! format_exc_check_arg(
! PyExc_UnboundLocalError,
! UNBOUNDLOCAL_ERROR_MSG,
! v);
err = -1;
break;
--- 1697,1716 ----
w = PyCell_Get(x);
if (w == NULL) {
! if (oparg < f->f_ncells) {
v = PyTuple_GetItem(co->co_cellvars,
oparg);
! format_exc_check_arg(
! PyExc_UnboundLocalError,
! UNBOUNDLOCAL_ERROR_MSG,
! v);
! } else {
v = PyTuple_GetItem(
co->co_freevars,
oparg - f->f_ncells);
! format_exc_check_arg(
! PyExc_NameError,
! UNBOUNDFREE_ERROR_MSG,
! v);
! }
err = -1;
break;
***************
*** 2884,2892 ****
}
if (!ok) {
- char* fn = get_func_name(func);
PyErr_Format(PyExc_TypeError,
! "unbound method %s%smust be "
"called with instance as first argument",
! fn ? fn : "", fn ? "() " : "");
return NULL;
}
--- 2891,2898 ----
}
if (!ok) {
PyErr_Format(PyExc_TypeError,
! "unbound method %s%s must be "
"called with instance as first argument",
! get_func_name(func), get_func_desc(func));
return NULL;
}