mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Add :abstractmethod: option to py:method directive (refs: #6138)
This commit is contained in:
parent
af9df449ea
commit
358e582490
1
CHANGES
1
CHANGES
@ -88,6 +88,7 @@ Features added
|
||||
* #4777: py domain: Add ``:async:`` option to :rst:dir:`py:function` directive
|
||||
* py domain: Add new options to :rst:dir:`py:method` directive
|
||||
|
||||
- ``:abstractmethod:``
|
||||
- ``:async:``
|
||||
- ``:classmethod:``
|
||||
- ``:property:``
|
||||
|
@ -226,16 +226,17 @@ The following directives are provided for module and class contents:
|
||||
The ``async`` option can be given (with no value) to indicate the method is
|
||||
an async method.
|
||||
|
||||
The ``classmethod`` option and ``staticmethod`` option can be given (with
|
||||
no value) to indicate the method is a class method (or a static method).
|
||||
The ``abstractmethod``, ``classmethod`` option and ``staticmethod`` option
|
||||
can be given (with no value) to indicate the method is an abstract method,
|
||||
a class method or a static method.
|
||||
|
||||
The ``property`` option can be given (with no value) to indicate the method
|
||||
is a property.
|
||||
|
||||
.. versionchanged:: 2.1
|
||||
|
||||
``:async:``, ``:classmethod:``, ``:property:`` and ``:staticmethod:``
|
||||
options added.
|
||||
``:abstractmethod:``, ``:async:``, ``:classmethod:``, ``:property:`` and
|
||||
``:staticmethod:`` options added.
|
||||
|
||||
.. rst:directive:: .. py:staticmethod:: name(parameters)
|
||||
|
||||
|
@ -585,6 +585,7 @@ class PyMethod(PyObject):
|
||||
|
||||
option_spec = PyObject.option_spec.copy()
|
||||
option_spec.update({
|
||||
'abstractmethod': directives.flag,
|
||||
'async': directives.flag,
|
||||
'classmethod': directives.flag,
|
||||
'property': directives.flag,
|
||||
@ -601,6 +602,8 @@ class PyMethod(PyObject):
|
||||
def get_signature_prefix(self, sig):
|
||||
# type: (str) -> str
|
||||
prefix = []
|
||||
if 'abstractmethod' in self.options:
|
||||
prefix.append('abstract')
|
||||
if 'async' in self.options:
|
||||
prefix.append('async')
|
||||
if 'classmethod' in self.options:
|
||||
|
@ -335,7 +335,9 @@ def test_pymethod_options(app):
|
||||
" .. py:method:: meth4\n"
|
||||
" :async:\n"
|
||||
" .. py:method:: meth5\n"
|
||||
" :property:\n")
|
||||
" :property:\n"
|
||||
" .. py:method:: meth6\n"
|
||||
" :abstractmethod:\n")
|
||||
domain = app.env.get_domain('py')
|
||||
doctree = restructuredtext.parse(app, text)
|
||||
assert_node(doctree, (addnodes.index,
|
||||
@ -350,6 +352,8 @@ def test_pymethod_options(app):
|
||||
addnodes.index,
|
||||
desc,
|
||||
addnodes.index,
|
||||
desc,
|
||||
addnodes.index,
|
||||
desc)])]))
|
||||
|
||||
# method
|
||||
@ -400,6 +404,16 @@ def test_pymethod_options(app):
|
||||
assert 'Class.meth5' in domain.objects
|
||||
assert domain.objects['Class.meth5'] == ('index', 'method')
|
||||
|
||||
# :abstractmethod:
|
||||
assert_node(doctree[1][1][10], addnodes.index,
|
||||
entries=[('single', 'meth6() (Class method)', 'Class.meth6', '', None)])
|
||||
assert_node(doctree[1][1][11], ([desc_signature, ([desc_annotation, "abstract "],
|
||||
[desc_name, "meth6"],
|
||||
[desc_parameterlist, ()])],
|
||||
[desc_content, ()]))
|
||||
assert 'Class.meth6' in domain.objects
|
||||
assert domain.objects['Class.meth6'] == ('index', 'method')
|
||||
|
||||
|
||||
def test_pyclassmethod(app):
|
||||
text = (".. py:class:: Class\n"
|
||||
|
Loading…
Reference in New Issue
Block a user