Repository navigation
Report bindings as session-stable symbol ids under includeSymbols - #38
Merged
knutwannheden merged 1 commit intoDec 4, 2026
Merged
Conversation
A new getTypes flag, includeSymbols, implies includeBindings and reports
each binding as {"symbolId": N}. The response carries a `symbols` table
describing each id (name, definedIn, qualifiedName) once per session, as
`types` does for descriptors.
An id stands for a variable: the (file, scope, place) of the definition
a reference resolves to, so every assignment to `x` in one scope shares
it. The salsa id of a Definition is per assignment and may change
between revisions. Names come from the place table, so parameters,
loop/with/except targets, walrus, comprehension and match variables
resolve too, and parameter declarations carry the id of their uses.
Without the flag, output is unchanged. The one-shot CLI gains --symbols.
knutwannheden
deleted the
ty-types-symbol-ids-for-bindings-includesymbols
branch
December 4, 2026 05:07
This was referenced Dec 4, 2026
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.
rewrite-python builds a
JavaType.Variablefor each name reference ty reports, and keeps every type it receives for the rest of a project parse. In a file of 200 lines ofvalues.append(str(i).zfill(4))that is 201 Variables for the one variablevalues. Sharing one per variable needs a key that is equal for two references to the same variable and different for two different variables.bindingcan't serve as that key:withandexcepttargets, walrus, comprehension and match variables get nobinding, becauseDefinition::nameisNonefor those kinds.qualifiedNamespells function scopes for display, so a property getter's localrand its setter's localrboth readm.C.<locals of function 'value'>.r.A symbol id per variable
The new
getTypesflagincludeSymbolsimpliesincludeBindingsand replaces each binding with an id. Thesymbolstable describes each id the first time a session sees it, astypesdoes for descriptors. Fordef f(a): return a + 1, an excerpt of the result:The id is keyed on the
(file, scope, place)of the definition the reference resolves to. Every assignment toxin one scope therefore shares an id, and same-named locals of two functions don't. The salsa id of theDefinitionwas rejected because it identifies one assignment and its docs say it can change between runs. Names come from ty's place table, which covers every definition kind. A file that resolves to no module, such asmy-script.py, keeps its ids, and itssymbolsentries leave outdefinedInandqualifiedName.The ruff fork needs no change.
Definition::file_scopeandDefinition::placeare already public inty_python_core.Compatibility and payload
The flag defaults off, and an older build ignores it.
symbolsis present, possibly as{}, exactly when the flag is honored, so a client can tell whether the build supports it. Over the 71 files of abseil-py, output with no flag and withincludeBindingsparses equal tomainon every response.includeSymbolsreports 75% more bindings for slightly less payload:includeBindingsincludeSymbolsTests
The new integration tests cover these cases:
x = xreads the module'sxand binds the class'sglobalandnonlocalnames get the owning scope's id--bindings --symbolscombination reports symbol idsNot changed here
self.xassigned only in a method has no binding. Where the class body bindsx,self.xcarries the class variable's id.qualifiedNamekeeps the display helper's spelling. A type parameterTofdef f[T]readsm.T. Clients key a variable by its id.getTypeRegistrydoesn't return symbols.