Repository navigation
Read ReST ivar, var and cvar fields as attributes - #172
Merged
Merged
Conversation
The :ivar:, :var: and :cvar: fields Sphinx documents attributes with were text items in ReST, while Epydoc already read @ivar as an attribute. Read them as params of kind ATTRIBUTE, and read :vartype x: as their type, as :type x: is of params: _fields.assign_types takes the new vartypes, which only attributes take, an attribute of a name with none taking from types as before. A :vartype: that no attribute takes is an attribute of its own, as a lone :type: is a param. A :type x: field with no type no longer gives x an empty type. One for a name that no other field gives still makes a param, with no type, so that the name is kept. Compose writes these attributes back with their own field names, and their types with :vartype:, so they read back the same. Epydoc's @ivar, @var and @cvar now convert to them too. An attribute with another key, such as one from Google, keeps :attribute: and :type:.
rr-
force-pushed
the
rework/34-rest-vartypes
branch
from
November 6, 2026 18:53
9f20852 to
df29541
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sphinx documents attributes with
:ivar:,:var:and:cvar:fields, typed by:vartype:. ReST parsed them as plain text items, so they were missing fromDocstring.attrs, and:vartype:was a text item too. Epydoc already reads@ivaras an attribute.Before:
DocstringMeta(kind=Kind.TEXT, key='ivar', name='a', description='The a.')andDocstringMeta(kind=Kind.TEXT, key='vartype', name='a', description='int').After:
DocstringParam(kind=Kind.ATTRIBUTE, key='ivar', arg_name='a', type_name='int', description='The a.').:vartype x:types attributes the way:type x:types params, through_fields.assign_types, which takes a newvartypestable. Only attributes take from it, and an attribute of a name with no:vartype:still takes from:type:, so:attribute x:with:type x:keeps working. A:param x:and an:ivar x:of the same name each get their own type. A:vartype:that no attribute takes is an attribute of its own, as a lone:type:is a param.An empty
:type x:no longer givesxthe type''. Ignoring it completely would drop the name when nothing else mentions it, which the no-text-dropped invariant test catches, so a lone empty:type y:still makes a paramy, now with no type.Compose: an attribute keyed
ivar,varorcvaris written back with that field name, and its type with:vartype:when it doesn't fit inline. Without this,:ivar a:would compose as:attribute a:and read back with another key. Attributes with any other key, such as the ones Google and Numpydoc give, still compose as:attribute:and:type:. Since Epydoc keys its attributesivar,varandcvartoo, converting Epydoc to ReST now writes:ivar a:instead of:attribute a:.test_kinds.py::test_sub_kindsnow expects:ivarto be an attribute.Parity against origin/main: 926 of 29,149 docstrings differ, 18 from the case files and 908 generated, none from the stdlib.
parse REST/parse AUTOand their composes: the three newrest/attribute_fields_*cases andconvert/rest-params, whose:ivar z:is now an attribute. Its Google and Numpydoc output stays the same.compose EPYDOC RESTandcompose AUTO REST(where auto picks Epydoc). There,@ivar,@varand@cvarnow compose as:ivar:,:var:and:cvar:instead of:attribute:, and their types as:vartype:instead of:type:. With those names swapped back, every one matches main.Bench (
just bench): parse rest 93.0 ms on main vs 92.4 ms (0.99x), compose rest 1.00x, other workloads 0.99x to 1.00x.