Skip to content

chore(remove): dead theming_components example functions - #106

Closed
elviskahoro wants to merge 1 commit into
LineIndent:mainfrom
elviskahoro:chore/remove-dead-theming-examples
Closed

elviskahoro wants to merge 1 commit into
LineIndent:mainfrom
elviskahoro:chore/remove-dead-theming-examples

Conversation

@elviskahoro

Copy link
Copy Markdown
Collaborator

Removes unreferenced example functions from the theming_components getting-started page — pure deletion, no behavior change.

Part of a series of independent cleanup PRs — each one is self-contained and can be reviewed/merged in any order.

Co-authored-by: detail-app[bot] <180357370+detail-app[bot]@users.noreply.github.com>
@elviskahoro

Copy link
Copy Markdown
Collaborator Author

/trunk merge

elviskahoro pushed a commit that referenced this pull request Nov 10, 2026
…irectives (#106)

**Detail bug report:** [View on
Detail](https://app.detail.dev/org_d38a878f-9df9-4c4b-a96a-f5180b860085/bugs/bug_bcce2d43-d9e5-482d-b370-a235996870f4)

Closes #90

## Bug

`DocParser._render` in `app/www/parser.py` substitutes `inspect_obj =
obj.__class__` for any registered object that is not a
class/function/module. For the 7 components exported as `name =
Class.create` (bound classmethods: `button`, `badge`, `toggle`,
`autocomplete`, `heatmap`, `textarea`, `separator`), `obj.__class__` is
the builtin `<class 'method'>`, which makes `inspect.getfile` raise. The
swallowed exception blanks `file_path`, and the `usage` branch falls
back to the literal stem `"component"`, emitting the non-existent import
`from components.ui.component import <name>` (no
`components/ui/component.py` exists, so copy-pasting it raises
`ModuleNotFoundError`).

7 of the 36 shipped `--USAGE(...)--` directives are affected; the other
29 (exported as `name = Class()`, i.e. `ComponentNamespace` instances)
render correctly. The same `inspect_obj` substitution also breaks the
`code_file` branch (`inspect.getmodule` resolves to `builtins`,
`inspect.getsource` raises), surfacing a red parse-error element —
currently latent since no shipped doc invokes
`--CODE_FILE(<one-of-the-7>)--`.

The bug became silent in commit `e102215`, which registered bound
classmethods for the `--USAGE(...)--` directive (adding
`inspect.ismethod(o)` to the registry-accept filter) but did not add
`inspect.ismethod(obj)` to the older `inspect_obj` substitution guard.
The 7 components went from a loud `'name' not found` to `from
components.ui.component import <name>`.

## Fix

Add `inspect.ismethod(obj)` to the "do not substitute" guard in
`app/www/parser.py`, so bound classmethods are passed straight through
to `inspect.getfile`/`inspect.getmodule`, both of which already unwrap
bound methods via `__func__`.

```diff
 inspect_obj = obj
 if obj and not (
-    inspect.isclass(obj) or inspect.isfunction(obj) or inspect.ismodule(obj)
+    inspect.isclass(obj)
+    or inspect.isfunction(obj)
+    or inspect.ismodule(obj)
+    or inspect.ismethod(obj)
 ):
     inspect_obj = getattr(obj, "__class__", obj)
```

This mirrors the parallel implementation in
`scripts/generate_markdown.py` (which already had the
`inspect.ismethod(obj)` guard since commit `af95d12`) — the production
parser had diverged from that script. The 29 `ComponentNamespace`
components are unchanged (`inspect.ismethod` is `False` for them, so the
existing `obj.__class__` substitution still runs).

## Testing

- Added `tests/test_parser_usage_imports.py` (4 regression tests): a
dynamic scan that verifies every bound-classmethod component in
`DocParser.registry` renders an importable `from components.ui.<name>
import <name>` (not the `components.ui.component` fallback); an
end-to-end scan of every shipped `--USAGE(arg)--` directive in
`docs/components/*.md`; a representative pin on the latent
`--CODE_FILE(button)--` path; and an inverse guard that the visible
`'name' not found` error still fires for unknown names. All 4 fail with
the fix reverted (the inverse guard passes both ways) and pass with it.
- `uv run pytest tests/` → 828 passed (824 pre-existing + 4 new). `uv
run pytest tests/test_generated_assets.py` → 457 passed.
- `ruff format` / `ruff check` clean on both changed files (parser.py
retains the same 5 pre-existing `BLE001` warnings as baseline; the new
test file has 0). `uv run pyright` → 0 errors on the new test file;
`app/www/parser.py` retains its 11 pre-existing errors, unchanged in
count.
- `uv run python scripts/generate_markdown.py` then `git diff
--exit-code assets/docs` → only the pre-existing doughnut-chart artifact
that exists on the baseline (identical with/without the fix, since the
markdown script already had the guard).
- End-to-end via the Reflex dev server: started `reflex run --env dev`
with `BURIDAN_DEV_PAGES=components/button`, compiled and served
`/docs/components/button`. The compiled route JSX
(`.web/app/routes/[docs].[components].[button]._index.jsx`) and the
served `docs/components/button.md` asset both contain `from
components.ui.button import button` once and `from
components.ui.component import button` zero times.

---
_Automatic Fixes PRs can be [configured
here](https://app.detail.dev/org_d38a878f-9df9-4c4b-a96a-f5180b860085/settings/repos/repo_04b9d58c-daa0-46b6-9560-7f39569ec6eb/bugs)._

---------

Co-authored-by: detail-app[bot] <180357370+detail-app[bot]@users.noreply.github.com>
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.

1 participant