delph-in / pydelphin

Python libraries for DELPH-IN
https://pydelphin.readthedocs.io/
MIT License
79 stars 27 forks source link

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

Closed goodmami closed 11 months ago

goodmami commented 11 months ago

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

https://github.com/delph-in/pydelphin/blob/33415cf45c1de47a9d895565062ef4ca731a378e/delphin/repp.py#L634-L636

These are deprecated as of 3.11:

https://github.com/python/cpython/issues/91308

A stopgap solution is to change the import from sre_parse to re._parser, similar to what Lark did: https://github.com/lark-parser/lark/commit/1b62465068fe95436d1e83839b522b18f84124f5

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

goodmami commented 11 months ago

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 https://github.com/python/cpython/issues/91524) which involved a change in the shape of the return value of parse_template().