Skip to content

Commit 00eb435

Browse files
miss-islingtonCharlieZhao95terryjreedy
authoredJul 14, 2023
[3.12] gh-106446: Fix failed doctest in stdtypes (GH-106447) (#106741)
(cherry picked from commit 89867d2) Co-authored-by: Charlie Zhao <zhaoyu_hit@qq.com> Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
1 parent e68b280 commit 00eb435

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed
 

‎Doc/library/stdtypes.rst

+20-17
Original file line numberDiff line numberDiff line change
@@ -3950,7 +3950,7 @@ copying.
39503950
>>> m = memoryview(bytearray(b'abc'))
39513951
>>> mm = m.toreadonly()
39523952
>>> mm.tolist()
3953-
[89, 98, 99]
3953+
[97, 98, 99]
39543954
>>> mm[0] = 42
39553955
Traceback (most recent call last):
39563956
File "<stdin>", line 1, in <module>
@@ -4006,6 +4006,7 @@ copying.
40064006
:mod:`struct` syntax. One of the formats must be a byte format
40074007
('B', 'b' or 'c'). The byte length of the result must be the same
40084008
as the original length.
4009+
Note that all byte lengths may depend on the operating system.
40094010

40104011
Cast 1D/long to 1D/unsigned bytes::
40114012

@@ -4036,8 +4037,8 @@ copying.
40364037
>>> x = memoryview(b)
40374038
>>> x[0] = b'a'
40384039
Traceback (most recent call last):
4039-
File "<stdin>", line 1, in <module>
4040-
ValueError: memoryview: invalid value for format "B"
4040+
...
4041+
TypeError: memoryview: invalid type for format 'B'
40414042
>>> y = x.cast('c')
40424043
>>> y[0] = b'a'
40434044
>>> b
@@ -4786,10 +4787,10 @@ An example of dictionary view usage::
47864787
>>> # set operations
47874788
>>> keys & {'eggs', 'bacon', 'salad'}
47884789
{'bacon'}
4789-
>>> keys ^ {'sausage', 'juice'}
4790-
{'juice', 'sausage', 'bacon', 'spam'}
4791-
>>> keys | ['juice', 'juice', 'juice']
4792-
{'juice', 'sausage', 'bacon', 'spam', 'eggs'}
4790+
>>> keys ^ {'sausage', 'juice'} == {'juice', 'sausage', 'bacon', 'spam'}
4791+
True
4792+
>>> keys | ['juice', 'juice', 'juice'] == {'bacon', 'spam', 'juice'}
4793+
True
47934794

47944795
>>> # get back a read-only proxy for the original dictionary
47954796
>>> values.mapping
@@ -4996,8 +4997,8 @@ exception to disallow mistakes like ``dict[str][str]``::
49964997

49974998
>>> dict[str][str]
49984999
Traceback (most recent call last):
4999-
File "<stdin>", line 1, in <module>
5000-
TypeError: There are no type variables left in dict[str]
5000+
...
5001+
TypeError: dict[str] is not a generic class
50015002

50025003
However, such expressions are valid when :ref:`type variables <generics>` are
50035004
used. The index must have as many elements as there are type variable items
@@ -5203,13 +5204,15 @@ enables cleaner type hinting syntax compared to :data:`typing.Union`.
52035204
>>> isinstance("", int | str)
52045205
True
52055206

5206-
However, union objects containing :ref:`parameterized generics
5207-
<types-genericalias>` cannot be used::
5207+
However, :ref:`parameterized generics <types-genericalias>` in
5208+
union objects cannot be checked::
52085209

5209-
>>> isinstance(1, int | list[int])
5210+
>>> isinstance(1, int | list[int]) # short-circuit evaluation
5211+
True
5212+
>>> isinstance([1], int | list[int])
52105213
Traceback (most recent call last):
5211-
File "<stdin>", line 1, in <module>
5212-
TypeError: isinstance() argument 2 cannot contain a parameterized generic
5214+
...
5215+
TypeError: isinstance() argument 2 cannot be a parameterized generic
52135216

52145217
The user-exposed type for the union object can be accessed from
52155218
:data:`types.UnionType` and used for :func:`isinstance` checks. An object cannot be
@@ -5512,7 +5515,7 @@ types, where they are relevant. Some of these are not reported by the
55125515
definition order. Example::
55135516

55145517
>>> int.__subclasses__()
5515-
[<class 'bool'>]
5518+
[<class 'bool'>, <enum 'IntEnum'>, <flag 'IntFlag'>, <class 're._constants._NamedIntConstant'>]
55165519

55175520

55185521
.. _int_max_str_digits:
@@ -5548,15 +5551,15 @@ When an operation would exceed the limit, a :exc:`ValueError` is raised:
55485551
>>> _ = int('2' * 5432)
55495552
Traceback (most recent call last):
55505553
...
5551-
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.
5554+
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
55525555
>>> i = int('2' * 4300)
55535556
>>> len(str(i))
55545557
4300
55555558
>>> i_squared = i*i
55565559
>>> len(str(i_squared))
55575560
Traceback (most recent call last):
55585561
...
5559-
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.
5562+
ValueError: Exceeds the limit (4300 digits) for integer string conversion; use sys.set_int_max_str_digits() to increase the limit
55605563
>>> len(hex(i_squared))
55615564
7144
55625565
>>> assert int(hex(i_squared), base=16) == i*i # Hexadecimal is unlimited.

0 commit comments

Comments
 (0)
Please sign in to comment.