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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-101100: Fix sphinx warnings in enum module #101122

Merged
merged 4 commits into from
Jan 20, 2023

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Jan 18, 2023

There were several warnings before:


/Users/sobolev/Desktop/cpython/Doc/library/enum.rst:428: WARNING: py:meth reference target not found: __str__
/Users/sobolev/Desktop/cpython/Doc/library/enum.rst:428: WARNING: py:func reference target not found: int.__str__
/Users/sobolev/Desktop/cpython/Doc/library/enum.rst:428: WARNING: py:meth reference target not found: __format__
/Users/sobolev/Desktop/cpython/Doc/library/enum.rst:428: WARNING: py:func reference target not found: int.__format__
/Users/sobolev/Desktop/cpython/Doc/library/enum.rst:764: WARNING: py:attr reference target not found: __members__
/Users/sobolev/Desktop/cpython/Doc/library/enum.rst:767: WARNING: py:meth reference target not found: __new__
/Users/sobolev/Desktop/cpython/Doc/library/enum.rst:767: WARNING: py:attr reference target not found: _value_
/Users/sobolev/Desktop/cpython/Doc/library/enum.rst:806: WARNING: py:meth reference target not found: _generate_next_value_
/Users/sobolev/Desktop/cpython/Doc/library/enum.rst:849: WARNING: py:attr reference target not found: __members__

Here's how these places were rendered:

Снимок экрана 2023-01-18 в 11 18 28

Снимок экрана 2023-01-18 в 11 18 38

Снимок экрана 2023-01-18 в 11 19 57

Снимок экрана 2023-01-18 в 11 21 18

After the fix, there are no warnings:

Снимок экрана 2023-01-18 в 11 27 00

Copy link
Member

@CAM-Gerlach CAM-Gerlach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, unfortunately none of these changes are actually the correct fix, and many are in fact regressions. Some common themes:

  • Method/attribute names should use be literal, not italic (reserved for parameters), and generic object methods/attributes can be either linked with :meth:`~object.__dunder__`, or unlinked with :meth:`!__dunder__` (see the reST markup quick reference in the devguide)
  • If the ref target actually exists, ! should not be used unless it would be repeating the same link within the same information unit (paragraph, description block, etc—see Style guide suggestion: Avoid duplicate links docs-community#52 )
  • If the ref target does not and should not exist, and the original usage did not prefix a method, attribute, etc. name with the class or module it belongs to, and it is unambiguous in context, then it shouldn't be added when making it an unresolved reference (see Style guide suggestion: Avoid duplicate links docs-community#52 again)
  • If the ref target does not exist, but potentially should be documented, then it is a valid warning that should either be documented or left as-is a rather than silenced (see what we did in sqlite3).

Etc., see individual comments on each change for more details and the suggested fixes to each.

Comment on lines 55 to 56
- The class ``Color`` is an *enumeration* (or *enum*)
- The attributes ``Color.RED``, ``Color.GREEN``, etc., are
Copy link
Member

@CAM-Gerlach CAM-Gerlach Jan 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If @ethanfurman prefers these to be verbatim code literals, as you've changed them to, instead of marked-up classes and attributes as they were before, then that's fine—it is a bit of a gray area.

However, in general when you're changing existing text, it seems to make more sense to at least initially propose the more minimal change that retains the previous markup, formatting and rendering, and just disables resolution (silencing the warnings):

Suggested change
- The class ``Color`` is an *enumeration* (or *enum*)
- The attributes ``Color.RED``, ``Color.GREEN``, etc., are
- The class :class:`!Color` is an *enumeration* (or *enum*)
- The attributes :attr:`!Color.RED`, :attr:`!Color.GREEN`, etc., are

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite agree that these references should be :class: and :attr:, because Color is only defined in the docs. But, visual separation is a good enough argument to keep it this way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think there's a good conceptual argument to be made for either way, and I don't have a particular preference myself—in fact, if anything generally I tend to prefer the style you used, for the reason you mentioned (plus its a little simpler).

However, I ended up mentioning it here because it preserved the existing syntax and styling as much as practical, and in particular because this particular usage is explicitly to highlight the semantic differences between the enum, members, and their names and values, which the markup helps accentuate (in fact, before I saw the next line, I hesitated to make this comment at all).

To note, though, due to a theme CSS bug, references in admonitions (like this note) are rendered with the background anyway—but will start working again as soon as that's fixed.

Doc/library/enum.rst Outdated Show resolved Hide resolved
Doc/library/enum.rst Outdated Show resolved Hide resolved
@@ -424,9 +424,9 @@ Data Types
Using :class:`auto` with :class:`IntEnum` results in integers of increasing
value, starting with ``1``.

.. versionchanged:: 3.11 :meth:`__str__` is now :func:`int.__str__` to
.. versionchanged:: 3.11 *__str__* is now ``int.__str__`` to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here; why not:

Suggested change
.. versionchanged:: 3.11 *__str__* is now ``int.__str__`` to
.. versionchanged:: 3.11 :meth:`~object.__str__` is now :meth:`!int.__str__` to

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have slightly modified your proposed change, because reading

:meth:`~object.__str__` is now :meth:`!int.__str__`

does not make much sense to me. Now it is:

:meth:`!__str__` is now :meth:`!int.__str__`

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the latter is essentially what readers will actually see, of course; the ~ removes the object prefix, so the original suggestion already displays as your second example, just with __str__ usefully cross-referenced to a description of the __str__ dunder and what it's used for, which seems to me to be potentially helpful to readers (and surely does no harm, at least).

Doc/library/enum.rst Outdated Show resolved Hide resolved
@@ -761,11 +761,11 @@ Data Types
Supported ``__dunder__`` names
""""""""""""""""""""""""""""""

:attr:`__members__` is a read-only ordered mapping of ``member_name``:``member``
:attr:`!EnumType.__members__` is a read-only ordered mapping of ``member_name``:``member``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really get this either. This is a list of supported dunder and sunder names, and none of the other names have the class name explicitly prefixed, so I'm not sure why it makes sense to treat this differently.

Either __members__ should be explicitly documented under EnumType, like a number of other dunders and sunders are (including some listed here), and the link fixed here in the meantime (which displays the same as now until it is added):

Suggested change
:attr:`!EnumType.__members__` is a read-only ordered mapping of ``member_name``:``member``
:attr:`~EnumType.__members__` is a read-only ordered mapping of ``member_name``:``member``

or, if for whatever reason it doesn't make sense to explicitly document __members__ in the usual way, silence the warning without the prefix:

Suggested change
:attr:`!EnumType.__members__` is a read-only ordered mapping of ``member_name``:``member``
:attr:`!__members__` is a read-only ordered mapping of ``member_name``:``member``

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's document __member__ separately and keep the focus of this PR focused 😉

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but if __members__ should be documented (or the decision left until later), then deresolving it not only silences a valid warning, but also means that it will stay broken even if and when __members__ is documented, rather than start working automatically.

Therefore, unless @ethanfurman has some reason to not explicitly document __members__ but still list it here (which is possible), then the default approach should be the former, i.e. to fix it but leave it resolving, unless and until it is decided to explicitly leave it undocumented.

Doc/library/enum.rst Outdated Show resolved Hide resolved
Doc/library/enum.rst Outdated Show resolved Hide resolved
Doc/library/enum.rst Outdated Show resolved Hide resolved
@CAM-Gerlach
Copy link
Member

Also, since this fixes a docs defect and would otherwise increase the change of merge conflicts when backporting other docs fixes, this should be backported as well, at least to 3.11 if not 3.10. To note, the 3.10 backport will likely hit a conflict on one of the lines that's 3.11-specific, but that can be backported manually or with Cherry-Picker.

@sobolevn
Copy link
Member Author

@CAM-Gerlach thanks a lot for teaching me this! It makes so much more sense now.
It is like 10x times better than just going through the https://devguide.python.org/documentation/style-guide/ :)

Copy link
Member

@CAM-Gerlach CAM-Gerlach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few followup suggestions.

(Standard reminder: You can apply the suggestions you want in one go with Files changed -> Add to batch -> Commit, or modify them/add your own and do the same)

Doc/library/enum.rst Outdated Show resolved Hide resolved
Doc/library/enum.rst Outdated Show resolved Hide resolved
Doc/library/enum.rst Outdated Show resolved Hide resolved
Doc/library/enum.rst Outdated Show resolved Hide resolved
Doc/library/enum.rst Outdated Show resolved Hide resolved
Doc/library/enum.rst Outdated Show resolved Hide resolved
@CAM-Gerlach
Copy link
Member

I'm so glad it was helpful to you! I was pretty worried that I was too harsh and critical with the tone of my comment, but I'm glad you learned a lot—that's as if not more important than fixing these issues, as it benefits everyone going forward!

ethanfurman and others added 2 commits January 19, 2023 18:07
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
Copy link
Member

@ethanfurman ethanfurman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you both!

@ethanfurman
Copy link
Member

The enum docs were completely redone in 3.11, so there's no backporting to 3.10.

@ethanfurman ethanfurman merged commit 9e025d3 into python:main Jan 20, 2023
@miss-islington
Copy link
Contributor

Thanks @sobolevn for the PR, and @ethanfurman for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 20, 2023
* pythongh-101100: [Enum] Fix sphinx warnings in

(cherry picked from commit 9e025d3)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
@bedevere-bot
Copy link

GH-101173 is a backport of this pull request to the 3.11 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Jan 20, 2023
ambv pushed a commit that referenced this pull request Jan 20, 2023
…1173)

(cherry picked from commit 9e025d3)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
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 skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants