You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Give PyPy the same citry check answers: replace symtable with an ast pass #434
Two analyses ask Python's symtable module which names a function binds locally:
_renamable_method_locals in packages/py/citry/citry/_template_python.py. The editor and citry check --types use it so that a template name such as a c-for loop variable never takes the declared type of a template_data() local with the same name.
_function_local_names in packages/py/citry/citry/_checker.py. citry check uses it to know which js_data() names hide a module value before it reads that value.
PyPy ships symtable.py but not the _symtable C module it imports. On PyPy both analyses therefore return no answer:
The editor and citry check --types give no types to a template that uses a name its template_data() method assigns, imports, defines or takes as a parameter. A template that shares no such name gets the same answer as on CPython. On this repository's own components this skips about a third of the templates whose template_data() returns a dict literal, because items = ...; return {"items": items} is common.
citry check reads no module values for js_data(), so it reports fewer js_data findings, including the early warning for a Path or Secret sent to the browser.
Neither analysis affects rendering, caching or a runtime safety decision; the runtime still refuses a Secret in js_data. citry check and the editor print a notice on such an interpreter.
Proposal
Compute the same local-name sets with an ast pass that works on every interpreter. A name counts as local when the function binds it: parameters, assignment and augmented-assignment targets, for and with targets, except ... as, imports, match captures, walrus targets, and nested def and class names. Names declared global or nonlocal do not count. Then use the ast pass everywhere, or only when symtable is missing.
Two cases need care to match symtable:
comprehension scopes, which differ between 3.11 and 3.12;
names that nested functions and classes read or bind.
Done when
A test compares the ast pass against symtable over the existing test sources on CPython and finds no difference.
The notice for interpreters without _symtable is gone.
Activity