Skip to content

fix(quick_construct): preserve histogram subclass type through construction#701

Draft
henryiii wants to merge 1 commit into
mainfrom
fix-quick-construct-typing
Draft

fix(quick_construct): preserve histogram subclass type through construction#701
henryiii wants to merge 1 commit into
mainfrom
fix-quick-construct-typing

Conversation

@henryiii

Copy link
Copy Markdown
Member

🤖 AI text below 🤖

Closes #675.

The quick-construct storage finalizers were annotated -> BaseHist, so hist.Hist.new.Reg(...).Weight() was statically typed as BaseHist and users had to cast. QuickConstruct/ConstructProxy are now generic over H = TypeVar(bound=BaseHist), captured from the originating class in MetaConstructor.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 TypeVar the 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_type on a snippet now reports Hist/NamedHist/user-subclass (was BaseHist[...]); prek -a (strict mypy on src/) is clean. No permanent typing-test was added — the repo has no typing-test harness.

…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
henryiii force-pushed the fix-quick-construct-typing branch from f7bfdd4 to 0d1576a Compare June 25, 2026 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] How are we supposed to use type annotations with this project?

1 participant