I am writing a Python bytecode optimizer for a module that previously had a Cython tool-chain. While that may be deprecated by now, I encountered something strange while fiddling with it. Consider this simple piece of code:
from opcode import opmap
globals().update(opmap)
print(STORE_GLOBAL)
This should print 97, as STORE_GLOBAL
is defined in opmap
with its opcode(which is 97). Cython will tell me that STORE_GLOBAL
is not defined, though:
Error compiling Cython file:
------------------------------------------------------------
...
from opcode import opmap
globals().update(opmap)
print(STORE_GLOBAL)
^
------------------------------------------------------------
test.py:5:18: undeclared name not builtin: STORE_GLOBAL
The reason for that is pretty easy, I guess. I assume that it doesn't update the globals, so it does not know about STORE_GLOBAL
now being a variable.
Is there a unhacky way to overcome this problem?
Cheers