[Python-ideas] Yet Another Switch-Case Syntax Proposal

Andrew Barnert abarnert at yahoo.com
Fri Apr 18 07:03:11 CEST 2014


On Apr 17, 2014, at 14:53, Oleg Broytman <phd at phdru.name> wrote:

> While I don't think it's a good addition for Python...
> 
> On Thu, Apr 17, 2014 at 02:41:56PM -0700, Andrew Barnert <abarnert at yahoo.com.dmarc.invalid> wrote:
>> On Apr 17, 2014, at 12:14, "Lucas Malor" <7vsfeu4pxg at snkmail.com> wrote:
>> 
>>> switch_stmt ::=  "switch" switch_expr "case" case_expr ":" suite
>>>   ("case" | "elcase" case_expr ":" suite)*
>>>   ["else" ":" suite]
>>> switch_expr ::= expression
>>> case_expr ::= expression_list
>> 
>>> - if case_expr is a tuple, the case suite will be executed if switch_expr is a member of the tuple
>> 
>> So there's no way to switch on a tuple?
> 
>   A tuple can be a member of a bigger tuple:
> 
>>>> (1, 'b') in ((1, 'a'), (1, 'b'), (1, 'a', 'b'))
> True

Well, yeah, but if you want to match (1, 'b') you'd have to write case ((1, 'b'),). Which is bad for static cases, and even worse for dynamic ones.


More information about the Python-ideas mailing list