providers/backend: define Backend type as union of versioned types#10043
providers/backend: define Backend type as union of versioned types#10043airwoodix wants to merge 1 commit into
Conversation
|
Thank you for opening a new pull request. Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone. One or more of the the following people are requested to review this:
|
aa65c19 to
3e95130
Compare
mtreinish
left a comment
There was a problem hiding this comment.
Sorry for taking so long to look at this, it fell through the cracks in my review queue. While I really like this change and think this is a much better interface which uses more modern Python conventions than what I came up with back in #5086 I think the biggest issue here is going to be backwards compatibility. The hard class for better or worse is part of the existing API and things are relying on the current structure (both in qiskit which you fixed most of and also in downstream code that does things like isinstance(obj, Backend) and also obj.version. I expect this was the cause of the CI failures because the tests were catching the API change here.
I'm not sure if there is a path to bridge the two styles. Normally I'd propose deprecating the hard class usage, but that's also going to be tricky to catch to raise a deprecation warning with the way the class is used. Maybe something like defining the union type alias as BackendType or something like so that it can be used in a typing scenario and keep the hard class in place as is?
|
Thanks for the review and apologies for the delayed feedback. As you point out, the proposed change is much more invasive than I initially anticipated while having less practical relevance than I thought. Since the main advantages would come up only with much wider typing coverage than |
Summary
This patch is a proposal for redefining the
qiskit.providers.Backendtype as a union of the versioned types instead of as an empty base class.The empty base class is unfortunately not very useful in a typed context because having an instance of the
Backendtype doesn't allow calling any methods / accessing any attributes other thanversionon it.With the proposed approach, a pre-processor could be defined:
such that functions consuming backends can access backend attributes in a typesafe manner:
Since both variants of the new
Backendtype have aversionattribute, the proposed modification is fully backwards compatible. Manualy narrowing using theversionattribute is still supported (see below).Details and comments