* Protect the stoplist from mutation (suggested by JvR).

* Replace the comment on non-CPython implementations with working code.
  Should help those who could not comprehend the efforts that were made
  to support non-CPython environments automatically, with no performance
  penalty.
This commit is contained in:
Raymond Hettinger 2004-04-20 11:01:35 +00:00
parent a8b8df4485
commit 5b706be0c0
1 changed files with 15 additions and 8 deletions

View File

@ -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:
* Automatic detection of a non-CPython environment that does not have
bytecodes [3]_. In that situation, the bind functions would simply
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.
* Add a flag to make it easy to disable binding.
The final code should add a flag to make it easy to disable binding.
References