Repository navigation
Avoid re-using variable names in tests - #354
Merged
Merged
Conversation
One of the things `erfa_generator` does is it translates ERFA tests from C to Python. Several C tests access attributes of structs, and the corresponding Python tests use `np.recarray` views so that they too could access named attributes, which simplifies the translation. Previously this was often done by storing the output of a `pyerfa` ufunc in a variable and then assigning the output of a `.view()` method call to the same variable. Type checkers can report such re-assignments as errors if the values involved have incompatible types. In many cases it is simple to avoid the intermediate variables entirely. In the few cases where the intermediate variable cannot be (easily) avoided the type checking problems can be prevented by giving the intermediate variable a different name.
avalentino
approved these changes
Oct 9, 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.
I have annotated more
pyerfaufuncs asnp.ufuncinstances in my local repository, but the improved annotations are triggering type-checking errors inerfa/tests/test_ufunc.py. The errors are caused by code that looks likeWith the improved annotations type checkers can infer that the
astromin the first line is an array or an array scalar, but the result of theview()method is annp.recarrayinstance, which is incompatible with the inferred type of the variable. This PR solves the problem by avoiding two separate assignments toastromwhere possible, or using a different variable name for the firstastromwhere two assignments are needed.The full difference between `erfa/tests/test_ufunc.py` in current `main` and in this PR