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

Doc/library/unittest.mock.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1656,7 +1656,7 @@ Keywords can be used in the :func:`patch.dict` call to set values in the diction
16561656
:func:`patch.dict` can be used with dictionary like objects that aren't actually
16571657
dictionaries. At the very minimum they must support item getting, setting,
16581658
deleting and either iteration or membership test. This corresponds to the
1659-
magic methods :meth:`__getitem__`, :meth:`__setitem__`, :meth:`__delitem__` and either
1659+
magic methods :meth:`~object.__getitem__`, :meth:`__setitem__`, :meth:`__delitem__` and either
16601660
:meth:`__iter__` or :meth:`__contains__`.
16611661

16621662
>>> class Container:

Doc/library/wsgiref.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ also provides these miscellaneous utilities:
180180
print(chunk)
181181

182182
.. versionchanged:: 3.11
183-
Support for :meth:`__getitem__` method has been removed.
183+
Support for :meth:`~object.__getitem__` method has been removed.
184184

185185

186186
:mod:`wsgiref.headers` -- WSGI response header tools
@@ -201,7 +201,7 @@ manipulation of WSGI response headers using a mapping-like interface.
201201
an empty list.
202202

203203
:class:`Headers` objects support typical mapping operations including
204-
:meth:`__getitem__`, :meth:`get`, :meth:`__setitem__`, :meth:`setdefault`,
204+
:meth:`~object.__getitem__`, :meth:`get`, :meth:`__setitem__`, :meth:`setdefault`,
205205
:meth:`__delitem__` and :meth:`__contains__`. For each of
206206
these methods, the key is the header name (treated case-insensitively), and the
207207
value is the first value associated with that header name. Setting a header

Doc/library/xml.dom.pulldom.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ DOMEventStream Objects
115115
.. class:: DOMEventStream(stream, parser, bufsize)
116116

117117
.. versionchanged:: 3.11
118-
Support for :meth:`__getitem__` method has been removed.
118+
Support for :meth:`~object.__getitem__` method has been removed.
119119

120120
.. method:: getEvent()
121121

Doc/reference/compound_stmts.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ subject value:
10601060
.. note:: Key-value pairs are matched using the two-argument form of the mapping
10611061
subject's ``get()`` method. Matched key-value pairs must already be present
10621062
in the mapping, and not created on-the-fly via :meth:`__missing__` or
1063-
:meth:`__getitem__`.
1063+
:meth:`~object.__getitem__`.
10641064

10651065
In simple terms ``{KEY1: P1, KEY2: P2, ... }`` matches only if all the following
10661066
happens:

Doc/reference/expressions.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ to the index so that, for example, ``x[-1]`` selects the last item of ``x``. The
872872
resulting value must be a nonnegative integer less than the number of items in
873873
the sequence, and the subscription selects the item whose index is that value
874874
(counting from zero). Since the support for negative indices and slicing
875-
occurs in the object's :meth:`__getitem__` method, subclasses overriding
875+
occurs in the object's :meth:`~object.__getitem__` method, subclasses overriding
876876
this method will need to explicitly add that support.
877877

878878
.. index::
@@ -927,7 +927,7 @@ slice list contains no proper slice).
927927
single: step (slice object attribute)
928928

929929
The semantics for a slicing are as follows. The primary is indexed (using the
930-
same :meth:`__getitem__` method as
930+
same :meth:`~object.__getitem__` method as
931931
normal subscription) with a key that is constructed from the slice list, as
932932
follows. If the slice list contains at least one comma, the key is a tuple
933933
containing the conversion of the slice items; otherwise, the conversion of the
@@ -1653,7 +1653,7 @@ If an exception is raised during the iteration, it is as if :keyword:`in` raised
16531653
that exception.
16541654

16551655
Lastly, the old-style iteration protocol is tried: if a class defines
1656-
:meth:`__getitem__`, ``x in y`` is ``True`` if and only if there is a non-negative
1656+
:meth:`~object.__getitem__`, ``x in y`` is ``True`` if and only if there is a non-negative
16571657
integer index *i* such that ``x is y[i] or x == y[i]``, and no lower integer index
16581658
raises the :exc:`IndexError` exception. (If any other exception is raised, it is as
16591659
if :keyword:`in` raised that exception).

Doc/whatsnew/2.2.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -424,22 +424,22 @@ Another significant addition to 2.2 is an iteration interface at both the C and
424424
Python levels. Objects can define how they can be looped over by callers.
425425

426426
In Python versions up to 2.1, the usual way to make ``for item in obj`` work is
427-
to define a :meth:`__getitem__` method that looks something like this::
427+
to define a :meth:`~object.__getitem__` method that looks something like this::
428428

429429
def __getitem__(self, index):
430430
return <next item>
431431

432-
:meth:`__getitem__` is more properly used to define an indexing operation on an
432+
:meth:`~object.__getitem__` is more properly used to define an indexing operation on an
433433
object so that you can write ``obj[5]`` to retrieve the sixth element. It's a
434434
bit misleading when you're using this only to support :keyword:`for` loops.
435435
Consider some file-like object that wants to be looped over; the *index*
436436
parameter is essentially meaningless, as the class probably assumes that a
437-
series of :meth:`__getitem__` calls will be made with *index* incrementing by
438-
one each time. In other words, the presence of the :meth:`__getitem__` method
437+
series of :meth:`~object.__getitem__` calls will be made with *index* incrementing by
438+
one each time. In other words, the presence of the :meth:`~object.__getitem__` method
439439
doesn't mean that using ``file[5]`` to randomly access the sixth element will
440440
work, though it really should.
441441

442-
In Python 2.2, iteration can be implemented separately, and :meth:`__getitem__`
442+
In Python 2.2, iteration can be implemented separately, and :meth:`~object.__getitem__`
443443
methods can be limited to classes that really do support random access. The
444444
basic idea of iterators is simple. A new built-in function, ``iter(obj)``
445445
or ``iter(C, sentinel)``, is used to get an iterator. ``iter(obj)`` returns

Doc/whatsnew/2.3.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ Deletion is more straightforward::
925925
>>> a
926926
[1, 3]
927927

928-
One can also now pass slice objects to the :meth:`__getitem__` methods of the
928+
One can also now pass slice objects to the :meth:`~object.__getitem__` methods of the
929929
built-in sequences::
930930

931931
>>> range(10).__getitem__(slice(0, 5, 2))
@@ -1596,7 +1596,7 @@ complete list of changes, or look through the CVS logs for all the details.
15961596
module.
15971597

15981598
Adding the mix-in as a superclass provides the full dictionary interface
1599-
whenever the class defines :meth:`__getitem__`, :meth:`__setitem__`,
1599+
whenever the class defines :meth:`~object.__getitem__`, :meth:`__setitem__`,
16001600
:meth:`__delitem__`, and :meth:`keys`. For example::
16011601

16021602
>>> import UserDict

Doc/whatsnew/3.8.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,7 @@ Deprecated
16501650
deprecated and will be prohibited in Python 3.9.
16511651
(Contributed by Elvis Pranskevichus in :issue:`34075`.)
16521652

1653-
* The :meth:`__getitem__` methods of :class:`xml.dom.pulldom.DOMEventStream`,
1653+
* The :meth:`~object.__getitem__` methods of :class:`xml.dom.pulldom.DOMEventStream`,
16541654
:class:`wsgiref.util.FileWrapper` and :class:`fileinput.FileInput` have been
16551655
deprecated.
16561656

Misc/NEWS.d/3.11.0a1.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1720,7 +1720,7 @@ Improve the speed and accuracy of statistics.pvariance().
17201720
.. nonce: WI9zQY
17211721
.. section: Library
17221722
1723-
Remove :meth:`__getitem__` methods of
1723+
Remove :meth:`~object.__getitem__` methods of
17241724
:class:`xml.dom.pulldom.DOMEventStream`, :class:`wsgiref.util.FileWrapper`
17251725
and :class:`fileinput.FileInput`, deprecated since Python 3.9.
17261726

Misc/NEWS.d/3.8.0a1.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3592,7 +3592,7 @@ Python 3.5.
35923592
.. nonce: V8Ou3K
35933593
.. section: Library
35943594
3595-
Deprecate :meth:`__getitem__` methods of
3595+
Deprecate :meth:`~object.__getitem__` methods of
35963596
:class:`xml.dom.pulldom.DOMEventStream`, :class:`wsgiref.util.FileWrapper`
35973597
and :class:`fileinput.FileInput`.
35983598

0 commit comments

Comments
 (0)