• Guido van Rossum's avatar
    Patch by Tim Peters: · 87460821
    Guido van Rossum yazdı
    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.]
    87460821
Adı
Son kayıt (commit)
Son güncelleme
..
Makefile Loading commit data...
Python.h Loading commit data...
abstract.h Loading commit data...
bitset.h Loading commit data...
bufferobject.h Loading commit data...
cStringIO.h Loading commit data...
ceval.h Loading commit data...
classobject.h Loading commit data...
cobject.h Loading commit data...
compile.h Loading commit data...
complexobject.h Loading commit data...
config.h Loading commit data...
dictobject.h Loading commit data...
errcode.h Loading commit data...
eval.h Loading commit data...
fileobject.h Loading commit data...
floatobject.h Loading commit data...
frameobject.h Loading commit data...
funcobject.h Loading commit data...
graminit.h Loading commit data...
grammar.h Loading commit data...
import.h Loading commit data...
intobject.h Loading commit data...
intrcheck.h Loading commit data...
listobject.h Loading commit data...
longintrepr.h Loading commit data...
longobject.h Loading commit data...
marshal.h Loading commit data...
metagrammar.h Loading commit data...
methodobject.h Loading commit data...
modsupport.h Loading commit data...
moduleobject.h Loading commit data...
mymalloc.h Loading commit data...
mymath.h Loading commit data...
myproto.h Loading commit data...
myselect.h Loading commit data...
mytime.h Loading commit data...
node.h Loading commit data...
object.h Loading commit data...
objimpl.h Loading commit data...
opcode.h Loading commit data...
osdefs.h Loading commit data...
parsetok.h Loading commit data...
patchlevel.h Loading commit data...
pgenheaders.h Loading commit data...
pydebug.h Loading commit data...
pyerrors.h Loading commit data...
pyfpe.h Loading commit data...
pystate.h Loading commit data...
pythonrun.h Loading commit data...
pythread.h Loading commit data...
rangeobject.h Loading commit data...
rename1.h Loading commit data...
rename2.h Loading commit data...
sliceobject.h Loading commit data...
stringobject.h Loading commit data...
structmember.h Loading commit data...
sysmodule.h Loading commit data...
thread.h Loading commit data...
token.h Loading commit data...
traceback.h Loading commit data...
tupleobject.h Loading commit data...