0
0
mirror of https://github.com/python/cpython.git synced 2024-12-01 11:15:56 +01:00
cpython/Include
Guido van Rossum 8746082175 Patch by Tim Peters:
Introduce a new builtin exception, UnboundLocalError, raised when ceval.c
tries to retrieve or delete a local name that isn't bound to a value.
Currently raises NameError, which makes this behavior a FAQ since the same
error is raised for "missing" global names too:  when the user has a global
of the same name as the unbound local, NameError makes no sense to them.
Even in the absence of shadowing, knowing whether a bogus name is local or
global is a real aid to quick understanding.

Example:

D:\src\PCbuild>type local.py
x = 42

def f():
    print x
    x = 13
    return x

f()

D:\src\PCbuild>python local.py
Traceback (innermost last):
  File "local.py", line 8, in ?
    f()
  File "local.py", line 4, in f
    print x
UnboundLocalError: x

D:\src\PCbuild>

Note that UnboundLocalError is a subclass of NameError, for compatibility
with existing class-exception code that may be trying to catch this as a
NameError.  Unfortunately, I see no way to make this wholly compatible
with -X (see comments in bltinmodule.c):  under -X, [UnboundLocalError
is an alias for NameError --GvR].

[The ceval.c patch differs slightly from the second version that Tim
submitted; I decided not to raise UnboundLocalError for DELETE_NAME,
only for DELETE_LOCAL.  DELETE_NAME is only generated at the module
level, and since at that level a NameError is raised for referencing
an undefined name, it should also be raised for deleting one.]
1999-06-22 14:47:32 +00:00
..
abstract.h
bitset.h
bufferobject.h
ceval.h
classobject.h
cobject.h
compile.h
complexobject.h
config.h
cStringIO.h
dictobject.h
errcode.h
eval.h
fileobject.h
floatobject.h
frameobject.h
funcobject.h
graminit.h
grammar.h
import.h
intobject.h
intrcheck.h
listobject.h
longintrepr.h
longobject.h
Makefile
marshal.h
metagrammar.h
methodobject.h
modsupport.h
moduleobject.h
mymalloc.h
mymath.h
myproto.h
myselect.h
mytime.h
node.h
object.h
objimpl.h
opcode.h
osdefs.h
parsetok.h
patchlevel.h Set PATCHLEVEL and PY_VERSION (string version only) to 1.5.2+ to 1999-06-09 15:16:18 +00:00
pgenheaders.h
pydebug.h
pyerrors.h Patch by Tim Peters: 1999-06-22 14:47:32 +00:00
pyfpe.h
pystate.h
Python.h
pythonrun.h
pythread.h Conform to standard boilerplate. 1999-03-24 19:02:09 +00:00
rangeobject.h
rename1.h
rename2.h
sliceobject.h
stringobject.h
structmember.h
sysmodule.h
thread.h Adding thread.h -- unused but for b/w compatibility. 1999-03-22 22:25:39 +00:00
token.h
traceback.h
tupleobject.h