Skip to content

Improve SQLModel constructor hover and completion - #4538

Open
ting-hong-shieh wants to merge 1 commit into
facebook:mainfrom
ting-hong-shieh:agent/sqlmodel-constructor-signature
Open

Improve SQLModel constructor hover and completion#4538
ting-hong-shieh wants to merge 1 commit into
facebook:mainfrom
ting-hong-shieh:agent/sqlmodel-constructor-signature

Conversation

@ting-hong-shieh

Copy link
Copy Markdown
Contributor

Summary

  • prefer an overridden __init__ signature when a class inherits an unannotated catch-all __new__
  • use the same preference for constructor call traces so hover and signature surfaces agree
  • add SQLModel-shaped Pydantic regressions for hover and keyword completion

Root cause

SQLModel defines __new__(cls, *args: Any, **kwargs: Any) without a return annotation. For subclasses, Pyrefly combined that inherited catch-all with the synthesized Pydantic __init__; the broader signature then obscured the model fields in IDE surfaces even though constructor diagnostics still checked those fields correctly.

The new preference is intentionally narrow: __new__ must be inherited, unannotated, and gradual, while __init__ must be overridden. Direct construction continues to check both methods.

User impact

SQLModel subclasses now expose their synthesized Pydantic fields in hover and keyword completion instead of only args and kwargs.

Test plan

  • cargo test -p pyrefly test::lsp::hover::
  • cargo test -p pyrefly test::lsp::completion::
  • cargo test -p pyrefly constructor
  • python3 test.py --no-test --no-tensor-shapes --no-conformance --no-jsonschema

Fixes #4530

@meta-codesync

meta-codesync Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D115857124. (Because this pull request was imported automatically, there will not be any future comments.)

@ting-hong-shieh
ting-hong-shieh marked this pull request as ready for review August 13, 2026 15:34
@github-actions
github-actions Bot requested a review from grievejia August 14, 2026 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SQLModel: better tooltip/completion needed

2 participants