ENG-9533 feat: render concise, readable types in docgen class documentation#6634
ENG-9533 feat: render concise, readable types in docgen class documentation#6634FarhanAliRaza wants to merge 3 commits into
Conversation
Rework reflex-docgen's type/signature rendering so generated class docs read cleanly instead of leaking implementation noise. - Add a public format_type() that strips module qualifiers, preserves type-alias names, and renders unions (Optional[...]), literals, and callables recursively. - Define the ASGI aliases (Scope, Message, Receive, Send, ASGIApp) via TypeAliasType so their short names survive introspection and docs show e.g. ASGIApp rather than a fully expanded MutableMapping/Awaitable blob. - Render method signatures without self/cls, with forward-ref strings kept verbatim (each annotation independently, so one TYPE_CHECKING-only name doesn't poison the rest) and optionality normalized to match format_type. - Clean field/parameter defaults: show function names or empty-collection literals instead of volatile <function ... at 0x...> reprs, and exclude function-valued field defaults from the methods table. - Polish App attribute docstrings with doc links and a fuller api_transformer description.
Merging this PR will not alter performance
Comparing Footnotes
|
Greptile SummaryThis PR overhauls
Confidence Score: 5/5Safe to merge — all changes are scoped to documentation generation and display logic; no runtime behavior of the application itself is altered. The TypeAliasType migration for ASGI aliases is annotation-only across every callsite (all files use from future import annotations or TYPE_CHECKING), so no evaluated runtime union or isinstance call is affected. The new formatting helpers are purely string-transforming utilities with comprehensive parametrized tests covering unions, optionality, callable types, forward-ref strings, and App integration. The app.py changes are docstring-only. No files require special attention. Important Files Changed
Reviews (2): Last reviewed commit: "refactor: inline single-use docgen type-..." | Re-trigger Greptile |
| if param.default is not empty: | ||
| default = _format_default(param.default, is_factory=False) | ||
| text += f" = {default if default is not None else '...'}" |
There was a problem hiding this comment.
Opaque defaults rendered as
= ...
When _format_default returns None for a lambda or unnamed callable default, the signature renders = ... (the Ellipsis literal). This is a reasonable "hidden default" convention used by stub files, but in generated documentation it can be confused with Python's ... stub-body syntax. Consider an explicit placeholder like = <default> or omitting the default entirely so readers understand there is a default without implying the Ellipsis object is the value.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Fold _literal_value, _EMPTY_FACTORY_DISPLAY, _strip_module_qualifiers, and _optional_from_string into their lone call sites. The string-only forward-ref handling now lives directly in _format_annotation, so the qualifier-stripping and Optional[...] rewrite read top-to-bottom in one place instead of hopping through tiny indirections. No behavior change; tests updated to exercise _format_annotation directly.

Rework reflex-docgen's type/signature rendering so generated class docs read cleanly instead of leaking implementation noise.
All Submissions:
Type of change
New Feature Submission:
Changes To Core Features:
Before
After
