-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
Docs: In param lists mark up multiple types correctly #116389
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
Docs: In param lists mark up multiple types correctly #116389
Conversation
Use the word 'or' instead of the symbol '|'.
|
My first reaction was "but these aren't valid Python type hints anymore!" My second reaction was to go... "Wait, he's right, these are probably much more readable for casual readers of the documentation who might not be familiar with Python's typing system" :) |
|
|
||
| :param exc_info: An exception tuple with the current exception information, | ||
| as returned by :func:`sys.exc_info`, | ||
| or ``None`` if no exception information is available. | ||
| :type exc_info: tuple[type[BaseException], BaseException, types.TracebackType] | None | ||
| :type exc_info: tuple[type[BaseException], BaseException, types.TracebackType] or None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this one still perhaps a bit too complex for the docs? Not sure how it could be simplified, though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is definitely complex. In this case, I'd say readability is definitely improved using or iso. |.
|
I checked the first one:
Both are linked and marked up the same. Are there some instances where there's a difference (other than "|" vs. "or")? Should we be formatting None as |
@hugovk: indeed, it looks like they are all the same. I also tried just using a comma ( |
|
No strong preference either way. In theory, if Sphinx says to do it one way, it makes sense to do that. In practice, if it makes no difference, let's pick the one we prefer. So I'll leave it up to you ;) |
It's a minor style issue to decide on, nevertheless it feels wrong for me to decide on the convention in a PR. I think at least a heads-up in the Documentation category on Discourse would be nice :) UPDATE: I created a topic on Discourse. |
|
Marked as draft until a decision has been made. |
Well... I don't remember whether there are corner cases where we fail to render correctly the docs (I know that there is an open issue in Sphinx about something related and I know it's something I've replied to but I don't remember the issue :D). Personally, I tend to use For CPython, I'd say that using or is fine and possibly preferrable for end-users and beginners. |
|
We discussed this at the docs meet-up recently, and there was many of arguments in favour of |
|
Based on python/editorial-board#7 (comment), I suspect the EB is ok with this PR. If so, let's land this and follow up with a devguide PR, to document this recommended practise. |
|
Take a look at the CI failure for commit d464f3f. It seems like Sphinx do not support its own convention for attributes. If this is really the case, we should definitely not land this PR, and instead recommend continued use of cc. Sphinx wizard @AA-Turner 🪄 |
|
Huh, maybe it requires Napoleon's extension for that to work? I don't remember where we parse the |
This reverts commit 577c52b. This should trigger the error I saw earlier.
|
@erlend-aasland basically what you're asking for is an historical disambiguation (initially motivated by a syntactic error in this PR) that can't be arbitrated by Sphinx devs alone because the acceptable values in those fields are multi-language and predate PEP 484 type expressions as we know them. The closest things is the napoleon extension intro on docstrings and a comprehensive historical rewrite to bring it up to date has not yet been proposed. Also, the specific numpy docstring style syntax is sufficiently ambiguous/underspecified (you'll rarely find full explanations of default values in APIs - or a complete example in their docs) and more or less independent. Every beginner who ever tried to write a docstring fell into this problem, but it's an extremely hard document to write because even the use of prose like types ( |
|
The EB landed on preferring |


Use the word 'or' instead of the symbol '|'.
See also the Sphinx docs:
📚 Documentation preview 📚: https://cpython-previews--116389.org.readthedocs.build/