Support abbreviations in property summaries#683
Open
Mr0grog wants to merge 2 commits intonumpy:mainfrom
Open
Conversation
This addresses one of the issues in numpy#299, where autosummary supports a set of well-known abbreviations in the middle of the first sentence of a docstring being summarized. The corresponding summarization logic here (used for properties listed in an "Attributes" section) does not support those abbreviations. This simply updates the logic to match what `sphinx.ext.autosummary` does.
Mr0grog
commented
Apr 30, 2026
Comment on lines
+1305
to
+1310
| @property | ||
| def multiline_single_sentence(self): | ||
| """This is a | ||
| sentence.""" | ||
| return | ||
|
|
Author
There was a problem hiding this comment.
I added this example because the sentence-splitting regex used in sphinx.ext.autosummary was a little different, and caused some subtle issues here. This example was helpful in differentiating multiline behavior with and without a single period and multiple periods.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This addresses one of the issues in #299, where sphinx.ext.autosummary supports a set of well-known abbreviations (e.g. “e.g.” 😉) in the first sentence of a docstring that is being summarized, but Numpydoc does not.
This only comes into play with properties that are listed in a class’s “Attributes” section. When Numpydoc tries to get the first sentence of a property’s docstring, it gets tripped up by abbreviations with periods and ends the summary after the abbreviation instead of at the actual end of the sentence:
Renders the summary of the property as ending with “i.e.”:
Open Questions/Caveats
My understanding from the discussion on #299 is that this logic is meant to largely match the behavior of autosummary (current logic in https://github.com/sphinx-doc/sphinx/blob/cc7c6f435ad37bb12264f8118c8461b230e6830c/sphinx/ext/autosummary/__init__.py#L553-L567), but the actual logic seems to have diverged a bit:
If there is no period in the opening stanza/paragraph, Autosummary takes the whole stanza, while Numpydoc takes only the first line. There are tests around this, so I assume it’s an intentional difference, and tried to call it out a little more clearly in the source.
Numpydoc’s previous implementation attempts to scan up to the first period and stop, while Autosummary splits all the candidate sentences into a list to work with. I don’t know if the difference was an intentional performance concern (what Numpydoc had should be faster and lower memory) or if it was drift over time or for some other reason.
I rewrote the code using the same general structure and logic as Autosummary, so it should be easier update if/when things change there. But I can re-do this using
re.finditer()if there are performance or other concerns.