TST: Adjust tests and require_geos decorator implementation for docstring indent stripping in Python 3.13#1938
Conversation
Pull Request Test Coverage Report for Build 7929712003Details
💛 - Coveralls |
|
@musicinmybrain Thanks for looking into this! We don't yet have CI for Python 3.13, but if you can test it on your end that this passes, I think we are certainly happy to already merge it.
That's maybe a bug to report to cpython? If I try with one of our docstrings with a |
|
I tried originally to form a simplified reproducer. For example, if I write class SomeClass:
def func(self):
"""Docstring that will be mocked.
A multiline.
.. note:: 'func' requires at least GEOS {version}.
Some description.
"""and then do I get what I would expect, Now that I’m returning to this after a few days, I see exactly what’s happening. The docstring modification algorithm runs on the introspected (i.e. after byte-compilation) docstring, and it assumes the indentation level is at least Lines 39 to 50 in dba2704 It seems like the choice of |
c85c1aa to
b50a99e
Compare
|
I began by force-pushing with an improved comment reflecting the above analysis. |
This fixes “extra” indentation before the GEOS version note in Python 3.13, where the compiler strips indentation from docstrings.
This approach appears to work as expected in my testing on Python 3.13 and 3.12. Updating this PR. |
|
If you wanted to find the indent more concisely without an explicit Python loop (in exchange for adding an otherwise-unnecessary temporary copy of part of the docstring), you could instead write: # Figure out the indentation level
indent = len(doc) - len(doc[position:].lstrip(" ")) - position |
|
Sorry for the slow follow-up, but rebased and still passing, so going to merge this now (and include in shapely 2.0.3). Thanks again! |
…ring indent stripping in Python 3.13 (shapely#1938)
…ring indent stripping in Python 3.13 (#1938)
Fixes #1937.
I’m not thrilled with this, particularly with the unexplained
extra_indent, but it does successfully match the behavior in Python 3.13.0a1.For reference, here’s the current implementation of
_PyCompile_CleanDoc():https://github.com/methane/cpython/blob/9c03215a3ee31462045b2c2ee162bdda30c54572/Python/compile.c#L7816