Extract subtyping metaclass from FunsorMeta and domains #433
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.
Addresses #351, #355.
This PR that attempts to isolate and reuse the parametric subtyping and type-caching functionality currently present in the metaclasses
FunsorMeta
,ArrayType
and #430'sProductDomain
, and to simplify their implementations. This change should enable nestedProduct
s and simplify the process of adding newProduct
/tuple
-likeDomain
s (i.e. with the same variance asProduct
).More broadly, this PR represents a minimal first attempt to bring both interpreter types and funsor types closer to the Python
typing
type system, thereby saving us work, reducing cognitive overhead for users who are familiar withtyping
, and approaching compatibility with some of the wider tooling ecosystem built aroundtyping
. It may turn out that these potential advantages are outweighed by design choices intyping
ormultipledispatch
, or that bugs, edge cases or performance limit the feasibility of this direction in practice, but it's hard to know without trying.I will also put up a different version of these changes that integrates with
typing
more directly in a separate PR.Tested: