Stuart,

thanks for clearly laying out the issue and coming up with a patch.

So, there's the "old style" cleandoc output generated by Python 3.12,
a "new style" output for the same function in 3.13 (stripping more
whitespace), and the patch then introduces a third option that
produces the same output under both 3.12 and 3.13 but doesn't match
the "native" output of either one.

Short term, adding the patch eliminates the issue introduced by the
changes to the docstring handling in 3.13. Unfortunately, it also
seems to require keeping the patch around after the transition from
3.12 to 3.13 is complete, even though the problem is tied to the
transition between these specific versions. Given that trixie is to
ship with 3.13 as the sole supported Python version (and work on that
seems to be progressing nicely), once 3.12 gets dropped and all
Python packages rebuilt for 3.13-only, the performance issues would
be history even if no action were taken on the ply end.

Looking at the cleandoc functions in inspect.py [1] and compile.c
[2], the only documented difference between them seems to be the
latter not removing leading and trailing empty lines. Is there any
reason the _normalize function in your patch couldn't mimick 3.13's
inspect.cleandoc [1], minus the removal of empty lines, to produce
output compatible with 3.13's compile.c under both 3.12 and 3.13?
That way, once 3.12 is dropped from the supported Python version in
Debian, the patch in ply could be dropped as well.


[1]https://github.com/python/cpython/blob/b93b7e566e5a4efe7f077af2083140e50bd2b08f/Lib/inspect.py#L788
[2]https://github.com/python/cpython/blob/8cd7f8bf8d6b62f30a8bba1f968eb0c593a8781a/Python/compile.c#L1408

Attachment: pgpEHlKH8cR8B.pgp
Description: OpenPGP digital signature

Reply via email to