-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Add maybe keyword. BDFL says, we deliver!
#131982
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think maybe should depend on the mood of the interpreter and thus a random.random() should be added as well to have unpredictable branches
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Maybe.
|
Approve |
| invalid_maybe_stmt: | ||
| | "maybe" named_expression NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") } | ||
| | a="maybe" a=named_expression ':' NEWLINE !INDENT { | ||
| RAISE_INDENTATION_ERROR("expected an indented block after 'if' statement on line %d", a->lineno) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| RAISE_INDENTATION_ERROR("expected an indented block after 'if' statement on line %d", a->lineno) } | |
| RAISE_INDENTATION_ERROR("expected an indented block after 'maybe' statement on line %d", a->lineno) } |
|
We might want to add more pythonic keywords for old I propose: maybe answer == 42:
print("Found the meaning")
ormay answer == 41:
print("So close")
otherwise:
print("Keep searching") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please include a What's New entry and NEWS file.
|
When you're done making the requested changes, leave the comment: |
Perfect feature to be added in pytest lib |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice use of soft keywords.
Please update pattern matching guards to allow the new syntax:
>>> match match:
... case case maybe maybe:
... ...As well as ternary maybe:
>>> maybe maybe maybe else maybe|
|
||
| // maybe_stmt: | ||
| // | invalid_maybe_stmt | ||
| // | "maybe" named_expression ':' block elif_stmt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // | "maybe" named_expression ':' block elif_stmt | |
| // | "maybe" named_expression ':' block elmaybe_stmt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have no idea how tempted I am to add the release blocker label.
Don't worry I will do it for you 🤣 The steering council will resist! |
Btw: You laugh but I am moderately confident the PEG parser can support this atrocity like Atlas holding the world 🌍🙂 |
This would be the end of Black as we know it. Maybe. |
|
Finally, Python achieves peak performance by just skipping the hard parts. Truly an But honestly, at this point, I don't want Python to handle exceptions. I want it to handle my emotions. |
|
I believe that functions using |
I had to try: @sobolevn I pushed a commit to this PR. It's not on the PEP ( 😆 ) but @brandtbucher has a way to nerdsnipe me :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work!
|
Thanks everyone, I hope we had fun on this 1st April together :) |
|
Long live the BDFL. |
|
The service of the SC will be continued. |


It works!
https://www.youtube.com/watch?v=wgxBHuUOmjA
Happy 1st April, everyone!