Skip to content

feat: let type checkers see model constructors - #15

Draft
chipkent wants to merge 1 commit into
masterfrom
feat/model-constructors
Draft

chipkent wants to merge 1 commit into
masterfrom
feat/model-constructors

Conversation

@chipkent

Copy link
Copy Markdown
Owner

Preview only. This is a draft in the fork showing the exact text of the PR planned for massive-com/client-python. It will be closed, not merged, once the upstream PR is opened.

Fixes #<issue: F4b>

@modelclass builds each model's __init__ at runtime, so type checkers cannot see it and reject every keyword argument:

$ mypy -c 'from massive.rest.models import LastTrade
LastTrade(ticker="AAPL", price=1.5)'
<string>:2: error: Unexpected keyword argument "ticker" for "LastTrade"  [call-arg]
<string>:2: error: Unexpected keyword argument "price" for "LastTrade"  [call-arg]

With this PR the same command prints Success: no issues found.

  • Marks 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+, from typing_extensions on 3.10. At runtime it is a no-op, so no dependency is added and 3.10 keeps working.
  • No unit test: the change is invisible at runtime, and make static does not check untyped test bodies. The mypy run above shows the effect.

@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.
@coderabbitai

coderabbitai Bot commented Oct 24, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

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.

1 participant