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

[BUG] Unsupport match...case... statement when compiling *.py #5755

Closed
DawnEver opened this issue Oct 8, 2023 · 1 comment
Closed

[BUG] Unsupport match...case... statement when compiling *.py #5755

DawnEver opened this issue Oct 8, 2023 · 1 comment

Comments

@DawnEver
Copy link

DawnEver commented Oct 8, 2023

Describe the bug

match...case... statement, proposed in PEP 634: Structural Pattern Matching,provides pattern matching process for users like switch statement in C/C++.

However, this statement is not supported in current Cython.

A minimal example is as following to reproduce the issue:

Code to reproduce the behaviour:

# Minimal example to reproduce the issue
a=1
match a:
    case 1:
        print("1")
    case _:
        print("2")
"""
>>> python .../test.py
1

>>> cython .../test.py
Error compiling Cython file:
------------------------------------------------------------
...
# minimal example to reproduce the issue
a=1
match a:
      ^
------------------------------------------------------------

.../test.py:3:6: Syntax error in simple statement list
"""

Expected behaviour

Any solutions or suggestions?

If it is a bug, I am trying to fix this bug if possible.

OS

macOS

Python version

3.10.12

Cython version

3.0.2 and 3.0.3

Additional context

My Analysis

So I trace back to the function def p_simple_statement_list(s, ctx, first_statement = 0) in ./Cython/Compiler/Parsing.py,which raise the syntax error. The only call appears in the function def p_statement(s, ctx, first_statement = 0) in the same file.

...
elif s.sy == 'include':
    if ctx.level not in ('module', 'module_pxd'):
        s.error("include statement not allowed here")
...
elif s.sy == 'for':
    return p_for_statement(s)
elif s.sy == 'with':
    return p_with_statement(s)
...

This function deals with different statements according to prefixs. I think p_match_statement and p_case_statement are needed to resolve this statement.

Also, I searched 'match' globally in the project, but found nothing. It seems that match statement is not considered in current cython.

I am trying to fix this bug now if possible.

@da-woods
Copy link
Contributor

da-woods commented Oct 8, 2023

Duplicate #4029.

It just isn't implemented yet in any Cython release. In that ticket you'll find links to a branch where it is implemented in full, but this hasn't yet been reviewed and merged.

@da-woods da-woods closed this as not planned Won't fix, can't repro, duplicate, stale Oct 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants