Skip to content

Annotate DataArray shape, set_arrays, array_id and action_indices - #244

Open
jenshnielsen wants to merge 2 commits into
QCoDeS:mainfrom
jenshnielsen:fix_type_checking
Open

Annotate DataArray shape, set_arrays, array_id and action_indices#244
jenshnielsen wants to merge 2 commits into
QCoDeS:mainfrom
jenshnielsen:fix_type_checking

Conversation

@jenshnielsen

Copy link
Copy Markdown
Contributor

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant