Skip to content

Commit 2186212

Browse files
[3.11] gh-106446: Fix failed doctest in stdtypes (GH-106447) (#106742)
(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 d22224a commit 2186212

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

Doc/library/stdtypes.rst

+20-15
Original file line numberDiff line numberDiff line change
@@ -3903,7 +3903,7 @@ copying.
39033903
>>> m = memoryview(bytearray(b'abc'))
39043904
>>> mm = m.toreadonly()
39053905
>>> mm.tolist()
3906-
[89, 98, 99]
3906+
[97, 98, 99]
39073907
>>> mm[0] = 42
39083908
Traceback (most recent call last):
39093909
File "<stdin>", line 1, in <module>
@@ -3959,6 +3959,7 @@ copying.
39593959
:mod:`struct` syntax. One of the formats must be a byte format
39603960
('B', 'b' or 'c'). The byte length of the result must be the same
39613961
as the original length.
3962+
Note that all byte lengths may depend on the operating system.
39623963

39633964
Cast 1D/long to 1D/unsigned bytes::
39643965

@@ -3989,8 +3990,8 @@ copying.
39893990
>>> x = memoryview(b)
39903991
>>> x[0] = b'a'
39913992
Traceback (most recent call last):
3992-
File "<stdin>", line 1, in <module>
3993-
ValueError: memoryview: invalid value for format "B"
3993+
...
3994+
TypeError: memoryview: invalid type for format 'B'
39943995
>>> y = x.cast('c')
39953996
>>> y[0] = b'a'
39963997
>>> b
@@ -4735,8 +4736,10 @@ An example of dictionary view usage::
47354736
>>> # set operations
47364737
>>> keys & {'eggs', 'bacon', 'salad'}
47374738
{'bacon'}
4738-
>>> keys ^ {'sausage', 'juice'}
4739-
{'juice', 'sausage', 'bacon', 'spam'}
4739+
>>> keys ^ {'sausage', 'juice'} == {'juice', 'sausage', 'bacon', 'spam'}
4740+
True
4741+
>>> keys | ['juice', 'juice', 'juice'] == {'bacon', 'spam', 'juice'}
4742+
True
47404743

47414744
>>> # get back a read-only proxy for the original dictionary
47424745
>>> values.mapping
@@ -4943,8 +4946,8 @@ exception to disallow mistakes like ``dict[str][str]``::
49434946

49444947
>>> dict[str][str]
49454948
Traceback (most recent call last):
4946-
File "<stdin>", line 1, in <module>
4947-
TypeError: There are no type variables left in dict[str]
4949+
...
4950+
TypeError: dict[str] is not a generic class
49484951

49494952
However, such expressions are valid when :ref:`type variables <generics>` are
49504953
used. The index must have as many elements as there are type variable items
@@ -5150,13 +5153,15 @@ enables cleaner type hinting syntax compared to :data:`typing.Union`.
51505153
>>> isinstance("", int | str)
51515154
True
51525155

5153-
However, union objects containing :ref:`parameterized generics
5154-
<types-genericalias>` cannot be used::
5156+
However, :ref:`parameterized generics <types-genericalias>` in
5157+
union objects cannot be checked::
51555158

5156-
>>> isinstance(1, int | list[int])
5159+
>>> isinstance(1, int | list[int]) # short-circuit evaluation
5160+
True
5161+
>>> isinstance([1], int | list[int])
51575162
Traceback (most recent call last):
5158-
File "<stdin>", line 1, in <module>
5159-
TypeError: isinstance() argument 2 cannot contain a parameterized generic
5163+
...
5164+
TypeError: isinstance() argument 2 cannot be a parameterized generic
51605165

51615166
The user-exposed type for the union object can be accessed from
51625167
:data:`types.UnionType` and used for :func:`isinstance` checks. An object cannot be
@@ -5472,7 +5477,7 @@ types, where they are relevant. Some of these are not reported by the
54725477
definition order. Example::
54735478

54745479
>>> int.__subclasses__()
5475-
[<class 'bool'>]
5480+
[<class 'bool'>, <enum 'IntEnum'>, <flag 'IntFlag'>, <class 're._constants._NamedIntConstant'>]
54765481

54775482

54785483
.. _int_max_str_digits:
@@ -5508,15 +5513,15 @@ When an operation would exceed the limit, a :exc:`ValueError` is raised:
55085513
>>> _ = int('2' * 5432)
55095514
Traceback (most recent call last):
55105515
...
5511-
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.
5516+
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
55125517
>>> i = int('2' * 4300)
55135518
>>> len(str(i))
55145519
4300
55155520
>>> i_squared = i*i
55165521
>>> len(str(i_squared))
55175522
Traceback (most recent call last):
55185523
...
5519-
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.
5524+
ValueError: Exceeds the limit (4300 digits) for integer string conversion; use sys.set_int_max_str_digits() to increase the limit
55205525
>>> len(hex(i_squared))
55215526
7144
55225527
>>> assert int(hex(i_squared), base=16) == i*i # Hexadecimal is unlimited.

0 commit comments

Comments
 (0)