From 182dd9d414355310b46e67f667924bcba9cc29ee Mon Sep 17 00:00:00 2001 From: Chip Kent <5250374+chipkent@users.noreply.github.com> Date: Fri, 23 Oct 2026 22:15:49 -0600 Subject: [PATCH] feat: let type checkers see model constructors @modelclass builds an __init__ that accepts every field positionally or by keyword, but type checkers could not see it: a call such as CryptoQuote(pair="BTC-USD", bid_price=1.5) was reported as "Unexpected keyword argument" for every field. Mark modelclass with dataclass_transform (PEP 681) so checkers derive the constructor from the field annotations. The decorator is imported only under TYPE_CHECKING, from typing on 3.11+ and from typing_extensions on 3.10, and is a no-op at runtime, so there is no new runtime dependency and Python 3.10 keeps working. --- massive/modelclass.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/massive/modelclass.py b/massive/modelclass.py index 117f7910..0605180a 100644 --- a/massive/modelclass.py +++ b/massive/modelclass.py @@ -1,10 +1,23 @@ import inspect +import sys import typing from dataclasses import dataclass +if typing.TYPE_CHECKING: + if sys.version_info >= (3, 11): + from typing import dataclass_transform + else: + from typing_extensions import dataclass_transform +else: + + def dataclass_transform(**kwargs): + return lambda f: f + + _T = typing.TypeVar("_T") +@dataclass_transform() def modelclass(cls: typing.Type[_T]) -> typing.Type[_T]: cls = dataclass(cls) type_hints = typing.get_type_hints(cls)