Annotate DataArray shape, set_arrays, array_id and action_indices - #244
Open
jenshnielsen wants to merge 2 commits into
Open
Annotate DataArray shape, set_arrays, array_id and action_indices#244jenshnielsen wants to merge 2 commits into
jenshnielsen wants to merge 2 commits into
Conversation
These are assigned from unannotated arguments whose defaults are an empty tuple or None, so type checkers inferred the narrowest type that fits the default, such as tuple[()] for set_arrays. Indexing them was therefore an error for consumers. nest is annotated too since it also assigns set_arrays and action_indices, and checkers take the union of every assignment site. shape is declared at its assignment because it is additionally assigned in init_data. Also add an explicit __iter__. Like __len__ it has to be delegated by hand because iter() looks the attribute up on the type rather than going through DelegateAttributes. Iteration already worked via the legacy __getitem__ protocol but the array was not recognised as iterable.
Iteration was only covered incidentally, by two formatter tests that happen to zip over data arrays in the test body itself. Nothing in qcodes_loop iterates a DataArray, so the only production consumers are downstream, which makes that coverage easy to lose. Assert the semantics directly: 1D yields values, 2D yields rows, and iteration agrees with indexing and length.
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.
These are assigned from unannotated arguments whose defaults are an empty tuple or None, so type checkers inferred the narrowest type that fits the default, such as tuple[()] for set_arrays. Indexing them was therefore an error for consumers. nest is annotated too since it also assigns set_arrays and action_indices, and checkers take the union of every assignment site. shape is declared at its assignment because it is additionally assigned in init_data.
Also add an explicit iter. Like len it has to be delegated by hand because iter() looks the attribute up on the type rather than going through DelegateAttributes. Iteration already worked via the legacy getitem protocol but the array was not recognised as iterable.