Skip to content

feat: improve type inference for related fields#2179

Open
legau wants to merge 2 commits intotortoise:developfrom
legau:develop
Open

feat: improve type inference for related fields#2179
legau wants to merge 2 commits intotortoise:developfrom
legau:develop

Conversation

@legau
Copy link
Copy Markdown

@legau legau commented Apr 13, 2026

Description

This PR improves typing for relational field factories so passing a model class preserves the concrete related model type in the returned relation.

Motivation and Context

Currently, relational field factories expose a free type variable but accepted type[Model] | str, which prevents type checkers from inferring the concrete related model when a real model class was passed.

This meant code like fields.ForeignKeyField(Field, related_name="segments") would not resolve to ForeignKeyRelation[Field].

How Has This Been Tested?

Added a type checking test file

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added the changelog accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

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