Skip to content

Commit 61c22a0

Browse files
committed
Make example objects more granular
1 parent 6afdd5a commit 61c22a0

File tree

2 files changed

+54
-5
lines changed

2 files changed

+54
-5
lines changed

singlestoredb/functions/ext/asgi.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,14 +1262,26 @@ def get_function_info(
12621262
doc_summary = docs.short_description or ''
12631263
doc_long_description = docs.long_description or ''
12641264
for ex in docs.examples:
1265-
out = []
1265+
ex_dict: Dict[str, Any] = {
1266+
'description': None,
1267+
'code': None,
1268+
'output': None,
1269+
}
12661270
if ex.description:
1267-
out.append(ex.description)
1271+
ex_dict['description'] = ex.description
12681272
if ex.snippet:
1269-
out.append(ex.snippet)
1273+
code, output = [], []
1274+
for line in ex.snippet.split('\n'):
1275+
line = line.rstrip()
1276+
if re.match(r'^(\w+>|>>>|\.\.\.)', line):
1277+
code.append(line)
1278+
else:
1279+
output.append(line)
1280+
ex_dict['code'] = '\n'.join(code) or None
1281+
ex_dict['output'] = '\n'.join(output) or None
12701282
if ex.post_snippet:
1271-
out.append(ex.post_snippet)
1272-
doc_examples.append('\n'.join(out))
1283+
ex_dict['postscript'] = ex.post_snippet
1284+
doc_examples.append(ex_dict)
12731285

12741286
except Exception as e:
12751287
logger.warning(

singlestoredb/tests/ext_funcs/__init__.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,43 @@
2828
from singlestoredb.functions.typing import pyarrow as pat
2929

3030

31+
@udf
32+
def doc_test(x: int, y: float) -> int:
33+
"""
34+
A simple function to test the decorator and documentation.
35+
36+
Parameters
37+
----------
38+
x : int
39+
An integer to be multiplied by 2.
40+
y : float
41+
A float that is not used in the computation.
42+
43+
Examples
44+
--------
45+
Basic usage of the function:
46+
>>> doc_test(3, 4.5)
47+
6
48+
49+
Another example with different values:
50+
>>> doc_test(5, 2.0)
51+
10
52+
53+
SQL Example
54+
sql> SELECT doc_test(3, 4.5);
55+
6
56+
57+
Final text
58+
59+
Returns
60+
-------
61+
int
62+
The input integer multiplied by 2.
63+
64+
"""
65+
return x * 2
66+
67+
3168
@udf
3269
def int_mult(x: int, y: int) -> int:
3370
return x * y

0 commit comments

Comments
 (0)