-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-111681: Fix doctests in typing.rst
and remove unused imports
#111682
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
Conversation
I think we already run these doctests via Sphinx in CI. If there are certain doctests that aren't being run via that CI job, then I think we should investigate why that is, rather than running the entire doctest suite twice in CI |
See https://github.com/python/cpython/actions/runs/6741804289/job/18326927659 for a recent run, in which 55/55 typing doctests were reported to have passed (but maybe there's some that the job missed) |
@AlexWaygood as you can see there's something wrong with I know this because I've already fixed multiple doctests for other modules. |
In which case, I think we should either try to fix the broken CI job, or, if it's useless, remove it from CI. @AA-Turner, any idea why the doctest CI job doesn't seem to be doing what it should be here? :) |
Doc/library/typing.rst
Outdated
>>> 1 + 2 | ||
4 |
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.
this isn't actually doctested, I don't think, since you don't have the .. doctest::
directive above this block. (I've just pushed to your branch to add it.)
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 a doctest, clearly:
» ./python.exe -m doctest Doc/library/typing.rst
**********************************************************************
File "Doc/library/typing.rst", line 651, in typing.rst
Failed example:
1 + 2
Expected:
4
Got:
3
**********************************************************************
1 items had failures:
1 of 48 in typing.rst
***Test Failed*** 1 failures.
It works the same way with and without .. doctest::
.
The problem might that Sphinx does not recognize doctests without this directive, but this is clearly a Sphinx's own issue.
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.
Yes, that was what I meant, sorry for not being clear: that it wouldn't be picked up by sphinx's doctest job :)
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.
We might need to use doctest_test_doctest_blocks
from https://www.sphinx-doc.org/en/master/usage/extensions/doctest.html
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.
We might need to use
doctest_test_doctest_blocks
from https://www.sphinx-doc.org/en/master/usage/extensions/doctest.html
We can try enabling that, sure, but that should be a separate issue/PR. This PR is about fixing broken doctests in typing.rst
, not changing the way we determine in CI which doctests should be run. The majority of these that need to be tested already are tested, using the .. doctest::
directive.
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 seems like the current CI job is not broken at all. The "clearly broken" example you added correctly failed in CI with the Sphinx doctest job after the .. doctest::
marker was added: https://github.com/python/cpython/actions/runs/6743594059/job/18331803827?pr=111682
@@ -1954,7 +1959,7 @@ without the dedicated syntax, as documented below. | |||
|
|||
.. doctest:: | |||
|
|||
>>> from typing import ParamSpec | |||
>>> from typing import ParamSpec, get_origin |
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.
I don't mind the change you're making here. But the reason why this doesn't currently fail when Sphinx runs our doctests in CI is because of this, which is run before every doctest block:
cpython/Doc/library/typing.rst
Lines 5 to 9 in d49aba5
.. testsetup:: * | |
import typing | |
from dataclasses import dataclass | |
from typing import * |
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 |
It might not be broken, it just allows a lot of broken doctests in. Because what happens in reality is that a lot of code blocks / example do not have |
I agree this situation is suboptimal. But that makes me think that we should do one of the following two things:
It makes no sense to me to do what this PR currently proposes: run most of the doctests in |
Yes, I agree. I will convert it to a very minimalistic one: just remove unused imports and fix doctests a bit, without adding new tests to the suite. |
typing.rst
and run it in CItyping.rst
and remove unused imports
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.
Thanks!
Thanks @sobolevn for the PR, and @AlexWaygood for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12. |
Sorry, @sobolevn and @AlexWaygood, I could not cleanly backport this to
|
Sorry, @sobolevn and @AlexWaygood, I could not cleanly backport this to
|
@sobolevn, can I leave the backports with you? :) |
Will do, I will also create a new issue about our CI + doctest. |
|
|
…s in `test_typing` (python#111682) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
GH-112035 is a backport of this pull request to the 3.12 branch. |
GH-112037 is a backport of this pull request to the 3.11 branch. |
…s in `test_typing` (python#111682) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
…s in `test_typing` (python#111682) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Without
globs
it would fail:typing.rst
contains failing doctests #111681📚 Documentation preview 📚: https://cpython-previews--111682.org.readthedocs.build/