A.2 Patched functions
When Psyco starts, it replaces a few functions from the __builtin__ and sys modules with a version of its own. This trick fails if you made a copy of one of these functions elsewhere before Psyco has a chance to replace it, because the old copy will not behave properly in the presence of Psyco.
globals |
|
locals |
(1) |
vars |
(1) when called with no argument |
dir |
(1) when called with no argument |
eval |
(1)(2) when called with a single argument |
execfile |
(1) when called with a single argument |
input |
(1) |
sys._getframe |
(3) |
Notes:
- (1)
- A function run by Psyco has no native locals dictionary. Psyco 1.3 and above can emulate it properly if a certain optimization (early dead variable deletion) is disabled. Psyco should turn off this optimization automatically for functions where it detects a call to one of the above built-in functions, but this detection is a guess over the function's bytecode. It means that certain indirect calls can be missed. If this occurs at run-time, a psyco.warning is issued and the emulated locals dictionary is empty.
- (2)
- Note that it is common to find Python programs that use dynamic code evaluation for an effect that can be obtained by calling an ad-hoc built-in function instead. For example,
eval('self.'+attr)
is better written as getattr(self, attr)
and exec 'import '+module
is better written as __import__(module, globals(), locals(), [])
.
- (3)
- Frames corresponding to Psyco-evaluated functions are incomplete, as described in section A.1.
Additionally, the exec
statement is not supported yet, as seen in section A.3.