SoquetT becomes a protocol #1721
Open
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.
Switches the
SoquetT
union type alias to atyping.Protocol
. This supports "duck typing", which is appropriate for the situation whereSoquetT
is used as a type annotation.Specifically,
SoquetT
is now anything that has.shape
and.item(*args)
. With the addition of these properties/methods to theSoquet
class, now this is satisfied bySoquet
andNDArray
. Note: we can't use mypy to annotate things withNDArray[Soquet]
now or before due to limitations in numpy.When users or developers need to dispatch depending on whether a
SoquetT
is a single soquet or an array thereof, they should use the newBloqBuilder
methods. The example from the new docstring:In the protocol implementations and bloq standard library, this PR:
Soquet
_infra/
and protocols modules. Following this, pytest passes but there are mypy issues in thebloqs/
standard librarybloqs/
standard library.uses new alias(removed from this PR)soq.dtype
instead ofsoq.reg.dtype
.Regarding #1720: this PR shows the changes to the standard library that would be required to avoid
isinstance(x, Soquet)
checks