mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Add :property: option to py:method directive
This commit is contained in:
parent
0d1a66996b
commit
a142a654fc
8
CHANGES
8
CHANGES
@ -84,8 +84,12 @@ Features added
|
|||||||
imported members on autosummary
|
imported members on autosummary
|
||||||
* #6271: ``make clean`` is catastrophically broken if building into '.'
|
* #6271: ``make clean`` is catastrophically broken if building into '.'
|
||||||
* #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 ``:async:``, ``:classmethod:`` and ``:staticmethod:`` options
|
* py domain: Add new options to :rst:dir:`py:method` directive
|
||||||
to :rst:dir:`py:method` directive
|
|
||||||
|
- ``:async:``
|
||||||
|
- ``:classmethod:``
|
||||||
|
- ``:property:``
|
||||||
|
- ``:staticmethod:``
|
||||||
|
|
||||||
Bugs fixed
|
Bugs fixed
|
||||||
----------
|
----------
|
||||||
|
@ -229,9 +229,13 @@ The following directives are provided for module and class contents:
|
|||||||
The ``classmethod`` option and ``staticmethod`` option can be given (with
|
The ``classmethod`` option and ``staticmethod`` option can be given (with
|
||||||
no value) to indicate the method is a class method (or a static method).
|
no value) to indicate the method is 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
|
.. versionchanged:: 2.1
|
||||||
|
|
||||||
``:async:``, ``:classmethod:`` and ``:staticmethod:`` options added.
|
``:async:``, ``:classmethod:``, ``:property:`` and ``:staticmethod:``
|
||||||
|
options added.
|
||||||
|
|
||||||
.. rst:directive:: .. py:staticmethod:: name(parameters)
|
.. rst:directive:: .. py:staticmethod:: name(parameters)
|
||||||
|
|
||||||
|
@ -587,22 +587,28 @@ class PyMethod(PyObject):
|
|||||||
option_spec.update({
|
option_spec.update({
|
||||||
'async': directives.flag,
|
'async': directives.flag,
|
||||||
'classmethod': directives.flag,
|
'classmethod': directives.flag,
|
||||||
|
'property': directives.flag,
|
||||||
'staticmethod': directives.flag,
|
'staticmethod': directives.flag,
|
||||||
})
|
})
|
||||||
|
|
||||||
def needs_arglist(self):
|
def needs_arglist(self):
|
||||||
# type: () -> bool
|
# type: () -> bool
|
||||||
return True
|
if 'property' in self.options:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
def get_signature_prefix(self, sig):
|
def get_signature_prefix(self, sig):
|
||||||
# type: (str) -> str
|
# type: (str) -> str
|
||||||
prefix = []
|
prefix = []
|
||||||
if 'async' in self.options:
|
if 'async' in self.options:
|
||||||
prefix.append('async')
|
prefix.append('async')
|
||||||
if 'staticmethod' in self.options:
|
|
||||||
prefix.append('static')
|
|
||||||
if 'classmethod' in self.options:
|
if 'classmethod' in self.options:
|
||||||
prefix.append('classmethod')
|
prefix.append('classmethod')
|
||||||
|
if 'property' in self.options:
|
||||||
|
prefix.append('property')
|
||||||
|
if 'staticmethod' in self.options:
|
||||||
|
prefix.append('static')
|
||||||
|
|
||||||
if prefix:
|
if prefix:
|
||||||
return ' '.join(prefix) + ' '
|
return ' '.join(prefix) + ' '
|
||||||
@ -622,10 +628,12 @@ class PyMethod(PyObject):
|
|||||||
else:
|
else:
|
||||||
return '%s()' % name
|
return '%s()' % name
|
||||||
|
|
||||||
if 'staticmethod' in self.options:
|
if 'classmethod' in self.options:
|
||||||
return _('%s() (%s static method)') % (methname, clsname)
|
|
||||||
elif 'classmethod' in self.options:
|
|
||||||
return _('%s() (%s class method)') % (methname, clsname)
|
return _('%s() (%s class method)') % (methname, clsname)
|
||||||
|
elif 'property' in self.options:
|
||||||
|
return _('%s() (%s property)') % (methname, clsname)
|
||||||
|
elif 'staticmethod' in self.options:
|
||||||
|
return _('%s() (%s static method)') % (methname, clsname)
|
||||||
else:
|
else:
|
||||||
return _('%s() (%s method)') % (methname, clsname)
|
return _('%s() (%s method)') % (methname, clsname)
|
||||||
|
|
||||||
|
@ -333,7 +333,9 @@ def test_pymethod_options(app):
|
|||||||
" .. py:method:: meth3\n"
|
" .. py:method:: meth3\n"
|
||||||
" :staticmethod:\n"
|
" :staticmethod:\n"
|
||||||
" .. py:method:: meth4\n"
|
" .. py:method:: meth4\n"
|
||||||
" :async:\n")
|
" :async:\n"
|
||||||
|
" .. py:method:: meth5\n"
|
||||||
|
" :property:\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,
|
||||||
@ -346,6 +348,8 @@ def test_pymethod_options(app):
|
|||||||
addnodes.index,
|
addnodes.index,
|
||||||
desc,
|
desc,
|
||||||
addnodes.index,
|
addnodes.index,
|
||||||
|
desc,
|
||||||
|
addnodes.index,
|
||||||
desc)])]))
|
desc)])]))
|
||||||
|
|
||||||
# method
|
# method
|
||||||
@ -387,6 +391,15 @@ def test_pymethod_options(app):
|
|||||||
assert 'Class.meth4' in domain.objects
|
assert 'Class.meth4' in domain.objects
|
||||||
assert domain.objects['Class.meth4'] == ('index', 'method')
|
assert domain.objects['Class.meth4'] == ('index', 'method')
|
||||||
|
|
||||||
|
# :property:
|
||||||
|
assert_node(doctree[1][1][8], addnodes.index,
|
||||||
|
entries=[('single', 'meth5() (Class property)', 'Class.meth5', '', None)])
|
||||||
|
assert_node(doctree[1][1][9], ([desc_signature, ([desc_annotation, "property "],
|
||||||
|
[desc_name, "meth5"])],
|
||||||
|
[desc_content, ()]))
|
||||||
|
assert 'Class.meth5' in domain.objects
|
||||||
|
assert domain.objects['Class.meth5'] == ('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