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

Stop using undocumented Python function sre_parse.parse_template() #378

Closed
goodmami opened this issue Dec 9, 2023 · 1 comment
Closed
Labels

Comments

@goodmami
Copy link
Member

goodmami commented Dec 9, 2023

PyDelphin currently uses sre_parse.parse_template() for parsing the capturing groups of regular expressions:

pydelphin/delphin/repp.py

Lines 634 to 636 in 33415cf

def _get_segments(replacement: str, _re):
# parse_template() is an undocumented function in the standard library
groups, literals = parse_template(replacement, _re)

These are deprecated as of 3.11:

python/cpython#91308

A stopgap solution is to change the import from sre_parse to re._parser, similar to what Lark did: lark-parser/lark@1b62465

This could be the reason tests are failing for Python 3.12.

@goodmami goodmami added the bug label Dec 9, 2023
goodmami added a commit that referenced this issue Dec 9, 2023
@goodmami
Copy link
Member Author

This could be the reason tests are failing for Python 3.12

Not entirely. This is the risk of using non-public functions. In Python 3.12, an optimization was made to re.sub() (see python/cpython#91524) which involved a change in the shape of the return value of parse_template().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant