Skip to content

ENG-9533 feat: render concise, readable types in docgen class documentation#6634

Open
FarhanAliRaza wants to merge 3 commits into
reflex-dev:mainfrom
FarhanAliRaza:fix-api-refs
Open

ENG-9533 feat: render concise, readable types in docgen class documentation#6634
FarhanAliRaza wants to merge 3 commits into
reflex-dev:mainfrom
FarhanAliRaza:fix-api-refs

Conversation

@FarhanAliRaza

@FarhanAliRaza FarhanAliRaza commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

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.

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

  • Bug fix (non-breaking change which fixes an issue)

New Feature Submission:

  • Does your submission pass the tests?
  • Have you linted your code locally prior to submission?

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Before

image

After
image

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.
@FarhanAliRaza FarhanAliRaza requested a review from a team as a code owner June 9, 2026 09:04
@FarhanAliRaza FarhanAliRaza added the skip-changelog For doc/internal changes label Jun 9, 2026
@codspeed-hq

codspeed-hq Bot commented Jun 9, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 26 untouched benchmarks
⏩ 8 skipped benchmarks1


Comparing FarhanAliRaza:fix-api-refs (67e572a) with main (6f5c80b)2

Open in CodSpeed

Footnotes

  1. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (e4a9365) during the generation of this report, so 6f5c80b was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@greptile-apps

greptile-apps Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR overhauls reflex-docgen's type and signature rendering so generated class docs show concise, human-readable output instead of fully-expanded internal representations. It also migrates the ASGI type aliases to TypeAliasType so their short names (ASGIApp, Scope, etc.) survive get_type_hints introspection.

  • format_type / _format_annotation: New public function strips module qualifiers, preserves TypeAliasType names, and recursively renders unions, Optional, Literal, and Callable — paired with string-level annotation handling for forward refs so a single unresolvable TYPE_CHECKING-only name doesn't break the entire signature.
  • _format_default / _format_signature: Clean default display (function names, empty-collection literals, ... for opaque callables) and self/cls-stripped method signatures; function-valued dataclass field defaults are excluded from the methods table.
  • reflex/app.py: Docstring-only changes adding doc links and fixing a stray } in the global-styles URL.

Confidence Score: 5/5

Safe 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

Filename Overview
packages/reflex-docgen/src/reflex_docgen/_class.py Core docgen logic rewrite: adds format_type, _format_annotation, _format_signature, and _format_default; all well-guarded and comprehensively tested.
packages/reflex-base/src/reflex_base/utils/types.py ASGI aliases migrated from plain assignments to TypeAliasType; used only as annotations across the codebase, so the change is backward compatible.
tests/units/docgen/test_class_and_component.py Extensive parametrized tests for format_type, _format_annotation, _format_signature, default formatting, and App integration; good coverage of edge cases.
reflex/app.py Docstring-only improvements: adds doc links and a clearer api_transformer description; also fixes a stray extra } in the global-styles URL.
tests/units/reflex_base/utils/test_types.py New test confirming ASGI aliases are TypeAliasType instances with correct names.
packages/reflex-docgen/src/reflex_docgen/init.py Exports format_type as a public API surface.

Reviews (2): Last reviewed commit: "refactor: inline single-use docgen type-..." | Re-trigger Greptile

Comment thread packages/reflex-docgen/src/reflex_docgen/_class.py
Comment on lines +488 to +490
if param.default is not empty:
default = _format_default(param.default, is_factory=False)
text += f" = {default if default is not None else '...'}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.
@masenf

masenf commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

the App, Event, EventHandler, EventSpec, page still has all of the attributes listed as body text in addition to appearing in the table

image

The Model page should be removed from auto-gen reference pages, since it is now deprecated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-changelog For doc/internal changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants