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
|
* #4777: py domain: Add ``:async:`` option to :rst:dir:`py:function` directive
|
||||||
* py domain: Add new options to :rst:dir:`py:method` directive
|
* py domain: Add new options to :rst:dir:`py:method` directive
|
||||||
|
|
||||||
|
- ``:abstractmethod:``
|
||||||
- ``:async:``
|
- ``:async:``
|
||||||
- ``:classmethod:``
|
- ``:classmethod:``
|
||||||
- ``:property:``
|
- ``: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
|
The ``async`` option can be given (with no value) to indicate the method is
|
||||||
an async method.
|
an async method.
|
||||||
|
|
||||||
The ``classmethod`` option and ``staticmethod`` option can be given (with
|
The ``abstractmethod``, ``classmethod`` option and ``staticmethod`` option
|
||||||
no value) to indicate the method is a class method (or a static method).
|
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
|
The ``property`` option can be given (with no value) to indicate the method
|
||||||
is a property.
|
is a property.
|
||||||
|
|
||||||
.. versionchanged:: 2.1
|
.. versionchanged:: 2.1
|
||||||
|
|
||||||
``:async:``, ``:classmethod:``, ``:property:`` and ``:staticmethod:``
|
``:abstractmethod:``, ``:async:``, ``:classmethod:``, ``:property:`` and
|
||||||
options added.
|
``:staticmethod:`` options added.
|
||||||
|
|
||||||
.. rst:directive:: .. py:staticmethod:: name(parameters)
|
.. rst:directive:: .. py:staticmethod:: name(parameters)
|
||||||
|
|
||||||
|
@ -585,6 +585,7 @@ class PyMethod(PyObject):
|
|||||||
|
|
||||||
option_spec = PyObject.option_spec.copy()
|
option_spec = PyObject.option_spec.copy()
|
||||||
option_spec.update({
|
option_spec.update({
|
||||||
|
'abstractmethod': directives.flag,
|
||||||
'async': directives.flag,
|
'async': directives.flag,
|
||||||
'classmethod': directives.flag,
|
'classmethod': directives.flag,
|
||||||
'property': directives.flag,
|
'property': directives.flag,
|
||||||
@ -601,6 +602,8 @@ class PyMethod(PyObject):
|
|||||||
def get_signature_prefix(self, sig):
|
def get_signature_prefix(self, sig):
|
||||||
# type: (str) -> str
|
# type: (str) -> str
|
||||||
prefix = []
|
prefix = []
|
||||||
|
if 'abstractmethod' in self.options:
|
||||||
|
prefix.append('abstract')
|
||||||
if 'async' in self.options:
|
if 'async' in self.options:
|
||||||
prefix.append('async')
|
prefix.append('async')
|
||||||
if 'classmethod' in self.options:
|
if 'classmethod' in self.options:
|
||||||
|
@ -335,7 +335,9 @@ def test_pymethod_options(app):
|
|||||||
" .. py:method:: meth4\n"
|
" .. py:method:: meth4\n"
|
||||||
" :async:\n"
|
" :async:\n"
|
||||||
" .. py:method:: meth5\n"
|
" .. py:method:: meth5\n"
|
||||||
" :property:\n")
|
" :property:\n"
|
||||||
|
" .. py:method:: meth6\n"
|
||||||
|
" :abstractmethod:\n")
|
||||||
domain = app.env.get_domain('py')
|
domain = app.env.get_domain('py')
|
||||||
doctree = restructuredtext.parse(app, text)
|
doctree = restructuredtext.parse(app, text)
|
||||||
assert_node(doctree, (addnodes.index,
|
assert_node(doctree, (addnodes.index,
|
||||||
@ -350,6 +352,8 @@ def test_pymethod_options(app):
|
|||||||
addnodes.index,
|
addnodes.index,
|
||||||
desc,
|
desc,
|
||||||
addnodes.index,
|
addnodes.index,
|
||||||
|
desc,
|
||||||
|
addnodes.index,
|
||||||
desc)])]))
|
desc)])]))
|
||||||
|
|
||||||
# method
|
# method
|
||||||
@ -400,6 +404,16 @@ def test_pymethod_options(app):
|
|||||||
assert 'Class.meth5' in domain.objects
|
assert 'Class.meth5' in domain.objects
|
||||||
assert domain.objects['Class.meth5'] == ('index', 'method')
|
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):
|
def test_pyclassmethod(app):
|
||||||
text = (".. py:class:: Class\n"
|
text = (".. py:class:: Class\n"
|
||||||
|
Loading…
Reference in New Issue
Block a user