Skip to content

feat(typefacts): --facts CLI fast lane in PyrightFactsAdapter - #127

Merged
devin-ai-integration[bot] merged 1 commit into
masterfrom
work/facts-cli-adapter
Oct 18, 2026
Merged

devin-ai-integration[bot] merged 1 commit into
masterfrom
work/facts-cli-adapter

Conversation

@espetro

@espetro espetro commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Summary

PyrightFactsAdapter gains a --facts fast lane: when the pyright CLI supports the new --facts verb (sigilco/pyright#3), the adapter spawns one pyright --facts --pythonversion 3.13 subprocess per module and maps its structural type JSON onto ModuleFacts directly — no hover-string parsing. When PYRIGHT_BIN (or the cli= arg) points at stock upstream pyright, the --help probe finds no --facts and the adapter keeps today's LSP-hover path unchanged, preserving upstream compatibility.

This removes the class of bugs where the ~800-line _parse_type_text/_parse_def_signature parsers silently mis-read pyright's printed type grammar (quoted forward refs, UniqueNameMap renames, tuple forms). Facts arrive pre-structured from the evaluator: {"kind":"class","fullName":"builtins.int","typeArgs":[...]}.

Contract kept identical

  • signature('__main__.f') keys: pyright's flat mod.outer.inner is remapped through the Python AST back to __main__.outer.<locals>.inner.
  • AnnAssign targets record the declared type — pyright narrows x in x: int | None = 1 to int; the lane copies the annotation node's own fact and unwraps the type[X] layer annotations evaluate to (_facts_denoted), yielding the same union optional [int, none] the hover path produces.
  • CallableFacts: / and bare * separators arrive as unnamed params → positional_only/keyword_only; defaultType.literalValue fills defaults for constant defaults.

Files

  • typefacts.py — _facts_type/_facts_signature/_facts_qualnames/_facts_denoted mappers (~150 LOC replacing the parse for this lane), cli=/PYRIGHT_BIN resolution + cached --help capability probe, _cli_facts subprocess lane reusing the preflight's generated-pyrightconfig (_pyright_stubs stubPath).
  • tests/test_pyright_facts.py — hermetic fake-CLI tests (signature separators/defaults/overloads/nested names/denoted annotations, stock-pyright probe rejection), live smoke behind PYRIGHT_BIN.
  • tests/test_census_self.py — fence ballpark 1189 → 1210 (+21, same subprocess/JSON plumbing family), line bound to 25k.

Verified end-to-end against the real fork binary: __main__.outer.<locals>.inner, overloads {int,str}, declared-union on AnnAssign, call-site return types. Full uv run pytest + ruff clean.

Link to Devin session: https://app.devin.ai/sessions/1f3aec41f04d4ee1829e2ee9e7a5c9aa
Open in Devin Desktop: https://app.devin.ai/desktop/session/1f3aec41f04d4ee1829e2ee9e7a5c9aa?variant=devin
Requested by: @espetro

Probe the pyright CLI (cli= arg / PYRIGHT_BIN, default 'pyright' on
PATH) for --facts support via --help; when present, spawn one
'pyright --facts --pythonversion 3.13' subprocess per module and map
its structural type JSON onto ModuleFacts directly — per-expression
resolved types, signatures, overloads, class fields — instead of
parsing rendered hover strings. The LSP-hover path stays as the
fallback for stock upstream pyright, keeping the adapter working
against unpatched binaries.

Mapping keeps the existing contract byte-for-byte: qualnames stay
'__main__.<locals>'-shaped (pyright's flat 'mod.outer.inner' is
remapped through the Python AST), AnnAssign targets record the
denoted declared type (unwrapping type[X] the annotation position
evaluates to), and '/'/'*' separator params derive positional_only
and keyword_only.

Requires the --facts verb from sigilco/pyright#3.
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying pyscriptc with  Cloudflare Pages  Cloudflare Pages

Latest commit: ba43a5f
Status: ✅  Deploy successful!
Preview URL: https://950065d7.pyscriptc.pages.dev
Branch Preview URL: https://work-facts-cli-adapter.pyscriptc.pages.dev

View logs

@devin-ai-integration
devin-ai-integration Bot merged commit f668d88 into master Oct 18, 2026
9 checks passed
@devin-ai-integration
devin-ai-integration Bot deleted the work/facts-cli-adapter branch October 18, 2026 21:28
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