Make it possible to set parameters as attribues and document these using a parser #3188
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.
This is an alternative suggestion to #3098. Since #32 was solved by #3125 I consider that out of scope for both these prs.
This enables parameters to be expressed as attributes on the instrument directly without having to call add_parameter. This has the advantage that the code exactly matches what one would expect a parameter to be namely an attribute on the instrument.
Sphinx automatically documents attributes if they have a docstring enabling this to fix #1151 However the documentation for instance attributes is less than ideal by default. This therefor also includes a very early proof of concept sphinx extension that instantiates parameter attributes when calling getattr on an instrument. It does this by parsing the code and extracting any argument that contains self (since the instrument class cannot be instantiated) and then instantiating the parameter without these.
The attributes are documented via their
__repr__
which has been overwritten here to prove the concept.This parser would need significant further work. One could either do
Compared to the old way of add_parameter this has a few disadvantages.
I do however feel that the added clarity of the code more that out ways these issues.
Note that some tests fail due to the change in repr.
If we go down this route we should probably do the same for qcodes functions and submodules eventually.