Skip to content

Commit 89867d2

Browse files
authoredJul 14, 2023
gh-106446: Fix failed doctest in stdtypes (#106447)
--------- Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
1 parent 21d98be commit 89867d2

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
@@ -3953,7 +3953,7 @@ copying.
39533953
>>> m = memoryview(bytearray(b'abc'))
39543954
>>> mm = m.toreadonly()
39553955
>>> mm.tolist()
3956-
[89, 98, 99]
3956+
[97, 98, 99]
39573957
>>> mm[0] = 42
39583958
Traceback (most recent call last):
39593959
File "<stdin>", line 1, in <module>
@@ -4009,6 +4009,7 @@ copying.
40094009
:mod:`struct` syntax. One of the formats must be a byte format
40104010
('B', 'b' or 'c'). The byte length of the result must be the same
40114011
as the original length.
4012+
Note that all byte lengths may depend on the operating system.
40124013

40134014
Cast 1D/long to 1D/unsigned bytes::
40144015

@@ -4039,8 +4040,8 @@ copying.
40394040
>>> x = memoryview(b)
40404041
>>> x[0] = b'a'
40414042
Traceback (most recent call last):
4042-
File "<stdin>", line 1, in <module>
4043-
ValueError: memoryview: invalid value for format "B"
4043+
...
4044+
TypeError: memoryview: invalid type for format 'B'
40444045
>>> y = x.cast('c')
40454046
>>> y[0] = b'a'
40464047
>>> b
@@ -4789,10 +4790,10 @@ An example of dictionary view usage::
47894790
>>> # set operations
47904791
>>> keys & {'eggs', 'bacon', 'salad'}
47914792
{'bacon'}
4792-
>>> keys ^ {'sausage', 'juice'}
4793-
{'juice', 'sausage', 'bacon', 'spam'}
4794-
>>> keys | ['juice', 'juice', 'juice']
4795-
{'juice', 'sausage', 'bacon', 'spam', 'eggs'}
4793+
>>> keys ^ {'sausage', 'juice'} == {'juice', 'sausage', 'bacon', 'spam'}
4794+
True
4795+
>>> keys | ['juice', 'juice', 'juice'] == {'bacon', 'spam', 'juice'}
4796+
True
47964797

47974798
>>> # get back a read-only proxy for the original dictionary
47984799
>>> values.mapping
@@ -4999,8 +5000,8 @@ exception to disallow mistakes like ``dict[str][str]``::
49995000

50005001
>>> dict[str][str]
50015002
Traceback (most recent call last):
5002-
File "<stdin>", line 1, in <module>
5003-
TypeError: There are no type variables left in dict[str]
5003+
...
5004+
TypeError: dict[str] is not a generic class
50045005

50055006
However, such expressions are valid when :ref:`type variables <generics>` are
50065007
used. The index must have as many elements as there are type variable items
@@ -5206,13 +5207,15 @@ enables cleaner type hinting syntax compared to :data:`typing.Union`.
52065207
>>> isinstance("", int | str)
52075208
True
52085209

5209-
However, union objects containing :ref:`parameterized generics
5210-
<types-genericalias>` cannot be used::
5210+
However, :ref:`parameterized generics <types-genericalias>` in
5211+
union objects cannot be checked::
52115212

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

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

55175520
>>> int.__subclasses__()
5518-
[<class 'bool'>]
5521+
[<class 'bool'>, <enum 'IntEnum'>, <flag 'IntFlag'>, <class 're._constants._NamedIntConstant'>]
55195522

55205523

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

0 commit comments

Comments
 (0)
Please sign in to comment.