Repository navigation
Doctest fails in stdtypes.rst #106446
Copy link
Copy link
Closed
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Documentation
When some codes are modified, the doc and doctests are not updated synchronously.
Local doctest:
./python -m doctest ./Doc/library/stdtypes.rstDetails
**********************************************************************
File "./Doc/library/stdtypes.rst", line 3769, in stdtypes.rst
Failed example:
v[1:4]
Expected:
<memory at 0x7f3ddc9f4350>
Got:
<memory at 0x7f42c250f040>
**********************************************************************
File "./Doc/library/stdtypes.rst", line 3952, in stdtypes.rst
Failed example:
mm.tolist()
Expected:
[89, 98, 99]
Got:
[97, 98, 99]
**********************************************************************
File "./Doc/library/stdtypes.rst", line 4037, in stdtypes.rst
Failed example:
x[0] = b'a'
Expected:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: memoryview: invalid value for format "B"
Got:
Traceback (most recent call last):
File "/home/github/cpython/Lib/doctest.py", line 1357, in __run
exec(compile(example.source, filename, "single",
File "<doctest stdtypes.rst[234]>", line 1, in <module>
x[0] = b'a'
~^^^
TypeError: memoryview: invalid type for format 'B'
**********************************************************************
File "./Doc/library/stdtypes.rst", line 4789, in stdtypes.rst
Failed example:
keys ^ {'sausage', 'juice'}
Expected:
{'juice', 'sausage', 'bacon', 'spam'}
Got:
{'spam', 'sausage', 'bacon', 'juice'}
**********************************************************************
File "./Doc/library/stdtypes.rst", line 4791, in stdtypes.rst
Failed example:
keys | ['juice', 'juice', 'juice']
Expected:
{'juice', 'sausage', 'bacon', 'spam', 'eggs'}
Got:
{'spam', 'bacon', 'juice'}
**********************************************************************
File "./Doc/library/stdtypes.rst", line 4997, in stdtypes.rst
Failed example:
dict[str][str]
Expected:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: There are no type variables left in dict[str]
Got:
Traceback (most recent call last):
File "/home/github/cpython/Lib/doctest.py", line 1357, in __run
exec(compile(example.source, filename, "single",
File "<doctest stdtypes.rst[335]>", line 1, in <module>
dict[str][str]
~~~~~~~~~^^^^^
TypeError: dict[str] is not a generic class
**********************************************************************
File "./Doc/library/stdtypes.rst", line 5209, in stdtypes.rst
Failed example:
isinstance(1, int | list[int])
Expected:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: isinstance() argument 2 cannot contain a parameterized generic
Got:
True
**********************************************************************
File "./Doc/library/stdtypes.rst", line 5514, in stdtypes.rst
Failed example:
int.__subclasses__()
Expected:
[<class 'bool'>]
Got:
[<class 'bool'>, <enum 'IntEnum'>, <flag 'IntFlag'>, <class 're._constants._NamedIntConstant'>]
**********************************************************************
File "./Doc/library/stdtypes.rst", line 5548, in stdtypes.rst
Failed example:
_ = int('2' * 5432)
Expected:
Traceback (most recent call last):
...
ValueError: Exceeds the limit (4300 digits) for integer string conversion: value has 5432 digits; use sys.set_int_max_str_digits() to increase the limit.
Got:
Traceback (most recent call last):
File "/home/github/cpython/Lib/doctest.py", line 1357, in __run
exec(compile(example.source, filename, "single",
File "<doctest stdtypes.rst[361]>", line 1, in <module>
_ = int('2' * 5432)
^^^^^^^^^^^^^^^
ValueError: Exceeds the limit (4300 digits) for integer string conversion: value has 5432 digits; use sys.set_int_max_str_digits() to increase the limit
**********************************************************************
File "./Doc/library/stdtypes.rst", line 5556, in stdtypes.rst
Failed example:
len(str(i_squared))
Expected:
Traceback (most recent call last):
...
ValueError: Exceeds the limit (4300 digits) for integer string conversion: value has 8599 digits; use sys.set_int_max_str_digits() to increase the limit.
Got:
Traceback (most recent call last):
File "/home/github/cpython/Lib/doctest.py", line 1357, in __run
exec(compile(example.source, filename, "single",
File "<doctest stdtypes.rst[365]>", line 1, in <module>
len(str(i_squared))
^^^^^^^^^^^^^^
ValueError: Exceeds the limit (4300 digits) for integer string conversion; use sys.set_int_max_str_digits() to increase the limit
**********************************************************************1 items had failures:
10 of 374 in stdtypes.rst
***Test Failed*** 10 failures.BTW, It seems that all doctests are passing in the CI pipeline. Those failed cases are not found by CI doctest.
See: https://github.com/CharlieZhao95/cpython/actions/runs/5461321900/jobs/9939195566
...
Document: library/stdtypes
--------------------------
1 items passed all tests:
50 tests in default
50 tests in 1 items.
50 passed and 0 failed.
Test passed.Environment:
CPython versions tested on: 3.13.0a0
Operating system and architecture: Ubuntu 22.04.1 LTS
Linked PRs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
CharlieZhao95 commentedon Jul 5, 2023
Failed doctests in
stdtypes.rst:terryjreedy commentedon Jul 6, 2023
I get 15 failures on Windows; the additional 5 (3,4,5,6,8 in details) seem to be from long ints being 8 versus 4 bytes.
Details, with error numbers added
I don't know how CI is run to avoid failures; perhaps it skips some things by examining failure. But some 'expected's are incorrect and should be changed in any case.
Comments: (I assume that you got same non-matching expected on Ubuntu. I checked validity of replacement expecteds back to 3.11 to be sure we can backport.)
0x..., but this would require option and comment. Maybe CI ignores 0x... differences; leave alone.97, not89is correct for ord('a'). Fix.Perhaps CI does so. Leave alone as long as CI passes as answer is correct from reader viewpoint.
keys | {'juice'}was originally before the deletions at which time the answer was correct. Change the test to>>> keys | {'juice'}and fix the answer.CharlieZhao95 commentedon Jul 6, 2023
I get the same result on Windows. Please let me know if further testing or other work is required, so as not to duplicate the work you are doing~
terryjreedy commentedon Jul 6, 2023
I finished testing, but will 'let' you revise the PR.
CharlieZhao95 commentedon Jul 11, 2023
Some additions:
(1, 9) The doctest docs recommend a solution to check set and address. Maybe we could use this to improve docs.
(10) The
keyshere is not a real set object, but a set-like object (dict_keys). The test cases for operators between set-like object and list are intentionally added. See gh-96408 for details. So we just need to fix answer :)(12) This result is correct until Python 3.10. But please consider the following examples:
I guess the syntax of Python has changed. In example 2, the second operand is never evaluated (short-circuit). Only modifying the result to
Truedoes not match the description in docs. It might be better to add example 3 and update docs.gh-106446: Fix failed doctest in stdtypes (#106447)
pythongh-106446: Fix failed doctest in stdtypes (pythonGH-106447)
pythongh-106446: Fix failed doctest in stdtypes (python#106447)
[3.11] pythongh-106446: Fix failed doctest in stdtypes (pythonGH-106447)
[3.12] gh-106446: Fix failed doctest in stdtypes (GH-106447) (#106741)
[3.11] gh-106446: Fix failed doctest in stdtypes (GH-106447) (#106742)
pythongh-106446: Fix failed doctest in stdtypes (python#106447)