Skip to content

Commit 1b60244

Browse files
[3.11] GH-101100: Fix reference warnings for __getitem__ (GH-110118) (#111074)
Co-authored-by: Adam Turner <[email protected]>
1 parent 4fc5352 commit 1b60244

20 files changed

+38
-38
lines changed

Doc/glossary.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ Glossary
645645
iterables include all sequence types (such as :class:`list`, :class:`str`,
646646
and :class:`tuple`) and some non-sequence types like :class:`dict`,
647647
:term:`file objects <file object>`, and objects of any classes you define
648-
with an :meth:`__iter__` method or with a :meth:`__getitem__` method
648+
with an :meth:`__iter__` method or with a :meth:`~object.__getitem__` method
649649
that implements :term:`sequence` semantics.
650650

651651
Iterables can be
@@ -1085,17 +1085,17 @@ Glossary
10851085

10861086
sequence
10871087
An :term:`iterable` which supports efficient element access using integer
1088-
indices via the :meth:`__getitem__` special method and defines a
1088+
indices via the :meth:`~object.__getitem__` special method and defines a
10891089
:meth:`__len__` method that returns the length of the sequence.
10901090
Some built-in sequence types are :class:`list`, :class:`str`,
10911091
:class:`tuple`, and :class:`bytes`. Note that :class:`dict` also
1092-
supports :meth:`__getitem__` and :meth:`__len__`, but is considered a
1092+
supports :meth:`~object.__getitem__` and :meth:`__len__`, but is considered a
10931093
mapping rather than a sequence because the lookups use arbitrary
10941094
:term:`immutable` keys rather than integers.
10951095

10961096
The :class:`collections.abc.Sequence` abstract base class
10971097
defines a much richer interface that goes beyond just
1098-
:meth:`__getitem__` and :meth:`__len__`, adding :meth:`count`,
1098+
:meth:`~object.__getitem__` and :meth:`__len__`, adding :meth:`count`,
10991099
:meth:`index`, :meth:`__contains__`, and
11001100
:meth:`__reversed__`. Types that implement this expanded
11011101
interface can be registered explicitly using

Doc/library/abc.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ a helper class :class:`ABC` to alternatively define ABCs through inheritance:
154154
Finally, the last line makes ``Foo`` a virtual subclass of ``MyIterable``,
155155
even though it does not define an :meth:`~iterator.__iter__` method (it uses
156156
the old-style iterable protocol, defined in terms of :meth:`__len__` and
157-
:meth:`__getitem__`). Note that this will not make ``get_iterator``
157+
:meth:`~object.__getitem__`). Note that this will not make ``get_iterator``
158158
available as a method of ``Foo``, so it is provided separately.
159159

160160

Doc/library/collections.abc.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ ABC Inherits from Abstract Methods Mi
191191
.. [2] Checking ``isinstance(obj, Iterable)`` detects classes that are
192192
registered as :class:`Iterable` or that have an :meth:`__iter__`
193193
method, but it does not detect classes that iterate with the
194-
:meth:`__getitem__` method. The only reliable way to determine
194+
:meth:`~object.__getitem__` method. The only reliable way to determine
195195
whether an object is :term:`iterable` is to call ``iter(obj)``.
196196
197197
@@ -221,7 +221,7 @@ Collections Abstract Base Classes -- Detailed Descriptions
221221

222222
Checking ``isinstance(obj, Iterable)`` detects classes that are registered
223223
as :class:`Iterable` or that have an :meth:`__iter__` method, but it does
224-
not detect classes that iterate with the :meth:`__getitem__` method.
224+
not detect classes that iterate with the :meth:`~object.__getitem__` method.
225225
The only reliable way to determine whether an object is :term:`iterable`
226226
is to call ``iter(obj)``.
227227

@@ -261,8 +261,8 @@ Collections Abstract Base Classes -- Detailed Descriptions
261261

262262
Implementation note: Some of the mixin methods, such as
263263
:meth:`__iter__`, :meth:`__reversed__` and :meth:`index`, make
264-
repeated calls to the underlying :meth:`__getitem__` method.
265-
Consequently, if :meth:`__getitem__` is implemented with constant
264+
repeated calls to the underlying :meth:`~object.__getitem__` method.
265+
Consequently, if :meth:`~object.__getitem__` is implemented with constant
266266
access speed, the mixin methods will have linear performance;
267267
however, if the underlying method is linear (as it would be with a
268268
linked list), the mixins will have quadratic performance and will

Doc/library/collections.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -742,12 +742,12 @@ stack manipulations such as ``dup``, ``drop``, ``swap``, ``over``, ``pick``,
742742
If calling :attr:`default_factory` raises an exception this exception is
743743
propagated unchanged.
744744

745-
This method is called by the :meth:`__getitem__` method of the
745+
This method is called by the :meth:`~object.__getitem__` method of the
746746
:class:`dict` class when the requested key is not found; whatever it
747-
returns or raises is then returned or raised by :meth:`__getitem__`.
747+
returns or raises is then returned or raised by :meth:`~object.__getitem__`.
748748

749749
Note that :meth:`__missing__` is *not* called for any operations besides
750-
:meth:`__getitem__`. This means that :meth:`get` will, like normal
750+
:meth:`~object.__getitem__`. This means that :meth:`get` will, like normal
751751
dictionaries, return ``None`` as a default rather than using
752752
:attr:`default_factory`.
753753

Doc/library/email.compat32-message.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ Here are the methods of the :class:`Message` class:
367367
.. method:: get(name, failobj=None)
368368

369369
Return the value of the named header field. This is identical to
370-
:meth:`__getitem__` except that optional *failobj* is returned if the
370+
:meth:`~object.__getitem__` except that optional *failobj* is returned if the
371371
named header is missing (defaults to ``None``).
372372

373373
Here are some additional useful methods:

Doc/library/email.message.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ message objects.
247247
.. method:: get(name, failobj=None)
248248

249249
Return the value of the named header field. This is identical to
250-
:meth:`__getitem__` except that optional *failobj* is returned if the
250+
:meth:`~object.__getitem__` except that optional *failobj* is returned if the
251251
named header is missing (*failobj* defaults to ``None``).
252252

253253

Doc/library/functions.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ are always available. They are listed here in alphabetical order.
982982
differently depending on the presence of the second argument. Without a
983983
second argument, *object* must be a collection object which supports the
984984
:term:`iterable` protocol (the :meth:`__iter__` method), or it must support
985-
the sequence protocol (the :meth:`__getitem__` method with integer arguments
985+
the sequence protocol (the :meth:`~object.__getitem__` method with integer arguments
986986
starting at ``0``). If it does not support either of those protocols,
987987
:exc:`TypeError` is raised. If the second argument, *sentinel*, is given,
988988
then *object* must be a callable object. The iterator created in this case
@@ -1562,7 +1562,7 @@ are always available. They are listed here in alphabetical order.
15621562

15631563
Return a reverse :term:`iterator`. *seq* must be an object which has
15641564
a :meth:`__reversed__` method or supports the sequence protocol (the
1565-
:meth:`__len__` method and the :meth:`__getitem__` method with integer
1565+
:meth:`__len__` method and the :meth:`~object.__getitem__` method with integer
15661566
arguments starting at ``0``).
15671567

15681568

Doc/library/mailbox.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ Supported mailbox formats are Maildir, mbox, MH, Babyl, and MMDF.
167167
Return a representation of the message corresponding to *key*. If no such
168168
message exists, *default* is returned if the method was called as
169169
:meth:`get` and a :exc:`KeyError` exception is raised if the method was
170-
called as :meth:`__getitem__`. The message is represented as an instance
170+
called as :meth:`~object.__getitem__`. The message is represented as an instance
171171
of the appropriate format-specific :class:`Message` subclass unless a
172172
custom message factory was specified when the :class:`Mailbox` instance
173173
was initialized.

Doc/library/operator.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ expect a function argument.
306306
itemgetter(*items)
307307
308308
Return a callable object that fetches *item* from its operand using the
309-
operand's :meth:`__getitem__` method. If multiple items are specified,
309+
operand's :meth:`~object.__getitem__` method. If multiple items are specified,
310310
returns a tuple of lookup values. For example:
311311

312312
* After ``f = itemgetter(2)``, the call ``f(r)`` returns ``r[2]``.
@@ -326,7 +326,7 @@ expect a function argument.
326326
return tuple(obj[item] for item in items)
327327
return g
328328

329-
The items can be any type accepted by the operand's :meth:`__getitem__`
329+
The items can be any type accepted by the operand's :meth:`~object.__getitem__`
330330
method. Dictionaries accept any :term:`hashable` value. Lists, tuples, and
331331
strings accept an index or a slice:
332332

Doc/library/stdtypes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2220,7 +2220,7 @@ expression support in the :mod:`re` module).
22202220

22212221
Return a copy of the string in which each character has been mapped through
22222222
the given translation table. The table must be an object that implements
2223-
indexing via :meth:`__getitem__`, typically a :term:`mapping` or
2223+
indexing via :meth:`~object.__getitem__`, typically a :term:`mapping` or
22242224
:term:`sequence`. When indexed by a Unicode ordinal (an integer), the
22252225
table object can do any of the following: return a Unicode ordinal or a
22262226
string, to map the character to one or more other characters; return

0 commit comments

Comments
 (0)