Skip to content

Use docgen parsing#1788

Merged
adhami3310 merged 6 commits intomainfrom
use-docgen-parsing
Mar 24, 2026
Merged

Use docgen parsing#1788
adhami3310 merged 6 commits intomainfrom
use-docgen-parsing

Conversation

@adhami3310
Copy link
Member

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 23, 2026

Greptile Summary

This PR replaces the hand-rolled source-code parsing (Source, Prop, inline EVENTS dict) in the docs pages with structured documentation objects provided by the new reflex_docgen library (from the in-development implement-reflex-docgen branch of reflex). The refactor substantially reduces duplication across source.py, component.py, apiref.py, and the Typesense indexer, and is accompanied by a comprehensive test file.

Key changes:

  • source.py: Source, format_field (old), and all inspect/re parsing logic replaced by FieldDocumentation / MethodDocumentation from reflex_docgen; new format_methods helper added
  • component.py: Prop, the ~40-entry EVENTS fallback dictionary, and same_trigger/generate_event_triggers helpers replaced with PropDocumentation / EventHandlerDocumentation; event descriptions now come solely from component annotations
  • apiref.py / scripts/typesense_indexer.py: Source usage removed; extra_fields accumulation switched from list-extend to tuple-concatenation
  • pyproject.toml: Both reflex and new reflex-docgen pinned to the implement-reflex-docgen feature branch — intentional while the upstream reflex PR is in review, but must be updated to a stable reference before final merge
  • tests/test_docgen.py: New tests cover Annotated unwrapping, generic subtypes, __future__ string annotations, and default-value extraction from docstrings

Confidence Score: 4/5

  • Safe to merge once the upstream reflex PR lands and the feature-branch pins are updated; two small code-quality issues should be addressed first.
  • The refactor is clean and well-tested. The main blocker is that pyproject.toml intentionally pins to a feature branch (noted in the PR description), which must be resolved before merge. The if field.default: falsy-default bug is a real correctness issue for fields like count: int = 0. The missing "Methods" guard and potential empty event descriptions are low-risk polish items. No data loss, security, or runtime-crash risk in the core logic.
  • pcweb/pages/docs/source.py (falsy default check + unconditional Methods section) and pyproject.toml (feature-branch pins)

Important Files Changed

Filename Overview
pcweb/pages/docs/source.py Replaces the hand-rolled Source class with reflex_docgen types. New format_field has a falsy-default bug (if field.default: drops 0/False/"" defaults), and the "Methods" section is always rendered even when doc.methods is empty.
pcweb/pages/docs/component.py Removes Source, Prop, and the EVENTS fallback dict; delegates to generate_documentation from reflex_docgen. Event handler descriptions now come solely from component annotations — empty if not yet populated in reflex#6200.
pcweb/pages/docs/apiref.py Switches from Source to generate_class_documentation; changes extra_fields accumulation from list-extend to tuple-concatenation, which aligns with the new FieldDocumentation tuple type. Clean refactor.
scripts/typesense_indexer.py Mirrors the apiref.py refactor: drops Source for generate_class_documentation, simplifies field/method iteration with direct attribute access instead of dict .get() lookups.
pyproject.toml Pins both reflex and the new reflex-docgen package to the implement-reflex-docgen feature branch. Intentional while the upstream PR is in review, but must be updated to stable references before merging.
tests/test_docgen.py New test file with good coverage of generate_class_documentation, format_field, and component prop extraction. Tests cover Annotated unwrapping, generic subtypes, string annotations, and default parsing from docstrings.
.pre-commit-config.yaml Renames the ruff hook to ruff-check, reflecting the upstream ruff hook rename. Correct change.
uv.lock Lock file updated to reference the implement-reflex-docgen branch commit and add the new reflex-docgen package entry. Auto-generated; no manual concerns.

Sequence Diagram

sequenceDiagram
    participant Page as docs page (apiref/component)
    participant DocGen as reflex_docgen
    participant Reflex as reflex (component class)
    participant Renderer as source.py / component.py

    Page->>DocGen: generate_class_documentation(cls)
    DocGen->>Reflex: inspect annotations, fields, methods
    Reflex-->>DocGen: raw type info + Doc() metadata
    DocGen-->>Page: ClassDocumentation(fields, methods, class_fields, name, description)

    Page->>Renderer: generate_docs(title, cls, extra_fields)
    Renderer->>DocGen: generate_class_documentation(cls)
    DocGen-->>Renderer: ClassDocumentation
    Renderer->>Renderer: format_field(field) per FieldDocumentation
    Renderer->>Renderer: format_methods(doc.methods)
    Renderer-->>Page: rx.Component tree

    Page->>DocGen: generate_documentation(component)
    DocGen->>Reflex: get_props(), get_event_triggers()
    Reflex-->>DocGen: PropDocumentation[], EventHandlerDocumentation[]
    DocGen-->>Page: ComponentDocumentation(props, event_handlers, description)

    Page->>Renderer: generate_props(doc.props, component, comp)
    Page->>Renderer: generate_event_triggers(doc.event_handlers)
    Renderer-->>Page: rx.Component trees
Loading

Reviews (1): Last reviewed commit: "use class funcs" | Re-trigger Greptile

adhami3310 and others added 3 commits March 23, 2026 15:05
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@adhami3310 adhami3310 merged commit f9e78e4 into main Mar 24, 2026
10 checks passed
@adhami3310 adhami3310 deleted the use-docgen-parsing branch March 24, 2026 00:17
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.

2 participants