Repository navigation
feat(typefacts): --facts CLI fast lane in PyrightFactsAdapter - #127
Merged
Merged
Conversation
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.
Contributor
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Deploying pyscriptc with
|
| Latest commit: |
ba43a5f
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://950065d7.pyscriptc.pages.dev |
| Branch Preview URL: | https://work-facts-cli-adapter.pyscriptc.pages.dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PyrightFactsAdaptergains a--factsfast lane: when the pyright CLI supports the new--factsverb (sigilco/pyright#3), the adapter spawns onepyright --facts --pythonversion 3.13subprocess per module and maps its structural type JSON ontoModuleFactsdirectly — no hover-string parsing. WhenPYRIGHT_BIN(or thecli=arg) points at stock upstream pyright, the--helpprobe finds no--factsand 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_signatureparsers silently mis-read pyright's printed type grammar (quoted forward refs,UniqueNameMaprenames, tuple forms). Facts arrive pre-structured from the evaluator:{"kind":"class","fullName":"builtins.int","typeArgs":[...]}.Contract kept identical
signature('__main__.f')keys: pyright's flatmod.outer.inneris remapped through the Python AST back to__main__.outer.<locals>.inner.AnnAssigntargets record the declared type — pyright narrowsxinx: int | None = 1toint; the lane copies the annotation node's own fact and unwraps thetype[X]layer annotations evaluate to (_facts_denoted), yielding the sameunion optional [int, none]the hover path produces.CallableFacts:/and bare*separators arrive as unnamed params →positional_only/keyword_only;defaultType.literalValuefillsdefaultsfor constant defaults.Files
typefacts.py—_facts_type/_facts_signature/_facts_qualnames/_facts_denotedmappers (~150 LOC replacing the parse for this lane),cli=/PYRIGHT_BINresolution + cached--helpcapability probe,_cli_factssubprocess lane reusing the preflight's generated-pyrightconfig (_pyright_stubsstubPath).tests/test_pyright_facts.py— hermetic fake-CLI tests (signature separators/defaults/overloads/nested names/denoted annotations, stock-pyright probe rejection), live smoke behindPYRIGHT_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. Fulluv 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