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

Add match and case syntax Python 3.10 #237

Closed
wants to merge 2 commits into from
Closed

Add match and case syntax Python 3.10 #237

wants to merge 2 commits into from

Conversation

cdce8p
Copy link

@cdce8p cdce8p commented May 1, 2021

Python 3.10 will add pattern matching with the match and case keywords.
This PR adds a regular expression to recognize them as keyword.control.flow.python if present in a match statement. Since they are only soft keywords and still allowed as normal variable names, it's not possible to simply add them to the list of the other keywords.

Closes: #235

Example

def http_error(status: int):
    match status:
        case 400:
            return "Bad request"
        case 404:
            return "Not found"
        case 418:
            return "I'm a teapot"
        case _:
            return "Default case, unreachable"

Screen Shot 2021-05-01 at 15 21 44

@cdce8p cdce8p changed the title Add match and case syntax Add match and case syntax Python 3.10 May 1, 2021
@norabelrose
Copy link

norabelrose commented Jan 29, 2022

It's no super clear to me why this PR is "failing" the CI tests. When I look at the logs it looks like none of the actual MagicPython tests fail, but later some bizarre error is thrown from inside Atom. When I clone this branch and run the tests myself, they all pass.

Can we try to get this merged soon? Does something need to be fixed with the CI?

@ConstantinGahr
Copy link

ConstantinGahr commented Mar 17, 2022

Hi, whats the current status of this pull request? I'd love to have match case statements.

@tiararosebiezetta
Copy link

tiararosebiezetta commented Mar 25, 2022

I am waiting for this pull request too.

@elprans elprans requested a review from vpetrovykh Mar 25, 2022
@ruthus18
Copy link

ruthus18 commented Apr 15, 2022

Any updates?

@spagh-eddie
Copy link

spagh-eddie commented Apr 25, 2022

I too would like this

@wszqkzqk
Copy link

wszqkzqk commented May 31, 2022

Nice feature!

@cdce8p
Copy link
Author

cdce8p commented May 31, 2022

I no longer need this myself. VS Code and Pylance in particular have added syntax highlighting for match / case a while ago. If someone else would like to continue with the PR, feel free to reuse it.

Just to note, although I believe the regex is quite good already. There might still be some edge cases left which aren't covered. I just haven't used it in a long time.

@cdce8p cdce8p closed this May 31, 2022
@cdce8p cdce8p deleted the add-match-case branch May 31, 2022
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

Successfully merging this pull request may close these issues.

7 participants