Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6e9d2e6

Browse files
committed
Issue #21240: Add an abstractmethod directive to mark abstract methods in the docs more explicitly
1 parent 45be8d6 commit 6e9d2e6

4 files changed

Lines changed: 25 additions & 11 deletions

File tree

Doc/library/importlib.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ ABC hierarchy::
230230
.. deprecated:: 3.3
231231
Use :class:`MetaPathFinder` or :class:`PathEntryFinder` instead.
232232

233-
.. method:: find_module(fullname, path=None)
233+
.. abstractmethod:: find_module(fullname, path=None)
234234

235235
An abstact method for finding a :term:`loader` for the specified
236236
module. Originally specified in :pep:`302`, this method was meant
@@ -453,7 +453,7 @@ ABC hierarchy::
453453
:pep:`302` protocol for loading arbitrary resources from the storage
454454
back-end.
455455

456-
.. method:: get_data(path)
456+
.. abstractmethod:: get_data(path)
457457

458458
An abstract method to return the bytes for the data located at *path*.
459459
Loaders that have a file-like storage back-end
@@ -489,7 +489,7 @@ ABC hierarchy::
489489
.. versionchanged:: 3.4
490490
No longer abstract and a concrete implementation is provided.
491491

492-
.. method:: get_source(fullname)
492+
.. abstractmethod:: get_source(fullname)
493493

494494
An abstract method to return the source of a module. It is returned as
495495
a text string using :term:`universal newlines`, translating all
@@ -546,7 +546,7 @@ ABC hierarchy::
546546
when implemented, helps a module to be executed as a script. The ABC
547547
represents an optional :pep:`302` protocol.
548548

549-
.. method:: get_filename(fullname)
549+
.. abstractmethod:: get_filename(fullname)
550550

551551
An abstract method that is to return the value of :attr:`__file__` for
552552
the specified module. If no path is available, :exc:`ImportError` is
@@ -586,11 +586,11 @@ ABC hierarchy::
586586
.. deprecated:: 3.4
587587
Use :meth:`Loader.exec_module` instead.
588588

589-
.. method:: get_filename(fullname)
589+
.. abstractmethod:: get_filename(fullname)
590590

591591
Returns :attr:`path`.
592592

593-
.. method:: get_data(path)
593+
.. abstractmethod:: get_data(path)
594594

595595
Reads *path* as a binary file and returns the bytes from it.
596596

Doc/library/numbers.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ The numeric tower
3535

3636
Abstract. Retrieves the imaginary component of this number.
3737

38-
.. method:: conjugate()
38+
.. abstractmethod:: conjugate()
3939

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

Doc/library/selectors.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ constants below:
9999
:class:`BaseSelector` and its concrete implementations support the
100100
:term:`context manager` protocol.
101101

102-
.. method:: register(fileobj, events, data=None)
102+
.. abstractmethod:: register(fileobj, events, data=None)
103103

104104
Register a file object for selection, monitoring it for I/O events.
105105

@@ -112,7 +112,7 @@ constants below:
112112
:exc:`ValueError` in case of invalid event mask or file descriptor, or
113113
:exc:`KeyError` if the file object is already registered.
114114

115-
.. method:: unregister(fileobj)
115+
.. abstractmethod:: unregister(fileobj)
116116

117117
Unregister a file object from selection, removing it from monitoring. A
118118
file object shall be unregistered prior to being closed.
@@ -136,7 +136,7 @@ constants below:
136136
:exc:`ValueError` in case of invalid event mask or file descriptor, or
137137
:exc:`KeyError` if the file object is not registered.
138138

139-
.. method:: select(timeout=None)
139+
.. abstractmethod:: select(timeout=None)
140140

141141
Wait until some registered file objects become ready, or the timeout
142142
expires.
@@ -179,7 +179,7 @@ constants below:
179179
This returns the :class:`SelectorKey` instance associated to this file
180180
object, or raises :exc:`KeyError` if the file object is not registered.
181181

182-
.. method:: get_map()
182+
.. abstractmethod:: get_map()
183183

184184
Return a mapping of file objects to selector keys.
185185

Doc/tools/extensions/pyspecific.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,19 @@ def run(self):
164164
return PyClassmember.run(self)
165165

166166

167+
class PyAbstractMethod(PyClassmember):
168+
169+
def handle_signature(self, sig, signode):
170+
ret = super(PyAbstractMethod, self).handle_signature(sig, signode)
171+
signode.insert(0, addnodes.desc_annotation('abstractmethod ',
172+
'abstractmethod '))
173+
return ret
174+
175+
def run(self):
176+
self.name = 'py:method'
177+
return PyClassmember.run(self)
178+
179+
167180
# Support for documenting version of removal in deprecations
168181

169182
class DeprecatedRemoved(Directive):
@@ -368,5 +381,6 @@ def setup(app):
368381
app.add_directive_to_domain('py', 'decoratormethod', PyDecoratorMethod)
369382
app.add_directive_to_domain('py', 'coroutinefunction', PyCoroutineFunction)
370383
app.add_directive_to_domain('py', 'coroutinemethod', PyCoroutineMethod)
384+
app.add_directive_to_domain('py', 'abstractmethod', PyAbstractMethod)
371385
app.add_directive('miscnews', MiscNews)
372386
return {'version': '1.0', 'parallel_read_safe': True}

0 commit comments

Comments
 (0)