Skip to content

Commit 69da3b4

Browse files
improvement: support more parameter descriptions, e.g. in polars (#4786)
## 📝 Summary Small follow up to #4673. ## 🔍 Description of Changes Polars often uses a simplified rst format for parameters where it does not include types. This requires `docstring-to-markdown` v0.17 with: - python-lsp/docstring-to-markdown#44 For example, before there was only one parameter with description for `polars.io.parquet.functions.read_parquet`, and now all 22 are displayed. Parameters from functions with overloads such as `polars.io.database.functions.read_database` remain without good suggestions. ## 📋 Checklist - [x] I have read the [contributor guidelines](https://github.com/marimo-team/marimo/blob/main/CONTRIBUTING.md). - [ ] For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on [Discord](https://marimo.io/discord?ref=pr), or the community [discussions](https://github.com/marimo-team/marimo/discussions) (Please provide a link if applicable). - [x] I have added tests for the changes made. - [x] I have run the code and verified that it works as expected. ## 📜 Reviewers @mscolnick --------- Co-authored-by: Myles Scolnick <[email protected]>
1 parent 38a4509 commit 69da3b4

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

marimo/_dependencies/dependencies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class DependencyManager:
200200
vl_convert_python = Dependency("vl_convert")
201201
dotenv = Dependency("dotenv")
202202
docstring_to_markdown = Dependency(
203-
"docstring_to_markdown", min_version="0.16.0"
203+
"docstring_to_markdown", min_version="0.17.0"
204204
)
205205

206206
# Version requirements to properly support the new superfences introduced in

marimo/_runtime/patches.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,13 +307,16 @@ def extract_docstring_to_markdown_arguments(
307307
for line in lines[start + 2 :]:
308308
if line.strip() == "" or line.startswith("#"):
309309
continue
310-
param_start = re.match(r"^\- `(.+)`: (.*)$", line.strip())
310+
param_start = re.match(r"^\- `(.+)`:(?: (.*))?$", line.strip())
311311
if param_start:
312312
param, first_line = param_start.groups()
313-
param_descriptions[param] = first_line
313+
param_descriptions[param] = first_line or ""
314314
else:
315315
if param:
316-
param_descriptions[param] += "\n" + line.strip()
316+
if param_descriptions[param]:
317+
param_descriptions[param] += "\n" + line.strip()
318+
else:
319+
param_descriptions[param] = line.strip()
317320
return param_descriptions
318321

319322
def py__doc__(self: ParamNameWrapper) -> str:

tests/_runtime/test_complete.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from inspect import signature
44
from types import ModuleType
5+
from typing import Any
56

67
import jedi
78
import pytest
@@ -136,6 +137,18 @@ def collect_functions_to_check():
136137
return objects_to_check
137138

138139

140+
def dummy_func(arg1: str, arg2: str) -> None:
141+
"""
142+
Parameters
143+
----------
144+
arg1
145+
polars often uses this format
146+
arg2 : str, required
147+
while other libraries prefer this format (which polars uses too)
148+
"""
149+
del arg1, arg2
150+
151+
139152
@pytest.mark.skipif(
140153
not DependencyManager.docstring_to_markdown.has(),
141154
reason="docstring_to_markdown is not installed",
@@ -145,13 +158,14 @@ def collect_functions_to_check():
145158
[[obj, False] for obj in collect_functions_to_check()]
146159
+ [
147160
# Test runtime inference for a subset of values
148-
[marimo.accordion, True]
161+
[marimo.accordion, True],
162+
[dummy_func, False],
149163
],
150164
ids=lambda obj: f"{obj}"
151165
if isinstance(obj, bool)
152166
else f"{obj.__module__}.{obj.__qualname__}",
153167
)
154-
def test_parameter_descriptions(obj, runtime_inference):
168+
def test_parameter_descriptions(obj: Any, runtime_inference: bool):
155169
patch_jedi_parameter_completion()
156170
import_name = obj.__module__
157171
marimo_export = obj.__name__
@@ -165,12 +179,14 @@ def test_parameter_descriptions(obj, runtime_inference):
165179
" is not yet supported by mkdocstrings for documentation rendering, see"
166180
" https://github.com/mkdocstrings/python/issues/135"
167181
)
182+
if path.endswith("dummy_func"):
183+
pytest.skip("Not picking up parameters for dummy_func")
168184
call = f"{path}("
169185
code = f"import {import_name};{call}"
170186
jedi.settings.auto_import_modules = ["marimo"] if runtime_inference else []
171187
script = jedi.Script(code=code)
172-
completions = script.complete(line=1, column=len(code))
173-
param_completions = {
188+
completions: list[Any] = script.complete(line=1, column=len(code))
189+
param_completions: dict[str, Any] = {
174190
completion.name[:-1]: completion
175191
for completion in completions
176192
if completion.name.endswith("=")

0 commit comments

Comments
 (0)