Skip to content

Conversation

@michal-lightly
Copy link
Contributor

@michal-lightly michal-lightly commented Dec 23, 2025

What has changed and why?

Motivation: Propagate types in schema.d.ts.

After a session with AI, I stumbled upon a solution that satisfies all three:

  • avoid circular imports
  • satisfy mypy
  • include types in schema generation

It is possible to add imports to the bottom of the file and avoid if TYPE_CHECKING clauses. This works because:

  • imports are deferred (no circular issue)
  • mypy does not mind if declarations are later
  • no if clause, thus types are propagated
  • SQLModel/SQLAlchemy model discovery is magic that does not need the imports seemingly at all

It turns out we can likely remove all if TYPE_CHECKING clauses. This PR does it for all files except annotations (todo later).

Two other changes were needed:

  • DB model is loaded before everything else. Added an import to __init__.py
  • SampleTable is the first one imported

How has it been tested?

CI

Did you update CHANGELOG.md?

  • Yes
  • Not needed (internal change)

@michal-lightly michal-lightly changed the title Remove if TYPE_CHECKING clause from model files Remove if TYPE_CHECKING clause from most model files Dec 23, 2025
@michal-lightly michal-lightly marked this pull request as ready for review December 23, 2025 16:56
@michal-lightly
Copy link
Contributor Author

/review

Copy link
Contributor

@horatiualmasan horatiualmasan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.

3 participants