fix(quick_construct): preserve histogram subclass type through construction#701
Draft
henryiii wants to merge 1 commit into
Draft
fix(quick_construct): preserve histogram subclass type through construction#701henryiii wants to merge 1 commit into
henryiii wants to merge 1 commit into
Conversation
…uction Make QuickConstruct/ConstructProxy generic over the originating class so Hist.new...Weight() is typed as Hist rather than BaseHist. Typing-only; runtime behavior is unchanged. Closes #675. Assisted-by: ClaudeCode:claude-opus-4.8
henryiii
force-pushed
the
fix-quick-construct-typing
branch
from
June 25, 2026 20:22
f7bfdd4 to
0d1576a
Compare
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.
🤖 AI text below 🤖
Closes #675.
The quick-construct storage finalizers were annotated
-> BaseHist, sohist.Hist.new.Reg(...).Weight()was statically typed asBaseHistand users had to cast.QuickConstruct/ConstructProxyare now generic overH = TypeVar(bound=BaseHist), captured from the originating class inMetaConstructor.new, so the finalizers return the real subclass (Hist,NamedHist, or a user subclass).This is typing-only — runtime behavior is unchanged (verified the constructed class is identical).
Tradeoff: with a single class-carrying
TypeVarthe return preserves the subclass but the storage parameter becomes free (Hist[S]); keeping both subclass identity and the concrete storage would need higher-kinded types. The issue asks for the subclass, so that is what's preserved.Verification:
mypy reveal_typeon a snippet now reportsHist/NamedHist/user-subclass (wasBaseHist[...]);prek -a(strict mypy onsrc/) is clean. No permanent typing-test was added — the repo has no typing-test harness.