Prefix remaining template variables that can clash with user-defined names (Optional follow-up to #1908) #1910
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.42 · 343 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.349
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1910"
general
weight: 0.35
mstimberg
Follow-up to #1908, as offered in #1906: I went through the other code generation templates and looked for local variables without a leading underscore in templates that contain user code. Three more clash with user-defined names:
| Template | Name | What happened |
|---|---|---|
| Cython
synapses_create_generator.pyx|newsize,oldsize|connect(condition="j < newsize")withnewsizein the namespace failed to compile and silently created 0 synapses (#1898) || C++
synapses_create_generator.cpp|newsize| Same expression: compile errorredefinition of 'newsize' with a different type|| Cython
summed_variable.pyx|vectorisation_idx| The template assignedvectorisation_idx = _idx, while every other Cython template uses_vectorisation_idx = _idx. A constant calledvectorisation_idxin a summed variable was overwritten ([10.]instead of[20.]in the example below), and_vectorisation_idxstayed at1inside the loop |This PR renames them to
_newsize,_oldsizeand_vectorisation_idx. The remaining unprefixed names are either in helper functions or support code that never contains user code (e.g.data_ptrin_flush_buffer,objects.cpp,network.cpp), or in templates without user expressions (synapses_push_spikes.pyx,synapses_create_array.cpp), so I left them alone to keep this focused. Happy to prefix those too for consistency if you prefer.Test
New
test_connect_and_summed_names_of_template_variablesintest_synapses.py, next to the test from #1908 (standalone compatible):connect(condition="j < newsize"),connect(j="k for k in range(oldsize)"), and a summed variablex_pre * vectorisation_idx, with those names in the namespace.On macOS (arm64, Apple clang 21.0.0, Python 3.13.15, Cython 3.3.0, numpy 2.5.4):
numpy; fails oncython(assert 0 == 10) and oncpp_standalone(redefinition of 'newsize').numpy,cythonandcpp_standalone.synapse or summed or connect or subgroup(including long tests) onnumpy,cythonandcpp_standalone: all passed (numpy 118, cython 116 + 2 skipped, cpp_standalone 91 + 4 standalone-specific).ruff format --check(v0.14.2) reports no changes.Before (on
master) and after (this branch), runningconnect(condition="j < newsize"),connect(j="k for k in range(oldsize)")and the summed variable from the test:<img width="1702" height="602" alt="image" src="https://github.com/user-attachments/assets/619b9116-6b39-4878-94d3-c9a283450f73" />
after:
<img width="1684" height="358" alt="image" src="https://github.com/user-attachments/assets/d87a8b83-ee0f-4b1c-a3a0-c299e7231c9c" />