Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

for-elif-else, try-except-elif-else-finally & while-elif-else #17

Closed
nineteendo opened this issue Jul 1, 2024 · 14 comments
Closed

for-elif-else, try-except-elif-else-finally & while-elif-else #17

nineteendo opened this issue Jul 1, 2024 · 14 comments

Comments

@nineteendo
Copy link
Owner

nineteendo commented Jul 1, 2024

Proposal:

Example:

for target in iter:
    expr1()
elif cond:
    expr2()
else:
    expr3()

try:
    expr1()
except exception:
    expr2()
elif cond:
    expr3()
else:
    expr4()
finally;
    expr5()

while cond1:
    expr1()
elif cond2:
    expr2()
else:
    expr3()

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

@nineteendo
Copy link
Owner Author

@dg-pb, I've actually been thinking about this as well :). I would indeed restrict your proposal to for-elif-else and while-elif-else only. I'll try to work on an implementation, but this probably needs a PEP before it can be implemented.

@dg-pb
Copy link

dg-pb commented Jul 1, 2024

I would say that adding try-except-elif-else[-finally] at the same time is sensible.

@nineteendo nineteendo changed the title for-elif-else and while-elif-else for-elif-else, try-except-elif-else-finally & while-elif-else Jul 1, 2024
@nineteendo
Copy link
Owner Author

@nineteendo
Copy link
Owner Author

Which regex were you using to find examples?

@dg-pb
Copy link

dg-pb commented Jul 2, 2024

I have mentioned in the PR that I might work on this myself.

For now I am introducing the idea, slowly gauging feedback and evaluating if it is needed.

If it reaches implementation stage and I decide not to take it myself, I will let you know.

@nineteendo
Copy link
Owner Author

I was more thinking about a proof of concept, which allows you to discover potential issues and what modifications are necessary.
Additionally, the implementation can already be discussed on Discourse.

@dg-pb
Copy link

dg-pb commented Jul 3, 2024

I don't think prematurely jumping into implementation is worthwhile.

  1. There are no potential issues here. Nothing to be discovered. Proposal can not be less unambiguous. It is a straight forward implementation without backwards compatibility or any other technical issues.
  2. If an idea is not syntax related, then the risk that all work will go to waste is lower. Syntactic changes are much more difficult to be accepted. The most important part here is communication with community.

@nineteendo
Copy link
Owner Author

How about allowing statements after else, like in C?

try:
except:
else try:
except:

@dg-pb
Copy link

dg-pb commented Jul 3, 2024

It is what Chris has identified: https://discuss.python.org/t/while-elif-else-for-elif-else-try-except-elif-else/57208/16

try:
except:
else:
except:

There is no need for second try it makes sense and works with else only.

But this is different and orthogonal idea which has nothing to do with current proposal.

And this one I would expect would be even more difficult to be accepted than what I am proposing.

@dg-pb
Copy link

dg-pb commented Jul 3, 2024

But I might be wrong.

It could very well be that community would like it more than my proposal.

Maybe someone should propose it just to see what happens.

Personally, I have no strong feelings about try:except:else:except:else:except:else.

@nineteendo
Copy link
Owner Author

nineteendo commented Jul 3, 2024

The cool thing about allowing a statement after else, is that it could be any statement;

if ...:
    pass
else while ...:
    pass

if ...:
    pass
else pass

It might make it easier to get your proposal accepted, to allow simplifying this:

while ...:
    pass
else if ...:
    pass

@dg-pb
Copy link

dg-pb commented Jul 3, 2024

How long do you think it would take to implement what I am proposing?

And how long do you think it would take to implement what you are proposing?

@dg-pb
Copy link

dg-pb commented Jul 4, 2024

Which regex were you using to find examples?

I just used python re in combination with more_itertools.windowed

@nineteendo
Copy link
Owner Author

This is going nowhere.

@nineteendo nineteendo closed this as not planned Won't fix, can't repro, duplicate, stale Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants