[Python-Dev] switch in Python.

Thomas Wouters thomas@xs4all.net
2001年11月13日 11:05:10 +0100


On Tue, Nov 13, 2001 at 10:45:19AM +0100, M.-A. Lemburg wrote:
> One question: What happens if the implementation finds that x is
> not hashable ?

It _should_ propagate the error upwards, but I see now that the error gets
eaten for some reason. The runtime part of switch is very small:
 case SWITCH:
 w = POP();
 v = POP();
 x = PyDict_GetItem(w, v);
 if (!x && PyErr_Occurred())
 break;
 if (!x) {
 JUMPBY(oparg);
 continue;
 }
 JUMPBY(PyInt_AsLong(x));
 continue;
That is, PyDict_GetItem() is supposed to return NULL for missing keys, but
without setting an exception. So if an exception is set, it's a regular
error in the dict lookup, and the error is simply propagated upwards.
Oh, wait, I think I see the problem: stack underflow. The value reaching the
switch is not the one put in, when passing (e.g.) a list to 'whatis'. No
time to look at this now though.
-- 
Thomas Wouters <thomas@xs4all.net>
Hi! I'm a .signature virus! copy me into your .signature file to help me spread!

AltStyle によって変換されたページ (->オリジナル) /