Possible bug in `re` module in Python 3.11?

I would like to ask for your guidance as I’m entirely sure whether the problem I’m experiencing should be posted in CPython’s repo as a bug issue.
I’ve tried using the newly released Python 3.11 interpreter in some of my projects and one of them failed to start with “RuntimeError: invalid SRE code” error.

Looking into implementation of one of the dependencies I’ve found out that the issue has been found out by a maintainer and fixed (Pydicom not running under Python 3.11 · Issue #1658 · pydicom/pydicom · GitHub).
It looks like this particular regexp caused the re.compile() method to raise:


I’ve checked and this hasn’t been an issue in all previous Python interpreter versions, starting from 3.6 (the oldest I’ve checked).
What’s more the regex is correctly recognized and does not cause any issues in other regexp implementations, e.g. the online tool https://regex101.com/

Could somebody help me decide whether this is indeed a bug?

Best regards,
Piotr Waszkiewicz

1 Like

Maybe @storchaka knows, as the error looks similar to this bug: Internal error when compile RE with conditional expression referring to not defined group · Issue #91700 · python/cpython · GitHub

It is a different bug.

Thank you for your input, I’ve already filled in a bug report: Python 3.11 `re.compile` raises SRE code error for valid regex. · Issue #98740 · python/cpython · GitHub