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

[ENH] Can Cython support match statement in Python? #6126

Closed
winer632 opened this issue Apr 3, 2024 · 1 comment
Closed

[ENH] Can Cython support match statement in Python? #6126

winer632 opened this issue Apr 3, 2024 · 1 comment

Comments

@winer632
Copy link

winer632 commented Apr 3, 2024

Is your feature request related to a problem? Please describe.

In my code, I would like to use the match statement. I compiled this method using Cython3.0.9 version, but got the following error.

Here is the python code

import argparse
import logging
import re
import os
import sys
import uvicorn
import time
import threading

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from datetime import datetime, timezone

from common.loggin_middleware import *
from common.server_context import ServerContext
from query_system.document_api import document
from query_system.initialize import initialize
from query_system.knowledge_api import knowledge
from query_system.message_api import message
from common.log_wrapper import *
from common.config import Config, get_config
from query_system.query_debug import server_debug, qa
from query_system.sensitive_api import sensitive
from common.log_wrapper import *

conf = get_config()
lib_path = conf.get_lib_config()
product_name, lic_path, quota_name, interval = conf.get_lic_config()
print(f"path is {lib_path} product_name is {product_name} lic_path is {lic_path} quota_name is {quota_name} interval is {interval}")
master = "https://private.ca.abc.com:8443"
slave = "https://slave.private.ca.abc.com:8443"

time_out = 30
sys.path.append(lib_path)
import _license

logger = logging.getLogger(__name__)

def read_license(file_path):
    with open(file_path, 'r') as file:
        c_lic = file.read()
    return c_lic


def auth(code):
    pid = os.getpid()
    tid = threading.get_ident()
    match code:
        case 0:
            logger.info(f"[AUTH] success pid: {pid}, tid: {tid}")
            return
        case -1:
            logger.info(f"[AUTH] invalid param pid: {pid}, tid: {tid}")
            os._exit(1)
        case -2:
            logger.info(f"[AUTH] init method error pid: {pid}, tid: {tid}")
            os._exit(1)
        case -3:
            logger.info(f"[AUTH] authentication method error pid: {pid}, tid: {tid}")
            os._exit(1)
        case _:
            print("Unknown error")
            os._exit(1)
......
......

The following is the error message

[1/1] Cythonizing /data/wisdom-vault/app/query_server.py

Error compiling Cython file:
------------------------------------------------------------
...
def auth(code):
    pid = os.getpid()
    tid = threading.get_ident()
    match code:
          ^
------------------------------------------------------------

app/query_server.py:51:10: Syntax error in simple statement list
Traceback (most recent call last):
  File "/data/wisdom-vault/setup.py", line 43, in <module>
    setup(ext_modules=cythonize(f_name),
                      ^^^^^^^^^^^^^^^^^
  File "/data/miniconda3/lib/python3.11/site-packages/Cython/Build/Dependencies.py", line 1154, in cythonize
    cythonize_one(*args)
  File "/data/miniconda3/lib/python3.11/site-packages/Cython/Build/Dependencies.py", line 1321, in cythonize_one
    raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: /data/wisdom-vault/app/query_server.py

Describe the solution you'd like.

Can Cython support match statement in Python?

Describe alternatives you've considered.

NA

Additional context

Python version 3.11.5
Cython version 3.0.9

@da-woods
Copy link
Contributor

da-woods commented Apr 3, 2024

#4029

@da-woods da-woods closed this as not planned Won't fix, can't repro, duplicate, stale Apr 3, 2024
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