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 dangling references in test.rst #114958

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

smontanaro
Copy link
Contributor

@smontanaro smontanaro commented Feb 3, 2024

Further cleanup related to #114770.

One or two typos. Mostly I just suppressed the dangling references, because this module is just meant for core dev usage.


📚 Documentation preview 📚: https://cpython-previews--114958.org.readthedocs.build/

@@ -1087,12 +1087,12 @@ The :mod:`test.support.socket_helper` module provides support for socket tests.
buildbot environment. This method raises an exception if the
``sock.family`` is :const:`~socket.AF_INET` and ``sock.type`` is
:const:`~socket.SOCK_STREAM`, and the socket has
:const:`~socket.SO_REUSEADDR` or :const:`~socket.SO_REUSEPORT` set on it.
:const:`!SO_REUSEADDR` or :const:`!SO_REUSEPORT` set on it.
Copy link
Member

@AlexWaygood AlexWaygood Feb 4, 2024

Choose a reason for hiding this comment

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

The better way to fix these two warnings would be to add documentation for these constants in the socket module docs, if that documentation doesn't already exist. Then we'll also be able to reference these constants in the docs for other modules, as will users of intersphinx outside of CPython

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps, but ISTR the socket module doc explicitly mentions a whole raft of constants as coming from the underlying C socket(2) implementation. That is presumably to keep from duplicating underlying canonical documentation and to avoid introducing mistakes (think platform dependencies).

I understand it would be great to have the Python library docs completely self-contained, but I don't think that's the best way to go in some cases.

Copy link
Member

Choose a reason for hiding this comment

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

Fair point, there are probably too many in the socket module for us to list them all out explicitly!

Copy link
Member

Choose a reason for hiding this comment

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

In that case, we should explicitly list them in conf.py as silenced with a comment explaining why, to avoid introducing noise here, making it easy to change the decision in the future, and ensuring we have a consistent central record of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Given that many of the possible constants are only given in the socket module doc as wildcards (e.g., SO_*) I don't think that will work unless you only want to list a known (small) subset.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This stuff is really at the fringe between low-level Unix stuff and the relevant Python wrappers. According to Wikipedia, the first edition of Stevens' Unix Network Programming (the network programming bible when I was a wee lad) is 768 pages long. It's not at all clear to me that there's much to be gained by documenting a few socket options. It's not really going to flatten the socket programming learning curve much. Programmers will have to delve into the C socket documentation to do anything serious anyway.

Sorry about the soapbox.

@hugovk
Copy link
Member

hugovk commented Feb 4, 2024

🎉

Congratulations! You improved:

Doc/library/test.rst

Please remove from Doc/tools/.nitignore

Let's combine #114770 into this one, they need to be atomic for the CI to be green and mergeable.

Doc/library/test.rst Outdated Show resolved Hide resolved
@smontanaro
Copy link
Contributor Author

Let's combine #114770 into this one

Done. I also closed that PR.

@smontanaro
Copy link
Contributor Author

Can we move this forward? Is there more people think needs to be done?

@AlexWaygood
Copy link
Member

Can we move this forward? Is there more people think needs to be done?

there's a merge conflict

@smontanaro
Copy link
Contributor Author

there's a merge conflict

Better now? I saw the alert in the web interface, but didn't see a conflict in my sandbox. I must have missed a step in there somewhere. I just resolved it through the web interface.

@smontanaro
Copy link
Contributor Author

Once it is merged, let me try to take care of 3.12 and 3.11 (assuming these changes are backported). I have a local version of cherry_picker with some minimal color support I'd like to exercise a bit.

@CAM-Gerlach CAM-Gerlach added needs backport to 3.11 only security fixes needs backport to 3.12 bug and security fixes labels Feb 21, 2024
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 general comment: IMO, it is much better to just leave valid warnings due to missing documentation than to take the easy way out and just hide them, as doing so defeats one of the most meaningful benefits of these warnings in the first place—identifying gaps in the docs where we haven't formally documented something that should be public. To be honest, I'd rather people not fix the trivial cases at all if that comes at the cost of ignoring the more important ones.

Doc/library/test.rst Outdated Show resolved Hide resolved
Comment on lines 327 to 328
True if Python was built with the :c:macro:`!Py_DEBUG` macro defined: if
Python is :ref:`built in debug mode <debug-build>`
Copy link
Member

Choose a reason for hiding this comment

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

What's the reason for disabling reference resolution here, sorry? Does it not work, for some reason? A c:macro: is defined for Py_DEBUG, and the macro definition and surrounding text describes what it means for Python to be built in debug mode, so seems a useful reference here.

Also, this wording change seems a bit incongruous to my eye and the breaks don't either minimize diffs or follow the semantic structure. Therefore, I'd suggest either simplifying the structure and wording with more logical breaks:

Suggested change
True if Python was built with the :c:macro:`!Py_DEBUG` macro defined: if
Python is :ref:`built in debug mode <debug-build>`
True if Python was built with the :c:macro:`Py_DEBUG` macro defined:
i.e. it was :ref:`built in debug mode <debug-build>`

or minimizing diffs to just the essential fixes

Suggested change
True if Python was built with the :c:macro:`!Py_DEBUG` macro defined: if
Python is :ref:`built in debug mode <debug-build>`
True if Python was built with the :c:macro:`Py_DEBUG` macro
defined; that is, if
Python was :ref:`built in debug mode <debug-build>`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably just confusion on my part, though I think in discussing changes to test.rst we might have gone back and forth a bit. Note that the meaning and effects of debug builds are scattered in multiple locations. In my mind defining the Py_DEBUG macro is just the marker for C programmers for what you really care about, creating a debug build. That's discussed in to sections in using/configure.rst and c-api/intro.rst.

@@ -1087,12 +1087,12 @@ The :mod:`test.support.socket_helper` module provides support for socket tests.
buildbot environment. This method raises an exception if the
``sock.family`` is :const:`~socket.AF_INET` and ``sock.type`` is
:const:`~socket.SOCK_STREAM`, and the socket has
:const:`~socket.SO_REUSEADDR` or :const:`~socket.SO_REUSEPORT` set on it.
:const:`!SO_REUSEADDR` or :const:`!SO_REUSEPORT` set on it.
Copy link
Member

Choose a reason for hiding this comment

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

In that case, we should explicitly list them in conf.py as silenced with a comment explaining why, to avoid introducing noise here, making it easy to change the decision in the future, and ensuring we have a consistent central record of it.

Doc/library/test.rst Outdated Show resolved Hide resolved
@@ -475,7 +475,7 @@ The :mod:`test.support` module defines the following functions:

.. function:: with_pymalloc()

Return :const:`_testcapi.WITH_PYMALLOC`.
Return :const:`!_testcapi.WITH_PYMALLOC`.
Copy link
Member

Choose a reason for hiding this comment

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

This is a constant in an underscored name, test module, so it's not required to document it, but given the entire description of this function is "return ", which doesn't seem terribly useful if said constant is entirely undocumented, it seems worth at least briefly touching on what that actually means here (which the warning is a canary for).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm guessing the reference must be suppressed in some other way, because no hyperlink shows up in the generated HTML (and no warning is emitted by Sphinx). You'll have to take this up with someone above my pay grade.

@@ -969,7 +969,7 @@ The :mod:`test.support` module defines the following functions:

.. function:: skip_if_broken_multiprocessing_synchronize()

Skip tests if the :mod:`multiprocessing.synchronize` module is missing, if
Skip tests if the :mod:`!multiprocessing.synchronize` module is missing, if
Copy link
Member

Choose a reason for hiding this comment

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

This is an purposefully undocumented module, I'm guessing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I couldn't begin to guess why it's undocumented. Maybe it's meant to be semantically identical to the relevant threading module synchronization primitives?

__all__ = [
    'Lock', 'RLock', 'Semaphore', 'BoundedSemaphore', 'Condition', 'Event'
    ]

I see this comment preceding an import which it suggests might fail:

# Try to import the mp.synchronize module cleanly, if it fails
# raise ImportError for platforms lacking a working sem_open implementation.
# See issue 3770

There is also a note about this possibility in the multiprocessing module documentation.

Comment on lines 1728 to 1729
The recorder object also has a :meth:`!reset` method, which clears the
warnings list.
Copy link
Member

Choose a reason for hiding this comment

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

This is a valid, public method of WarningsRecorder, a class publicly documented just below, that is missing its documentation. Therefore, this warning shouldn't be silenced, as again it indicates a legitimite gap in the docs. The simplest solution seems to move this line to a .. method under the WarningsRecorder class to properly document the method there, instead of overloading the already long and complex check_warnings context description with details of the object it returns.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed the text to :meth:``~WarningsRecorder.reset`` (how in the heck do I make the raw ReST display correctly in Markdown???) which is fine as far as that goes, but there is no documentation of either the class or the reset method. I'll leave it as-is. There will be a nitpick warning:

.../Doc/library/test.rst:1728: WARNING: py:meth reference target not found: WarningsRecorder.reset

Copy link
Contributor

Choose a reason for hiding this comment

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

(how in the heck do I make the raw ReST display correctly in Markdown???)

Use the fact that GitHub supports HTML tags and escape backquotes:

<code>:meth:\`~WarningsRecorder.reset\`</code>

produces :meth:`~WarningsRecorder.reset`.

@@ -1716,7 +1716,7 @@ The :mod:`test.support.warnings_helper` module provides support for warnings tes

In this case all warnings are caught and no errors are raised.

On entry to the context manager, a :class:`WarningRecorder` instance is
On entry to the context manager, a :class:`WarningsRecorder` instance is
returned. The underlying warnings list from
:func:`~warnings.catch_warnings` is available via the recorder object's
:attr:`warnings` attribute. As a convenience, the attributes of the object
Copy link
Member

Choose a reason for hiding this comment

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

This existing reference resolves but entirely incorrectly; it implies warnings is an "attribute" of the test.support.warnings_helper module, and furthermore actually falls back to link to the warnings stdlib module instead, which is entirely not what is intended. It should presumably be moved to where it belongs, under the class below, instead, to both avoid the misleading reference and properly document it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is one place where it would be real nice if Sphinx applied some simple semantics to the refs. Something which is an attribute clearly can't be a module. I've qualified the reference. As with the reset reference, it is now broken.

.../Doc/library/test.rst:1719: WARNING: py:attr reference target not found: WarningsRecorder.warnings

Both the reset and warnings items are fully qualified, so even though the links don't work, the full names are displayed.

@bedevere-app
Copy link

bedevere-app bot commented Feb 21, 2024

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

And if you don't make the requested changes, you will be put in the comfy chair!

@smontanaro
Copy link
Contributor Author

@CAM-Gerlach I can't see how I'm supposed to respond to your comment about the suppressed SO_REUSEADDR and SO_REUSEPORT attributes. Neither of those attributes is defined in the socket documentation (though mentioned a couple times). I'm not keen on reproducing bits of external documentation, especially as in this case where it means exactly the same thing in Python as in C.

Also note that the text near these suppressed links says basically, "Don't use these in tests!"

Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
@hugovk hugovk removed the needs backport to 3.11 only security fixes label Apr 11, 2024
@serhiy-storchaka serhiy-storchaka added the needs backport to 3.13 bugs and security fixes label May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting changes docs Documentation in the Doc dir needs backport to 3.12 bug and security fixes needs backport to 3.13 bugs and security fixes skip news
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

6 participants