[Python-Dev] Switch statement

Jim Jewett jimjjewett at gmail.com
Mon Jun 26 22:30:03 CEST 2006


In http://mail.python.org/pipermail/python-dev/2006-June/066475.html
Nick Coghlan wrote:

> (Unlike Jim, I have no problems with restricting switch statements to
> hashable objects and building the entire jump table at once - if what you want
> is an arbitrary if-elif chain, then write one!)

I haven't been clear.  I don't object to building the entire table at
once.  I object to promising that this will happen, which forbids
other implementations from using certain optimizations.

I would prefer something like:

There is no guarantee on how often or when the case statements will be
evaluated, except that it will be after the enclosing scope exists and
before the relevant test is needed.  If a case expression has side
effects, the behavior with respect to these side effects is explicitly
undefined.

-jJ


More information about the Python-Dev mailing list