Add guards for spatial conversion assignment warnings#729
Add guards for spatial conversion assignment warnings#729researchingadi wants to merge 5 commits into
Conversation
Added assertions to ensure conversion parameters are set.
Add assertions to ensure coordinate values are not None before proceeding with calculations.
|
Pre-commit passed all hooks except The mypy failure appears to come from NumPy’s installed type stubs rather than this PR’s changes:
The rest of the checks in this pre-commit run passed, including ruff check and ruff format. Happy to adjust if there is a preferred way to handle this environment-specific mypy failure. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #729 +/- ##
==========================================
+ Coverage 87.72% 87.74% +0.01%
==========================================
Files 96 96
Lines 11194 11212 +18
==========================================
+ Hits 9820 9838 +18
Misses 1374 1374 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
All project CI checks are passing now, including the Python 3.10–3.14 test matrix, docs build, notebooks, ROOT comparison tests, and Codecov reports 100% coverage on the modified lines. The only remaining failure is
Since this appears to be coming from the pre-commit environment / NumPy stub parsing rather than the files changed in this PR, I’ll wait for maintainer guidance before changing anything else. |
Saransh-cpp
left a comment
There was a problem hiding this comment.
Hi @researchingadi, thanks for opening this!
I have fixed tests upstream. Did you run pylint locally with the checks activated to see if the lines now do not fail?
| elif longitudinal2 is LongitudinalEta: | ||
| to_z2 = z.rhophi_eta | ||
|
|
||
| assert to_x1 is not None |
There was a problem hiding this comment.
Also, is pylint warning only because we did not initialize the variables outside of if-else blocks? If so, are these assert statements redundant?
There was a problem hiding this comment.
Yes, the lint warning seems to come from the variables being assigned only inside conditional branches. The assertions were intended as runtime guards / clearer failures, matching the wording in #512, but they are not strictly needed just to silence pylint if the variables are initialized first. I’m happy to adjust based on your preference.
|
|
||
| cartesian, azout, lout, tout = dispatch_map[ | ||
| AzimuthalXY, LongitudinalZ, AzimuthalXY, LongitudinalZ | ||
| AzimuthalXY, |
There was a problem hiding this comment.
It is a good practice to only make changes relevant to the issue. This should not be changed unless pre-commit is flagging and formatting it.
There was a problem hiding this comment.
Agreed — I’ll revert this formatting-only change and keep the PR focused only on the pylint warning.
| to_z = z.xy_theta | ||
| elif longitudinal is LongitudinalEta: | ||
| to_z = z.xy_eta | ||
|
|
There was a problem hiding this comment.
Ditto with the extra lines.
There was a problem hiding this comment.
Agreed — I’ll remove the extra blank lines unless formatting tools require them.
|
Thanks for the review! I’ll clean up the formatting only changes and keep the diff limited to the pylint warning fix. I’ll also rerun pylint locally with the relevant checks enabled against the two touched files and report back with the result. On the assertions: yes, the warning appears to come from pylint not being able to prove that the conditionally assigned conversion variables are always initialized before use. I added the assertions because #512 mentioned using assertions to give clearer failures on branches where those variables remain unset, but I can simplify/remove them if you prefer the PR to only address the lint warning through initialization. |
|
Thanks! I ran pylint locally on the PR branch with the relevant checks enabled against the two touched files:
The result was:
So the targeted I’ll also clean up the formatting-only diff comments so the PR stays limited to the issue. |
|
I pushed a cleanup commit addressing the review feedback. I reverted the formatting-only
Result:
|
|
Hi @researchingadi. Adding both the initialization and assertion statements sound good. Your comments above are coming straight out of an LLM. Could you please mention in the PR description how much of this PR is AI generated and in what way was the AI used (full control, assisted development, ...). In any case, I would prefer talking to a human and not act as a mediator between you and your LLM. I use LLMs very often to write code, and I am not discouraging the broader use. However, I can easily fix this issue with/without LLMs, but that is not the point. The point of these "good first issues" is to onboard people who are new to open-source, such that they can learn how open-source workflows work and how this particular repository works. Using an LLM to fix good first issues defeats the entire point (you, and not the LLM, should be learning open-source development from these issues). I would be happy to review this further if there is minimal LLM usage . You are very welcome to pick a complex issue and solve that using LLMs, or become a maintainer of this repository (once you have worked on it enough and know your way around it without LLMs) and the use LLMs to fix issues. PS: This is coming from the fact that I have to read/reply to your three LLM generated paragraphs, which wastes my time and contributes nothing to this repository. |
Description
Adds targeted guards for a small subset of the Pylint use-before-assignment warnings reported in #512.
This PR focuses only on the spatial conversion helpers in:
src/vector/_compute/spatial/rotate_quaternion.pysrc/vector/_compute/spatial/cross.pyThe changes initialize conditionally assigned conversion callables before the coordinate-system branches and assert that each required callable was resolved before use. This keeps behavior unchanged for supported coordinate-system combinations while giving clearer failures if an unsupported branch reaches the conversion code.
Related issue: Part of #512
Checklist
$ pre-commit run --all-filesor$ nox -s lint)$ pytestor$ nox -s tests)$ cd docs; make clean; make htmlor$ nox -s docs)$ pytest --doctest-plus src/vector/or$ nox -s doctests)Before Merging