Skip to content

Commit d69e528

Browse files
committed
apply greptile feedback
1 parent f830f37 commit d69e528

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

packages/reflex-base/src/reflex_base/utils/pyi_generator.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -318,20 +318,20 @@ def _get_class_prop_comments(clz: type[Component]) -> Mapping[str, tuple[str, ..
318318
in_docstring = False
319319
docstring_lines: list[str] = []
320320
for line in _get_source(clz).splitlines():
321-
reached_functions = re.search(r"def ", line)
322-
if reached_functions:
323-
# We've reached the functions, so stop.
324-
break
325-
326321
stripped = line.strip()
327322

328323
# Handle triple-quoted docstrings after prop definitions.
324+
# This must be checked before the `def ` boundary so that
325+
# docstring prose containing "def " doesn't break the loop.
329326
if in_docstring:
330327
if '"""' in stripped or "'''" in stripped:
331328
# End of multi-line docstring.
332-
end_text = stripped.partition('"""')[0] or stripped.partition("'''")[0]
329+
if '"""' in stripped:
330+
end_text = stripped.partition('"""')[0].strip()
331+
else:
332+
end_text = stripped.partition("'''")[0].strip()
333333
if end_text:
334-
docstring_lines.append(end_text.strip())
334+
docstring_lines.append(end_text)
335335
if last_prop and docstring_lines:
336336
props_comments[last_prop] = tuple(docstring_lines)
337337
in_docstring = False
@@ -341,6 +341,11 @@ def _get_class_prop_comments(clz: type[Component]) -> Mapping[str, tuple[str, ..
341341
docstring_lines.append(stripped)
342342
continue
343343

344+
reached_functions = re.search(r"def ", line)
345+
if reached_functions:
346+
# We've reached the functions, so stop.
347+
break
348+
344349
# Check for start of a docstring right after a prop.
345350
if last_prop and (stripped.startswith(('"""', "'''"))):
346351
quote = '"""' if stripped.startswith('"""') else "'''"

tests/units/reflex_base/utils/pyi_generator/dataset/simple_component.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ class SimpleComponent(Component):
4949
"""A tooltip that appears on hover
5050
with additional details."""
5151

52+
callback: Var[str]
53+
"""
54+
The def of the callback to use when the component is clicked.
55+
"""
56+
5257
def _private_method(self):
5358
"""This should not appear in the stub.
5459

tests/units/reflex_base/utils/pyi_generator/golden/simple_component.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class SimpleComponent(Component):
2727
label: Var[str] | str | None = None,
2828
description: Var[str] | str | None = None,
2929
tooltip: Var[str] | str | None = None,
30+
callback: Var[str] | str | None = None,
3031
style: Sequence[Mapping[str, Any]]
3132
| Mapping[str, Any]
3233
| Var[Mapping[str, Any]]
@@ -66,6 +67,7 @@ class SimpleComponent(Component):
6667
label: An optional label with a default value.
6768
description: A detailed description of the component.
6869
tooltip: A tooltip that appears on hover with additional details.
70+
callback: The def of the callback to use when the component is clicked.
6971
style: The style of the component.
7072
key: A unique key for the component.
7173
id: The id for the component.

0 commit comments

Comments
 (0)