Skip to content

Commit 30e8924

Browse files
authored
GH-121970: Replace custom abstract method directive with the :abstract: option (#129311)
1 parent 8e96adf commit 30e8924

File tree

6 files changed

+66
-47
lines changed

6 files changed

+66
-47
lines changed

Doc/library/importlib.resources.abc.rst

+22-11
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,31 @@
4646
.. deprecated:: 3.12
4747
Use :class:`importlib.resources.abc.TraversableResources` instead.
4848

49-
.. abstractmethod:: open_resource(resource)
49+
.. method:: open_resource(resource)
50+
:abstractmethod:
5051

5152
Returns an opened, :term:`file-like object` for binary reading
5253
of the *resource*.
5354

5455
If the resource cannot be found, :exc:`FileNotFoundError` is
5556
raised.
5657

57-
.. abstractmethod:: resource_path(resource)
58+
.. method:: resource_path(resource)
59+
:abstractmethod:
5860

5961
Returns the file system path to the *resource*.
6062

6163
If the resource does not concretely exist on the file system,
6264
raise :exc:`FileNotFoundError`.
6365

64-
.. abstractmethod:: is_resource(name)
66+
.. method:: is_resource(name)
67+
:abstractmethod:
6568

6669
Returns ``True`` if the named *name* is considered a resource.
6770
:exc:`FileNotFoundError` is raised if *name* does not exist.
6871

69-
.. abstractmethod:: contents()
72+
.. method:: contents()
73+
:abstractmethod:
7074

7175
Returns an :term:`iterable` of strings over the contents of
7276
the package. Do note that it is not required that all names
@@ -97,19 +101,23 @@
97101

98102
Abstract. The base name of this object without any parent references.
99103

100-
.. abstractmethod:: iterdir()
104+
.. method:: iterdir()
105+
:abstractmethod:
101106

102107
Yield Traversable objects in self.
103108

104-
.. abstractmethod:: is_dir()
109+
.. method:: is_dir()
110+
:abstractmethod:
105111

106112
Return ``True`` if self is a directory.
107113

108-
.. abstractmethod:: is_file()
114+
.. method:: is_file()
115+
:abstractmethod:
109116

110117
Return ``True`` if self is a file.
111118

112-
.. abstractmethod:: joinpath(*pathsegments)
119+
.. method:: joinpath(*pathsegments)
120+
:abstractmethod:
113121

114122
Traverse directories according to *pathsegments* and return
115123
the result as :class:`!Traversable`.
@@ -134,12 +142,14 @@
134142
may contain forward slashes as path separators.
135143
Previously, only a single *child* argument was accepted.
136144

137-
.. abstractmethod:: __truediv__(child)
145+
.. method:: __truediv__(child)
146+
:abstractmethod:
138147

139148
Return Traversable child in self.
140149
Equivalent to ``joinpath(child)``.
141150

142-
.. abstractmethod:: open(mode='r', *args, **kwargs)
151+
.. method:: open(mode='r', *args, **kwargs)
152+
:abstractmethod:
143153

144154
*mode* may be 'r' or 'rb' to open as text or binary. Return a handle
145155
suitable for reading (same as :attr:`pathlib.Path.open`).
@@ -168,7 +178,8 @@
168178
Loaders that wish to support resource reading are expected to
169179
implement this interface.
170180

171-
.. abstractmethod:: files()
181+
.. method:: files()
182+
:abstractmethod:
172183

173184
Returns a :class:`importlib.resources.abc.Traversable` object for the loaded
174185
package.

Doc/library/importlib.rst

+32-16
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,8 @@ ABC hierarchy::
390390
This ABC is deprecated in favour of supporting resource loading
391391
through :class:`importlib.resources.abc.TraversableResources`.
392392

393-
.. abstractmethod:: get_data(path)
393+
.. method:: get_data(path)
394+
:abstractmethod:
394395

395396
An abstract method to return the bytes for the data located at *path*.
396397
Loaders that have a file-like storage back-end
@@ -427,7 +428,8 @@ ABC hierarchy::
427428
.. versionchanged:: 3.4
428429
No longer abstract and a concrete implementation is provided.
429430

430-
.. abstractmethod:: get_source(fullname)
431+
.. method:: get_source(fullname)
432+
:abstractmethod:
431433

432434
An abstract method to return the source of a module. It is returned as
433435
a text string using :term:`universal newlines`, translating all
@@ -484,7 +486,8 @@ ABC hierarchy::
484486
when implemented, helps a module to be executed as a script. The ABC
485487
represents an optional :pep:`302` protocol.
486488

487-
.. abstractmethod:: get_filename(fullname)
489+
.. method:: get_filename(fullname)
490+
:abstractmethod:
488491

489492
An abstract method that is to return the value of
490493
:attr:`~module.__file__` for the specified module. If no path is
@@ -524,11 +527,13 @@ ABC hierarchy::
524527
.. deprecated-removed:: 3.4 3.15
525528
Use :meth:`Loader.exec_module` instead.
526529

527-
.. abstractmethod:: get_filename(fullname)
530+
.. method:: get_filename(fullname)
531+
:abstractmethod:
528532

529533
Returns :attr:`path`.
530534

531-
.. abstractmethod:: get_data(path)
535+
.. method:: get_data(path)
536+
:abstractmethod:
532537

533538
Reads *path* as a binary file and returns the bytes from it.
534539

@@ -664,27 +669,31 @@ ABC hierarchy::
664669
.. deprecated-removed:: 3.12 3.14
665670
Use :class:`importlib.resources.abc.TraversableResources` instead.
666671

667-
.. abstractmethod:: open_resource(resource)
672+
.. method:: open_resource(resource)
673+
:abstractmethod:
668674

669675
Returns an opened, :term:`file-like object` for binary reading
670676
of the *resource*.
671677

672678
If the resource cannot be found, :exc:`FileNotFoundError` is
673679
raised.
674680

675-
.. abstractmethod:: resource_path(resource)
681+
.. method:: resource_path(resource)
682+
:abstractmethod:
676683

677684
Returns the file system path to the *resource*.
678685

679686
If the resource does not concretely exist on the file system,
680687
raise :exc:`FileNotFoundError`.
681688

682-
.. abstractmethod:: is_resource(name)
689+
.. method:: is_resource(name)
690+
:abstractmethod:
683691

684692
Returns ``True`` if the named *name* is considered a resource.
685693
:exc:`FileNotFoundError` is raised if *name* does not exist.
686694

687-
.. abstractmethod:: contents()
695+
.. method:: contents()
696+
:abstractmethod:
688697

689698
Returns an :term:`iterable` of strings over the contents of
690699
the package. Do note that it is not required that all names
@@ -720,27 +729,33 @@ ABC hierarchy::
720729

721730
Abstract. The base name of this object without any parent references.
722731

723-
.. abstractmethod:: iterdir()
732+
.. method:: iterdir()
733+
:abstractmethod:
724734

725735
Yield ``Traversable`` objects in ``self``.
726736

727-
.. abstractmethod:: is_dir()
737+
.. method:: is_dir()
738+
:abstractmethod:
728739

729740
Return ``True`` if ``self`` is a directory.
730741

731-
.. abstractmethod:: is_file()
742+
.. method:: is_file()
743+
:abstractmethod:
732744

733745
Return ``True`` if ``self`` is a file.
734746

735-
.. abstractmethod:: joinpath(child)
747+
.. method:: joinpath(child)
748+
:abstractmethod:
736749

737750
Return Traversable child in ``self``.
738751

739-
.. abstractmethod:: __truediv__(child)
752+
.. method:: __truediv__(child)
753+
:abstractmethod:
740754

741755
Return ``Traversable`` child in ``self``.
742756

743-
.. abstractmethod:: open(mode='r', *args, **kwargs)
757+
.. method:: open(mode='r', *args, **kwargs)
758+
:abstractmethod:
744759

745760
*mode* may be 'r' or 'rb' to open as text or binary. Return a handle
746761
suitable for reading (same as :attr:`pathlib.Path.open`).
@@ -774,7 +789,8 @@ ABC hierarchy::
774789
.. deprecated-removed:: 3.12 3.14
775790
Use :class:`importlib.resources.abc.TraversableResources` instead.
776791

777-
.. abstractmethod:: files()
792+
.. method:: files()
793+
:abstractmethod:
778794

779795
Returns a :class:`importlib.resources.abc.Traversable` object for the loaded
780796
package.

Doc/library/numbers.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ The numeric tower
3838

3939
Abstract. Retrieves the imaginary component of this number.
4040

41-
.. abstractmethod:: conjugate()
41+
.. method:: conjugate()
42+
:abstractmethod:
4243

4344
Abstract. Returns the complex conjugate. For example, ``(1+3j).conjugate()
4445
== (1-3j)``.

Doc/library/os.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,8 @@ process and user.
321321

322322
.. versionadded:: 3.6
323323

324-
.. abstractmethod:: __fspath__()
324+
.. method:: __fspath__()
325+
:abstractmethod:
325326

326327
Return the file system path representation of the object.
327328

Doc/library/selectors.rst

+8-4
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ constants below:
103103
:class:`BaseSelector` and its concrete implementations support the
104104
:term:`context manager` protocol.
105105

106-
.. abstractmethod:: register(fileobj, events, data=None)
106+
.. method:: register(fileobj, events, data=None)
107+
:abstractmethod:
107108

108109
Register a file object for selection, monitoring it for I/O events.
109110

@@ -116,7 +117,8 @@ constants below:
116117
:exc:`ValueError` in case of invalid event mask or file descriptor, or
117118
:exc:`KeyError` if the file object is already registered.
118119

119-
.. abstractmethod:: unregister(fileobj)
120+
.. method:: unregister(fileobj)
121+
:abstractmethod:
120122

121123
Unregister a file object from selection, removing it from monitoring. A
122124
file object shall be unregistered prior to being closed.
@@ -140,7 +142,8 @@ constants below:
140142
:exc:`ValueError` in case of invalid event mask or file descriptor, or
141143
:exc:`KeyError` if the file object is not registered.
142144

143-
.. abstractmethod:: select(timeout=None)
145+
.. method:: select(timeout=None)
146+
:abstractmethod:
144147

145148
Wait until some registered file objects become ready, or the timeout
146149
expires.
@@ -183,7 +186,8 @@ constants below:
183186
This returns the :class:`SelectorKey` instance associated to this file
184187
object, or raises :exc:`KeyError` if the file object is not registered.
185188

186-
.. abstractmethod:: get_map()
189+
.. method:: get_map()
190+
:abstractmethod:
187191

188192
Return a mapping of file objects to selector keys.
189193

Doc/tools/extensions/pyspecific.py

-14
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,6 @@ def run(self):
103103
return PyMethod.run(self)
104104

105105

106-
class PyAbstractMethod(PyMethod):
107-
108-
def handle_signature(self, sig, signode):
109-
ret = super(PyAbstractMethod, self).handle_signature(sig, signode)
110-
signode.insert(0, addnodes.desc_annotation('abstractmethod ',
111-
'abstractmethod '))
112-
return ret
113-
114-
def run(self):
115-
self.name = 'py:method'
116-
return PyMethod.run(self)
117-
118-
119106
# Support for documenting Opcodes
120107

121108
opcode_sig_re = re.compile(r'(\w+(?:\+\d)?)(?:\s*\((.*)\))?')
@@ -201,6 +188,5 @@ def setup(app):
201188
app.add_directive_to_domain('py', 'coroutinemethod', PyCoroutineMethod)
202189
app.add_directive_to_domain('py', 'awaitablefunction', PyAwaitableFunction)
203190
app.add_directive_to_domain('py', 'awaitablemethod', PyAwaitableMethod)
204-
app.add_directive_to_domain('py', 'abstractmethod', PyAbstractMethod)
205191
app.connect('env-check-consistency', patch_pairindextypes)
206192
return {'version': '1.0', 'parallel_read_safe': True}

0 commit comments

Comments
 (0)