Repository navigation
Docstring pluming - #5694
Merged
Merged
Docstring pluming#5694
Conversation
There was a problem hiding this comment.
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:andReturns:sections into structuredArgumentSpec.docsandArgumentSpec.return_doc. - Extend Libdoc models and serializers (XML/JSON + schemas) to include per-argument
<doc>/docandreturndoc/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", "") |
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") |
Member
There was a problem hiding this comment.
Good catch. Not related to this feature, though, but should be fixed separately.
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 |
| 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: |
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.
Fixes #5604 partially.