Skip to content

Docstring pluming - #5694

Merged
pekkaklarck merged 2 commits into
robotframework:masterfrom
aaltat:docstring_pluming
Jul 5, 2026
Merged

pekkaklarck merged 2 commits into
robotframework:masterfrom
aaltat:docstring_pluming

Conversation

@aaltat

@aaltat aaltat commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Fixes #5604 partially.

Copilot AI review requested due to automatic review settings July 3, 2026 16:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds “Google-style” docstring plumbing so Libdoc can extract per-argument and return-value documentation separately from the main keyword documentation, and then serialize/deserialize that information in XML/JSON outputs.

Changes:

  • Parse keyword docstrings to extract Args: and Returns: sections into structured ArgumentSpec.docs and ArgumentSpec.return_doc.
  • Extend Libdoc models and serializers (XML/JSON + schemas) to include per-argument <doc> / doc and returndoc / returnDoc.
  • Thread the new docs through Libdoc’s internal keyword/argument model (ArgInfo.doc, KeywordDoc.to_dictionary).

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/robot/running/keywordimplementation.py Parses docstrings and stores extracted argument/return docs on the keyword argument spec.
src/robot/running/arguments/validators.py Adds validation for argument-doc mappings against actual argument names.
src/robot/running/arguments/argumentspec.py Adds storage and iteration support for per-argument docs and return doc.
src/robot/libdocpkg/xmlwriter.py Serializes per-argument docs and return doc into Libdoc XML.
src/robot/libdocpkg/xmlbuilder.py Deserializes per-argument docs and return doc from Libdoc XML.
src/robot/libdocpkg/robotbuilder.py Ensures doc parsing happens when building Libdoc keyword models.
src/robot/libdocpkg/model.py Includes arg/return docs in JSON dict output and converts arg docs during HTML conversion.
src/robot/libdocpkg/jsonbuilder.py Deserializes per-argument docs and return doc from Libdoc JSON.
doc/schema/libdoc.xsd Updates XML schema to allow per-argument doc elements and return doc element.
doc/schema/libdoc.json Updates JSON schema to include required argument doc and optional returnDoc.
doc/schema/libdoc_json_schema.py Updates the schema source models for argument doc and return doc fields.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +141 to +149
def update_docs(self):
result = parse_docstring(self.doc)
self.doc = result.doc
self.args.return_doc = result.returns
try:
self.args.docs = result.args
except DataError as err:
self.error = str(err)

Comment on lines +126 to +127
for arg in item.args:
item.args.docs[arg.name] = formatter.html(arg.doc)
shortdoc: str
args: List[Argument]
returnType: Optional[TypeInfo]
returnDoc: Optional[str]
named_only.append(name)
elif kind == ArgInfo.VAR_NAMED:
spec.var_named = name
spec.docs[name] = arg.get("doc", "")
@aaltat
aaltat force-pushed the docstring_pluming branch from 8579250 to 9c1d760 Compare July 3, 2026 23:11
Copilot AI review requested due to automatic review settings July 4, 2026 19:54
@aaltat
aaltat force-pushed the docstring_pluming branch from 9c1d760 to 14178eb Compare July 4, 2026 19:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.

Comment on lines +141 to +149
def update_docs(self):
result = parse_docstring(self.doc)
self.doc = result.doc
self.args.return_doc = result.returns
try:
self.args.docs = result.args
except DataError as err:
self.error = str(err)

Comment on lines 127 to +129
item.doc = formatter.html(item.doc)
for arg in item.args:
item.args.docs[arg.name] = formatter.html(arg.doc)
Comment on lines +168 to 172
kw.update_docs()
doc, tags = self._get_doc_and_tags(kw) # TODO: Move this update_docs().
if kw.error:
doc = f"*Creating keyword failed:* {kw.error}"
if not self._resource:
Comment on lines 92 to 96
named_only.append(name)
elif kind == ArgInfo.VAR_NAMED:
spec.var_named = name
spec.docs[name] = arg.get("doc", "")
default = arg.get("defaultValue")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Not related to this feature, though, but should be fixed separately.

@aaltat
aaltat force-pushed the docstring_pluming branch from 14178eb to 2a5b119 Compare July 4, 2026 22:44
Copilot AI review requested due to automatic review settings July 5, 2026 09:44
@aaltat
aaltat force-pushed the docstring_pluming branch from 2a5b119 to 3023ea5 Compare July 5, 2026 09:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.

Comment on lines +125 to 132
def _add_return_info(self, data, kw: KeywordDoc):
type_data = data.get("returnType")
if type_data:
type_docs = {}
kw.args.return_type = self._parse_type_info(data, type_docs)
kw.args.return_type = self._parse_type_info(type_data, type_docs)
kw.type_docs["return"] = type_docs
kw.args.return_doc = data.get("returnDoc", "")

Comment on lines +148 to 157
def _add_return_info(self, elem, kw):
type_elem = elem.find("returntype")
if type_elem is not None:
type_docs = {}
kw.args.return_type = self._parse_type_info(elem, type_docs)
kw.args.return_type = self._parse_type_info(type_elem, type_docs)
kw.type_docs["return"] = type_docs
doc_elem = elem.find("returndoc")
if doc_elem is not None:
kw.args.return_doc = doc_elem.text or ""

Comment on lines +595 to 598
"returnDoc": "",
"tags": [],
"source": "/home/peke/Devel/robotframework/atest/testdata/libdoc/Annotations.py",
"source": "/Users/tatuaalto/workspace/robotframework/atest/testdata/libdoc/Annotations.py",
"lineno": null

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@aaltat
aaltat force-pushed the docstring_pluming branch from 3023ea5 to 27e7091 Compare July 5, 2026 10:10
Copilot AI review requested due to automatic review settings July 5, 2026 10:18
@aaltat
aaltat force-pushed the docstring_pluming branch from 27e7091 to 10ed663 Compare July 5, 2026 10:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.

kw.args.return_type = self._parse_type_info(data, type_docs)
kw.args.return_type = self._parse_type_info(type_data, type_docs)
kw.type_docs["return"] = type_docs
kw.args.return_doc = data.get("returnDoc", "")
Comment on lines +108 to +109
for arg in item.args:
item.args.docs[arg.name] = formatter.html(arg.doc)
Comment on lines 81 to 86
writer.start("arg", attrs)
if arg.name:
writer.element("name", arg.name)
if arg.doc:
writer.element("doc", arg.doc)
if arg.type:
@aaltat
aaltat force-pushed the docstring_pluming branch from 10ed663 to 2486b0a Compare July 5, 2026 10:29
@pekkaklarck
pekkaklarck merged commit 4db9c75 into robotframework:master Jul 5, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Libdoc: Argument and return value documentation syntax

3 participants