Skip to content

Fix import cyaron on Python 3.15 - #187

Open
b84330808 wants to merge 1 commit into
luogu-dev:masterfrom
b84330808:fix-xeger-import-py315
Open

b84330808 wants to merge 1 commit into
luogu-dev:masterfrom
b84330808:fix-xeger-import-py315

Conversation

@b84330808

Copy link
Copy Markdown

Fixes #185.

On Python 3.15, import cyaron fails. cyaron/string.py imports xeger, and xeger 0.4.0 (the latest release; the repo hasn't changed since 2023) does:

try:
    import sre_parse
except ImportError:
    sre_parse = re.sre_parse

Python 3.15 removed the sre_parse module, and re.sre_parse doesn't exist on 3.11+ either, so the import ends with AttributeError: module 're' has no attribute 'sre_parse'.

This keeps the xeger dependency and only changes how it's imported: if import xeger raises that AttributeError, cyaron.string registers re._parser (the same parser, renamed in 3.11) as sre_parse, imports xeger, then removes that entry again. On 3.6–3.14 the first import xeger still succeeds, so nothing changes there.

The new test test_import_without_sre_parse blocks sre_parse and re-imports cyaron.string, so it reproduces the 3.15 failure on 3.11+ as well.

Test results (Windows):

  • Python 3.15.1: before, import cyaron and python unit_test.py fail with the error above; after, all 54 tests pass.
  • Python 3.11: the new test fails without the string.py change and passes with it; the full suite passes.

test_output_gen_time_limit_not_exceeded (0.5 s limit) sometimes timed out on a busy machine with or without this change; it passed on rerun.

CI doesn't run 3.15 yet. I can add it in a follow-up if you want.

I used Claude Code to write this change.

xeger <= 0.4.0 imports the sre_parse module, which Python 3.15 removed,
and its fallback (re.sre_parse) does not exist on Python 3.11+ either, so
importing cyaron raised AttributeError. When that import fails, expose
re._parser as sre_parse for the duration of the xeger import.

Fixes luogu-dev#185

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

最新版 Python 3.15.0 无法运行 CYaRon 库

1 participant