[Python-Dev] Switch statement - handling errors

Guido van Rossum guido at python.org
Wed Jun 28 06:40:35 CEST 2006

On 6/27/06, Jim Jewett <jimjjewett at gmail.com> wrote:
> Bad Case Option (5) -- ad hoc mixture
> -------------------------------------
> Pick an arbitrary set of rules, and follow it.
> Guido is currently leaning towards this, with the rules being "freeze
> at definition", raise for unhashable, ignore later changes, undecided
> on overlapping ranges.
> The disadvantage is that people can "cheat" with non-constant
> expressions.  Sometimes, this will work out great.  Sometimes it will
> lead to nasty non-localized bugs.  We have to explain exactly which
> cheats are allowed, and that explanation could get byzantine.

A solution that is often offered in situations like this: Pychecker
(or something like it) can do a much more thorough check. It should be
easy for Pychecker to keep track of the constancy of variables.

IMO my proposal has no cheats. It has well-defined semantics. Maybe
not the semantics you'd like to see, but without ESP built into the
compiler that's impossible. If you stick to the simple rule "constants
only" then you won't see any semantics surprises. Just stay away from
anything where you're not sure whether it's really a constant, and
you'll be fine. If on the other hand you want to explore the
boundaries of the semantics, we'll give you one simple rule, and you
can verify that that rule is indeed all there is.

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-Dev mailing list