Repository navigation
Resolve @ivar links on interface attributes from the implementor - #958
wolfgang-aura wants to merge 5 commits into
Conversation
An @ivar on a class that documents an attribute declared by a Zope interface in another module reported 'Cannot find link target for "__init__"'. The text is written by the implementor, but inheriting the interface attribute's docsource made the link resolve from the interface. Keep the parent as the source when the parsed docstring came from a field. Fixes twisted#940
| attrobj.parsed_type = field.body() | ||
| else: | ||
| attrobj.parsed_docstring = field.body() | ||
| attrobj.parsed_docstring_from_field = True |
There was a problem hiding this comment.
| attrobj.parsed_docstring_from_field = True |
tristanlatr
left a comment
There was a problem hiding this comment.
I don't really like the current proposed changes because it introduce a new attribute to the model. I'd prefer if it was a property instead
| @@ -941,6 +941,7 @@ | |||
| attrobj.parsed_type = field.body() | |||
| else: | |||
| attrobj.parsed_docstring = field.body() | |||
There was a problem hiding this comment.
| attrobj.parsed_docstring = field.body() | |
| attrobj.parsed_docstring = ExtractedFromParentsFields(field.body()) |
| } | ||
|
|
||
|
|
||
| def extract_fields(obj: model.CanContainImportsDocumentable) -> None: |
There was a problem hiding this comment.
| class ExtractedFromParentsFields(ParsedDocstring): ... # to implement... | |
| def extract_fields(obj: model.CanContainImportsDocumentable) -> None: |
| """ | ||
| docstring: Optional[str] = None | ||
| parsed_docstring: Optional[ParsedDocstring] = None | ||
| parsed_docstring_from_field = False |
There was a problem hiding this comment.
This should be a @property checking wether the self.parsed_docstring attribute is an instance of the custom ParsedDocstring type that describe that it's cominf from parents fields instead :)
| # This is an unfortunate behaviour but it’s too big of a refactor for now (see https://github.com/twisted/pydoctor/issues/798). | ||
| if self.parsed_docstring: | ||
| self.parsed_docstring = None | ||
| self.parsed_docstring_from_field = False |
There was a problem hiding this comment.
| self.parsed_docstring_from_field = False |
| # Get the source of the docs. This must win over an inherited docstring | ||
| # (e.g. from an interface attribute): the text was written by the parent. |
There was a problem hiding this comment.
Can we get more descriptions here ?
|
Thanks, switched to a property. I also expanded the comment in
|
|
Thanks a lot, I’ll try to get my head around this and merge it for next release. |
Closes #940.
When an implementor's class docstring has
@ivar username: See L{__init__}and the interface that declaresusernamelives in another module, pydoctor warnsCannot find link target for "__init__", reports it against the interface file, and renders no link.@ivartext is split off the class docstring and attached to the attribute, so the attribute's docs are written by its parent class. When the attribute also has an inherited docsource (the interface attribute),ensure_parsed_docstringtook that as the source, so the link was resolved from the interface's scope, which has no__init__. As noted in the issue, a stub__init__on the interface hides it.This marks a parsed docstring that came from a field (
parsed_docstring_from_field) and keepsobj.parentas the source for it, even when an inherited docsource exists. Docstrings that are really inherited keep the docsource. The change is a few lines inepydoc2stan.pyandmodel.py, a test, and a changelog line inREADME.rst.How this was tested
test_ivar_link_resolved_from_implementor_not_interfaceintest_zopeinterface.pybuilds the two-class case from the issue, asserts no warning and that the link points toThing.html#__init__. A script with that setup exits 1 at base279e589and 0 with the change. The related test files passed (1489 tests in the 15 files that import the changed modules, 0 failures). These ran on Windows with Python 3.14.3 only; CI covers the rest.🤖 Generated with Claude Code