-
Notifications
You must be signed in to change notification settings - Fork 64
Bring 'else' back? #89
Comments
I can see the arguments for
Also, lets not forget that disallowing |
Also, ambiguity about the "correct" indentation level for |
I prefer |
|
@0312birdzhang: I think at this point we should strive for a discussion on arguments rather than personal preferences, so as to effectively move forward with this. First, I agree with @Delta456 in that |
If we really want |
I totally agree with @brandtbucher and feel he summarised the main arguments quite neatly. The only argument I can see that really is in favour of If we were to bring match t:
case P1():
...
else:
... I see another argument in favour of I am wondering whether the idea of having an |
@Delta456 Could you briefly explain what you mean by behaviour like Go's? Not everyone here is familiar with Go. |
See this |
What specific aspect of Go's behavior are you referring to? Given that the underscore is already a valid name in Python, and there is an established convention of using it for values we want to ignore (such as in tuple unpacking), we can't radically alter the definition of it without breaking a lot of programs. |
I am refering that I know that so I think we should go with |
As @Delta456 alluded to,
Right now my vote is for |
@Delta456 and @elimisteve, ‘_’ is used as a wildcard in the rest of the pattern matching syntax, ‘case _’ is just a special use of that. Read the README.md in this repo. |
It seems like the discussion here is more and more circling about a different issue. Instead of discussing The issue at hand is much rather whether we want/need an I see no reason, however, to bring in |
Yes
Yes I want to conclude that |
This really would be easier if we could agree on how to indent I really think it should be aligned with 'case' (similar to how people indent 'default' in C switches); I believe only @Tobias-Kohn disagrees. But since it really is just a catch-all case, I think it should align with the cases -- otherwise people might wonder that it has some other semantics (given that |
If we're adding it for completeness alone, then it should "obviously" match the other compound statements and be at that outer level. But I agree that, logically, it is a case, and should be indented with those... but why disguise a case as Eh, I've said all I have to say. |
FYI, some points in favor of adding "else":
|
match t:
case P1():
case P2():
...
case P3():
else: # it will go to else when none of the cases match
else: # after completion of match This can hopefully solve the problem as @brandtbucher says for |
@Delta456 you are a true Solomon. |
@gvanrossum lol! Its an honor! |
Having given it some thought, I still believe that the To put it differently, the way I think of it might be expressed roughly as: try: # match
case A:
...
case B:
...
except NoMatch:
# this is the else-clause I would not seriously consider allowing it on both level as suggested by @Delta456, and having slightly different semantics makes it even worse. The mental burdon is just way too high. |
Many including me said
From this perspective, +1 @Tobias-Kohn |
@Tobias-Kohn I know why you disagree but we need an
I suggested following this rule only. |
@Tobias-Kohn How would an Every compound statement has an else when that |
@DimitrisJim I certainly agree with that. I am actually not advocating to have an
This is a fair and important point, nicely put (highlights from me). It also answers @Delta456's suggestion to have two possible |
Some while ago we had considered to have a one-off syntax, but decided to put it into the 'deferred ideas' section. Now, I absolutely do not want to reopen that discussion: the one-off syntax is an excellent candidate for the 'deferred ideas' to be considered later. However, if a future PEP proposes to include the one-off syntax, they will probably want to have an So, if we combine the one-off idea with an match x:
case P: ...
else:
... you could have something like: match x as P:
...
else:
... or, using the alternative synax: if match x as P:
...
else:
... Having the Let me reiterate: this is not a votum to bring the one-off syntax back on the table, but rather another argument why I feel that the All that being said, adding |
I propose that we reject this idea. The reasoning should be
(*) Not to mention disagreement. :-) |
Let's add that to the PEP - one reason we didn't go with else is the difficulty of getting agreement on the level of indentation. |
There were several commenters on today's revealing of the PEP on python-dev who want an
else
clause instead ofcase _:
to enter final catch-all block. It's not terrible. If we do this I propose it should be indented with thecase
clauses:I'm trying to hold this off a little longer, but it may be an easy thing to give.
The text was updated successfully, but these errors were encountered: