Skip to content
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

[3.12] gh-106446: Fix failed doctest in stdtypes (GH-106447) #106741

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

.. index:: single: true

By default, an object is considered true unless its class defines either a

Check warning on line 46 in Doc/library/stdtypes.rst

View workflow job for this annotation

GitHub Actions / Docs

py:meth reference target not found: __bool__

Check warning on line 46 in Doc/library/stdtypes.rst

View workflow job for this annotation

GitHub Actions / Docs

py:meth reference target not found: __len__
:meth:`__bool__` method that returns ``False`` or a :meth:`__len__` method that
returns zero, when called with the object. [1]_ Here are most of the built-in
objects considered false:
Expand Down Expand Up @@ -195,7 +195,7 @@
pair: operator; in
pair: operator; not in

Two more operations with the same syntactic priority, :keyword:`in` and

Check warning on line 198 in Doc/library/stdtypes.rst

View workflow job for this annotation

GitHub Actions / Docs

py:meth reference target not found: __contains__
:keyword:`not in`, are supported by types that are :term:`iterable` or
implement the :meth:`__contains__` method.

Expand Down Expand Up @@ -705,7 +705,7 @@
Hashing of numeric types
------------------------

For numbers ``x`` and ``y``, possibly of different types, it's a requirement

Check warning on line 708 in Doc/library/stdtypes.rst

View workflow job for this annotation

GitHub Actions / Docs

py:attr reference target not found: modulus
that ``hash(x) == hash(y)`` whenever ``x == y`` (see the :meth:`~object.__hash__`
method documentation for more details). For ease of implementation and
efficiency across a variety of numeric types (including :class:`int`,
Expand Down Expand Up @@ -902,7 +902,7 @@
Generator Types
---------------

Python's :term:`generator`\s provide a convenient way to implement the iterator

Check warning on line 905 in Doc/library/stdtypes.rst

View workflow job for this annotation

GitHub Actions / Docs

py:meth reference target not found: __iter__

Check warning on line 905 in Doc/library/stdtypes.rst

View workflow job for this annotation

GitHub Actions / Docs

py:meth reference target not found: __iter__
protocol. If a container object's :meth:`__iter__` method is implemented as a
generator, it will automatically return an iterator object (technically, a
generator object) supplying the :meth:`__iter__` and :meth:`~generator.__next__`
Expand Down Expand Up @@ -1223,22 +1223,22 @@
item is removed and returned.

(3)
:meth:`remove` raises :exc:`ValueError` when *x* is not found in *s*.

Check warning on line 1226 in Doc/library/stdtypes.rst

View workflow job for this annotation

GitHub Actions / Docs

py:meth reference target not found: remove

(4)
The :meth:`reverse` method modifies the sequence in place for economy of

Check warning on line 1229 in Doc/library/stdtypes.rst

View workflow job for this annotation

GitHub Actions / Docs

py:meth reference target not found: reverse
space when reversing a large sequence. To remind users that it operates by
side effect, it does not return the reversed sequence.

(5)
:meth:`clear` and :meth:`!copy` are included for consistency with the

Check warning on line 1234 in Doc/library/stdtypes.rst

View workflow job for this annotation

GitHub Actions / Docs

py:meth reference target not found: clear
interfaces of mutable containers that don't support slicing operations
(such as :class:`dict` and :class:`set`). :meth:`!copy` is not part of the
:class:`collections.abc.MutableSequence` ABC, but most concrete
mutable sequence classes provide it.

.. versionadded:: 3.3
:meth:`clear` and :meth:`!copy` methods.

Check warning on line 1241 in Doc/library/stdtypes.rst

View workflow job for this annotation

GitHub Actions / Docs

py:meth reference target not found: clear

(6)
The value *n* is an integer, or an object implementing
Expand Down Expand Up @@ -3950,7 +3950,7 @@
>>> m = memoryview(bytearray(b'abc'))
>>> mm = m.toreadonly()
>>> mm.tolist()
[89, 98, 99]
[97, 98, 99]
>>> mm[0] = 42
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Expand Down Expand Up @@ -4006,6 +4006,7 @@
:mod:`struct` syntax. One of the formats must be a byte format
('B', 'b' or 'c'). The byte length of the result must be the same
as the original length.
Note that all byte lengths may depend on the operating system.

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

Expand Down Expand Up @@ -4036,8 +4037,8 @@
>>> x = memoryview(b)
>>> x[0] = b'a'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: memoryview: invalid value for format "B"
...
TypeError: memoryview: invalid type for format 'B'
>>> y = x.cast('c')
>>> y[0] = b'a'
>>> b
Expand Down Expand Up @@ -4786,10 +4787,10 @@
>>> # set operations
>>> keys & {'eggs', 'bacon', 'salad'}
{'bacon'}
>>> keys ^ {'sausage', 'juice'}
{'juice', 'sausage', 'bacon', 'spam'}
>>> keys | ['juice', 'juice', 'juice']
{'juice', 'sausage', 'bacon', 'spam', 'eggs'}
>>> keys ^ {'sausage', 'juice'} == {'juice', 'sausage', 'bacon', 'spam'}
True
>>> keys | ['juice', 'juice', 'juice'] == {'bacon', 'spam', 'juice'}
True

>>> # get back a read-only proxy for the original dictionary
>>> values.mapping
Expand Down Expand Up @@ -4996,8 +4997,8 @@

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

However, such expressions are valid when :ref:`type variables <generics>` are
used. The index must have as many elements as there are type variable items
Expand Down Expand Up @@ -5203,13 +5204,15 @@
>>> isinstance("", int | str)
True

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

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

The user-exposed type for the union object can be accessed from
:data:`types.UnionType` and used for :func:`isinstance` checks. An object cannot be
Expand Down Expand Up @@ -5512,7 +5515,7 @@
definition order. Example::

>>> int.__subclasses__()
[<class 'bool'>]
[<class 'bool'>, <enum 'IntEnum'>, <flag 'IntFlag'>, <class 're._constants._NamedIntConstant'>]


.. _int_max_str_digits:
Expand Down Expand Up @@ -5548,15 +5551,15 @@
>>> _ = int('2' * 5432)
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.
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
>>> i = int('2' * 4300)
>>> len(str(i))
4300
>>> i_squared = i*i
>>> len(str(i_squared))
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.
ValueError: Exceeds the limit (4300 digits) for integer string conversion; use sys.set_int_max_str_digits() to increase the limit
>>> len(hex(i_squared))
7144
>>> assert int(hex(i_squared), base=16) == i*i # Hexadecimal is unlimited.
Expand Down