]> git.ipfire.org Git - thirdparty/fastapi/sqlmodel.git/commitdiff
🐛 Fix type annotation in `SQLModel.__new__`, avoid explicitly returning `Any` (#1846)
authorCarl Meyer <carl@oddbird.net>
Thu, 2 Apr 2026 20:58:24 +0000 (13:58 -0700)
committerGitHub <noreply@github.com>
Thu, 2 Apr 2026 20:58:24 +0000 (22:58 +0200)
sqlmodel/main.py

index 300031de8bd2783f5eeb7b33a2d5b77e755fc06e..17d64e8ffbf985d02d071767967ed5a8e1f50a6b 100644 (file)
@@ -814,7 +814,9 @@ class SQLModel(BaseModel, metaclass=SQLModelMetaclass, registry=default_registry
     __allow_unmapped__ = True  # https://docs.sqlalchemy.org/en/20/changelog/migration_20.html#migration-20-step-six
     model_config = SQLModelConfig(from_attributes=True)
 
-    def __new__(cls, *args: Any, **kwargs: Any) -> Any:
+    # Typing spec says `__new__` returning `Any` overrides normal constructor
+    # behavior, but a missing annotation does not:
+    def __new__(cls, *args: Any, **kwargs: Any):  # type: ignore[no-untyped-def]
         new_object = super().__new__(cls)
         # SQLAlchemy doesn't call __init__ on the base class when querying from DB
         # Ref: https://docs.sqlalchemy.org/en/14/orm/constructors.html