[Python-checkins] cpython (merge 3.5 -> default): Issue #21240: Add an abstractmethod directive to mark abstract methods in the

berker.peksag python-checkins at python.org
Tue Dec 8 05:15:30 EST 2015


https://hg.python.org/cpython/rev/84468e1aea61
changeset:   99508:84468e1aea61
parent:      99506:d6e27eafb4e1
parent:      99507:1d0d8b27a4e6
user:        Berker Peksag <berker.peksag at gmail.com>
date:        Tue Dec 08 12:15:19 2015 +0200
summary:
  Issue #21240: Add an abstractmethod directive to mark abstract methods in the docs more explicitly

files:
  Doc/library/importlib.rst          |  12 ++++++------
  Doc/library/numbers.rst            |   2 +-
  Doc/library/selectors.rst          |   8 ++++----
  Doc/tools/extensions/pyspecific.py |  14 ++++++++++++++
  4 files changed, 25 insertions(+), 11 deletions(-)


diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst
--- a/Doc/library/importlib.rst
+++ b/Doc/library/importlib.rst
@@ -230,7 +230,7 @@
    .. deprecated:: 3.3
       Use :class:`MetaPathFinder` or :class:`PathEntryFinder` instead.
 
-   .. method:: find_module(fullname, path=None)
+   .. abstractmethod:: find_module(fullname, path=None)
 
       An abstact method for finding a :term:`loader` for the specified
       module.  Originally specified in :pep:`302`, this method was meant
@@ -453,7 +453,7 @@
     :pep:`302` protocol for loading arbitrary resources from the storage
     back-end.
 
-    .. method:: get_data(path)
+    .. abstractmethod:: get_data(path)
 
         An abstract method to return the bytes for the data located at *path*.
         Loaders that have a file-like storage back-end
@@ -489,7 +489,7 @@
         .. versionchanged:: 3.4
            No longer abstract and a concrete implementation is provided.
 
-    .. method:: get_source(fullname)
+    .. abstractmethod:: get_source(fullname)
 
         An abstract method to return the source of a module. It is returned as
         a text string using :term:`universal newlines`, translating all
@@ -546,7 +546,7 @@
     when implemented, helps a module to be executed as a script. The ABC
     represents an optional :pep:`302` protocol.
 
-    .. method:: get_filename(fullname)
+    .. abstractmethod:: get_filename(fullname)
 
         An abstract method that is to return the value of :attr:`__file__` for
         the specified module. If no path is available, :exc:`ImportError` is
@@ -586,11 +586,11 @@
       .. deprecated:: 3.4
          Use :meth:`Loader.exec_module` instead.
 
-   .. method:: get_filename(fullname)
+   .. abstractmethod:: get_filename(fullname)
 
       Returns :attr:`path`.
 
-   .. method:: get_data(path)
+   .. abstractmethod:: get_data(path)
 
       Reads *path* as a binary file and returns the bytes from it.
 
diff --git a/Doc/library/numbers.rst b/Doc/library/numbers.rst
--- a/Doc/library/numbers.rst
+++ b/Doc/library/numbers.rst
@@ -35,7 +35,7 @@
 
       Abstract. Retrieves the imaginary component of this number.
 
-   .. method:: conjugate()
+   .. abstractmethod:: conjugate()
 
       Abstract. Returns the complex conjugate. For example, ``(1+3j).conjugate()
       == (1-3j)``.
diff --git a/Doc/library/selectors.rst b/Doc/library/selectors.rst
--- a/Doc/library/selectors.rst
+++ b/Doc/library/selectors.rst
@@ -99,7 +99,7 @@
    :class:`BaseSelector` and its concrete implementations support the
    :term:`context manager` protocol.
 
-   .. method:: register(fileobj, events, data=None)
+   .. abstractmethod:: register(fileobj, events, data=None)
 
       Register a file object for selection, monitoring it for I/O events.
 
@@ -112,7 +112,7 @@
       :exc:`ValueError` in case of invalid event mask or file descriptor, or
       :exc:`KeyError` if the file object is already registered.
 
-   .. method:: unregister(fileobj)
+   .. abstractmethod:: unregister(fileobj)
 
       Unregister a file object from selection, removing it from monitoring. A
       file object shall be unregistered prior to being closed.
@@ -136,7 +136,7 @@
       :exc:`ValueError` in case of invalid event mask or file descriptor, or
       :exc:`KeyError` if the file object is not registered.
 
-   .. method:: select(timeout=None)
+   .. abstractmethod:: select(timeout=None)
 
       Wait until some registered file objects become ready, or the timeout
       expires.
@@ -179,7 +179,7 @@
       This returns the :class:`SelectorKey` instance associated to this file
       object, or raises :exc:`KeyError` if the file object is not registered.
 
-   .. method:: get_map()
+   .. abstractmethod:: get_map()
 
       Return a mapping of file objects to selector keys.
 
diff --git a/Doc/tools/extensions/pyspecific.py b/Doc/tools/extensions/pyspecific.py
--- a/Doc/tools/extensions/pyspecific.py
+++ b/Doc/tools/extensions/pyspecific.py
@@ -164,6 +164,19 @@
         return PyClassmember.run(self)
 
 
+class PyAbstractMethod(PyClassmember):
+
+    def handle_signature(self, sig, signode):
+        ret = super(PyAbstractMethod, self).handle_signature(sig, signode)
+        signode.insert(0, addnodes.desc_annotation('abstractmethod ',
+                                                   'abstractmethod '))
+        return ret
+
+    def run(self):
+        self.name = 'py:method'
+        return PyClassmember.run(self)
+
+
 # Support for documenting version of removal in deprecations
 
 class DeprecatedRemoved(Directive):
@@ -368,5 +381,6 @@
     app.add_directive_to_domain('py', 'decoratormethod', PyDecoratorMethod)
     app.add_directive_to_domain('py', 'coroutinefunction', PyCoroutineFunction)
     app.add_directive_to_domain('py', 'coroutinemethod', PyCoroutineMethod)
+    app.add_directive_to_domain('py', 'abstractmethod', PyAbstractMethod)
     app.add_directive('miscnews', MiscNews)
     return {'version': '1.0', 'parallel_read_safe': True}

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list