Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: In param lists mark up multiple types correctly #116389

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

erlend-aasland
Copy link
Contributor

@erlend-aasland erlend-aasland commented Mar 5, 2024

Use the word 'or' instead of the symbol '|'.

See also the Sphinx docs:


馃摎 Documentation preview 馃摎: https://cpython-previews--116389.org.readthedocs.build/

Use the word 'or' instead of the symbol '|'.
@erlend-aasland erlend-aasland changed the title Docs: In param lists Docs: In param lists mark up multiple types correctly Mar 5, 2024
@AlexWaygood
Copy link
Member

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
Copy link
Member

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

Copy link
Contributor Author

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. |.

@hugovk
Copy link
Member

hugovk commented Mar 6, 2024

I checked the first one:

Before After
image image

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 None? https://devguide.python.org/documentation/markup/#quick-reference

@erlend-aasland
Copy link
Contributor Author

Both are linked and marked up the same. Are there some instances where there's a difference (other than "|" vs. "or")?

@hugovk: indeed, it looks like they are all the same. I also tried just using a comma (:type name: str, dict), which is also marked up like this. Looks like it just boils down to a style issue. Do we want it written as str or dict, or str | dict? See also @AlexWaygood's comment: #116389 (comment).

@hugovk
Copy link
Member

hugovk commented Mar 8, 2024

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 ;)

@erlend-aasland
Copy link
Contributor Author

erlend-aasland commented Mar 9, 2024

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.

@erlend-aasland erlend-aasland marked this pull request as draft March 12, 2024 13:54
@erlend-aasland
Copy link
Contributor Author

Marked as draft until a decision has been made.

@hugovk hugovk removed the needs backport to 3.11 only security fixes label Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir needs backport to 3.12 bug and security fixes skip issue skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants