Support typing.Self#613
Open
eb8680 wants to merge 10 commits into
Open
Conversation
datvo06
added a commit
that referenced
this pull request
May 27, 2026
Revert the ``_DistributionMethodTerm`` fallback class, the recursive ``_is_eager``, and the ``_pos_base_dist`` override. jfeser pointed out that the right fix is ``typing.Self`` resolution (#613), after which ``Normal(mu()).expand(s)`` routes through the existing concrete ``NormalTerm`` directly — no abstract-base fallback needed. Drop the workaround; come back with the principled fix once #613 lands. What remains in this PR: - The ``_DistributionTerm.expand`` return-annotation flip (``jax.Array`` → ``dist.Distribution``). Stops the result from being routed through ``_ArrayTerm``; necessary precursor to the Self-based routing. - One ``xfail(strict=True)``-marked regression test pinning the desired chain-construction behaviour. Flips to PASS once #613 + the follow-up land. Also restore ``xfail="to_event not implemented"`` on the parametrised ``Beta(...).to_event(k)`` / ``Dirichlet(...).to_event(k)`` cases — those pass through the same routing hole and need the same follow-up.
datvo06
added a commit
that referenced
this pull request
May 27, 2026
Brings in the ``typing.Self`` resolution machinery from #613 (eb-self-type) and annotates ``expand``'s ``self`` / return as ``Self`` per @jfeser's suggestion — the goal being that ``Normal(mu()).expand(s)`` routes through the concrete ``NormalTerm`` registration via ``Self → dist.Normal``. Status: not yet sufficient on its own. ``unify`` (post-#613) widens subclasses to parent classes: >>> unify(TypeVar('T'), Bar) # Bar extends Foo {T: Foo} >>> unify(TypeVar('T'), dist.Normal) {T: dist.Distribution} So even with the correct ``Self`` annotation, dispatch on the unified return type lands on ``dist.Distribution`` (no registration) and falls through to ``_CallableTerm``. The xfail regression test from the prior commit therefore still xfails. Surfacing the unify-widening behaviour for jfeser to address before this can land green.
Contributor
|
Have a question previously raised in #667 but I think worth checking again here. When we unify a type var with an inherited class, we are widening to the ancestor: Is it intended? I think by standard the principal type would be |
Contributor
Author
assert unify(T, Bar) == unify(canonicalize(T), canonicalize(Bar)) == {T: canonicalize(Bar)} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 #602