Skip to content

Commit cdcab40

Browse files
[3.12] GH-101100: Fix reference warnings for __getitem__ (GH-110118) (#111073)
Co-authored-by: Adam Turner <[email protected]>
1 parent 68a5640 commit cdcab40

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
@@ -1087,17 +1087,17 @@ Glossary
10871087

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

10981098
The :class:`collections.abc.Sequence` abstract base class
10991099
defines a much richer interface that goes beyond just
1100-
:meth:`__getitem__` and :meth:`__len__`, adding :meth:`count`,
1100+
:meth:`~object.__getitem__` and :meth:`__len__`, adding :meth:`count`,
11011101
:meth:`index`, :meth:`__contains__`, and
11021102
:meth:`__reversed__`. Types that implement this expanded
11031103
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
@@ -192,7 +192,7 @@ ABC Inherits from Abstract Methods Mi
192192
.. [2] Checking ``isinstance(obj, Iterable)`` detects classes that are
193193
registered as :class:`Iterable` or that have an :meth:`__iter__`
194194
method, but it does not detect classes that iterate with the
195-
:meth:`__getitem__` method. The only reliable way to determine
195+
:meth:`~object.__getitem__` method. The only reliable way to determine
196196
whether an object is :term:`iterable` is to call ``iter(obj)``.
197197
198198
@@ -222,7 +222,7 @@ Collections Abstract Base Classes -- Detailed Descriptions
222222

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

@@ -262,8 +262,8 @@ Collections Abstract Base Classes -- Detailed Descriptions
262262

263263
Implementation note: Some of the mixin methods, such as
264264
:meth:`__iter__`, :meth:`__reversed__` and :meth:`index`, make
265-
repeated calls to the underlying :meth:`__getitem__` method.
266-
Consequently, if :meth:`__getitem__` is implemented with constant
265+
repeated calls to the underlying :meth:`~object.__getitem__` method.
266+
Consequently, if :meth:`~object.__getitem__` is implemented with constant
267267
access speed, the mixin methods will have linear performance;
268268
however, if the underlying method is linear (as it would be with a
269269
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
@@ -743,12 +743,12 @@ stack manipulations such as ``dup``, ``drop``, ``swap``, ``over``, ``pick``,
743743
If calling :attr:`default_factory` raises an exception this exception is
744744
propagated unchanged.
745745

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

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

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
@@ -983,7 +983,7 @@ are always available. They are listed here in alphabetical order.
983983
differently depending on the presence of the second argument. Without a
984984
second argument, *object* must be a collection object which supports the
985985
:term:`iterable` protocol (the :meth:`__iter__` method), or it must support
986-
the sequence protocol (the :meth:`__getitem__` method with integer arguments
986+
the sequence protocol (the :meth:`~object.__getitem__` method with integer arguments
987987
starting at ``0``). If it does not support either of those protocols,
988988
:exc:`TypeError` is raised. If the second argument, *sentinel*, is given,
989989
then *object* must be a callable object. The iterator created in this case
@@ -1563,7 +1563,7 @@ are always available. They are listed here in alphabetical order.
15631563

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

15691569

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
@@ -2264,7 +2264,7 @@ expression support in the :mod:`re` module).
22642264

22652265
Return a copy of the string in which each character has been mapped through
22662266
the given translation table. The table must be an object that implements
2267-
indexing via :meth:`__getitem__`, typically a :term:`mapping` or
2267+
indexing via :meth:`~object.__getitem__`, typically a :term:`mapping` or
22682268
:term:`sequence`. When indexed by a Unicode ordinal (an integer), the
22692269
table object can do any of the following: return a Unicode ordinal or a
22702270
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
@@ -1658,7 +1658,7 @@ Keywords can be used in the :func:`patch.dict` call to set values in the diction
16581658
:func:`patch.dict` can be used with dictionary like objects that aren't actually
16591659
dictionaries. At the very minimum they must support item getting, setting,
16601660
deleting and either iteration or membership test. This corresponds to the
1661-
magic methods :meth:`__getitem__`, :meth:`__setitem__`, :meth:`__delitem__` and either
1661+
magic methods :meth:`~object.__getitem__`, :meth:`__setitem__`, :meth:`__delitem__` and either
16621662
:meth:`__iter__` or :meth:`__contains__`.
16631663

16641664
>>> 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
@@ -1058,7 +1058,7 @@ subject value:
10581058
.. note:: Key-value pairs are matched using the two-argument form of the mapping
10591059
subject's ``get()`` method. Matched key-value pairs must already be present
10601060
in the mapping, and not created on-the-fly via :meth:`__missing__` or
1061-
:meth:`__getitem__`.
1061+
:meth:`~object.__getitem__`.
10621062

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

Doc/reference/expressions.rst

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

888888
.. index::
@@ -937,7 +937,7 @@ slice list contains no proper slice).
937937
single: step (slice object attribute)
938938

939939
The semantics for a slicing are as follows. The primary is indexed (using the
940-
same :meth:`__getitem__` method as
940+
same :meth:`~object.__getitem__` method as
941941
normal subscription) with a key that is constructed from the slice list, as
942942
follows. If the slice list contains at least one comma, the key is a tuple
943943
containing the conversion of the slice items; otherwise, the conversion of the
@@ -1663,7 +1663,7 @@ If an exception is raised during the iteration, it is as if :keyword:`in` raised
16631663
that exception.
16641664

16651665
Lastly, the old-style iteration protocol is tried: if a class defines
1666-
:meth:`__getitem__`, ``x in y`` is ``True`` if and only if there is a non-negative
1666+
:meth:`~object.__getitem__`, ``x in y`` is ``True`` if and only if there is a non-negative
16671667
integer index *i* such that ``x is y[i] or x == y[i]``, and no lower integer index
16681668
raises the :exc:`IndexError` exception. (If any other exception is raised, it is as
16691669
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
@@ -1653,7 +1653,7 @@ Deprecated
16531653
deprecated and will be prohibited in Python 3.9.
16541654
(Contributed by Elvis Pranskevichus in :issue:`34075`.)
16551655

1656-
* The :meth:`__getitem__` methods of :class:`xml.dom.pulldom.DOMEventStream`,
1656+
* The :meth:`~object.__getitem__` methods of :class:`xml.dom.pulldom.DOMEventStream`,
16571657
:class:`wsgiref.util.FileWrapper` and :class:`fileinput.FileInput` have been
16581658
deprecated.
16591659

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)