3 ms·
This looks like it would be pretty stable in practice. The iffiest assumption I see is that names are always ordered by first appearance. It would be worse if
by duckerude 5y ago
This looks like it would be pretty stable in practice. The iffiest assumption I see is that names are always ordered by first appearance.
It would be worse if it touched the bytecode itself, I've seen that break even in a bugfix release.
It actually works in PyPy (if you change the way dictionaries are merged so that it's 3.8-compatible). Other Python implementations could have a harder time.
A future Python release could always overhaul the bytecode system to the point this no longer makes sense. I think they'd consider it a backward compatibility break, but I'm not sure, and Python makes those fairly regularly regardless.
If the optimization were added to the standard library then it could just be kept in sync with the interpreter.