>From past rumblings, I gather that Python is moving towards preventing __builtins__ from being shadowed. I would like to know what you guys think about going ahead with that idea whenever the -O optimization flag is set. The idea is to scan the code for lines like: LOAD_GLOBAL 2 (range) and, if the name is found in __builtins__, then lookup the name, add the reference to the constants table and, replace the code with something like: LOAD_CONST 5 (<type 'range'>) The opcode replacement bypasses module level shadowing but leaves local shadowing intact. For example: modglob = 1 range = xrange def f(list): for i in list: # local shadowing of 'list' is unaffected print ord(i) # access to 'ord' is optimized j = modglob # non-shadowed globals are unaffected k = range(j) # shadowing of globals is ignored I've already tried out a pure python proof-of-concept and it is straightforward to recode it in C and attach it to PyCode_New(). Raymond Hettinger
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4