diff --git a/pep-0329.txt b/pep-0329.txt index 76e65458e..e3779ce32 100644 --- a/pep-0329.txt +++ b/pep-0329.txt @@ -154,8 +154,9 @@ Here is a sample implementation for codetweaks.py:: """ import __builtin__ env = vars(__builtin__).copy() + stoplist = dict.fromkeys(stoplist) if builtin_only: - stoplist.extend(f.func_globals) + stoplist.update(f.func_globals) else: env.update(f.func_globals) @@ -214,19 +215,25 @@ Here is a sample implementation for codetweaks.py:: elif type(v) in (type, ClassType): bind_all(v, builtin_only, stoplist, verbose) + + def f(): pass + try: + f.func_code.code + except AttributeError: # detect non-CPython environments + bind_all = lambda *args, **kwds: 0 + del f + import sys bind_all(sys.modules[__name__]) # Optimizer, optimize thyself! - -The final code should have some minor embellishments: +Note the automatic detection of a non-CPython environment that does not +have bytecodes [3]_. In that situation, the bind functions would simply +return the original function unchanged. This assures that the two +line additions to library modules do not impact other implementations. -* Automatic detection of a non-CPython environment that does not have - bytecodes [3]_. In that situation, the bind functions would simply - return the original function unchanged. This assures that the two - line additions to library modules do not impact other implementations. +The final code should add a flag to make it easy to disable binding. -* Add a flag to make it easy to disable binding. References