]> git.ipfire.org Git - thirdparty/fastapi/sqlmodel.git/commitdiff
👷 Run mypy by pre-commit (#1738)
authorMotov Yurii <109919500+YuriiMotov@users.noreply.github.com>
Tue, 3 Feb 2026 18:11:03 +0000 (21:11 +0300)
committerGitHub <noreply@github.com>
Tue, 3 Feb 2026 18:11:03 +0000 (19:11 +0100)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
.pre-commit-config.yaml
sqlmodel/main.py

index 41c64c030c37aaa82e7c09a6bb49e26ffb22f748..8440301ad807305328c51e1650975c651f898d61 100644 (file)
@@ -28,6 +28,13 @@ repos:
         language: unsupported
         types: [python]
 
+      - id: local-mypy
+        name: mypy check
+        entry: uv run mypy sqlmodel tests/test_select_typing.py
+        require_serial: true
+        language: unsupported
+        pass_filenames: false
+
       - id: generate-select
         language: unsupported
         name: generate-select
index b0e88fd04ec428203098ad9befd8f6cf33028a9c..bdced7ddbe37f3f53b615c107d56d59385b87942 100644 (file)
@@ -579,7 +579,9 @@ class SQLModelMetaclass(ModelMetaclass, DeclarativeMeta):
         config_kwargs = {
             key: kwargs[key] for key in kwargs.keys() & allowed_config_kwargs
         }
-        new_cls = super().__new__(cls, name, bases, dict_used, **config_kwargs)
+        new_cls = cast(
+            "SQLModel", super().__new__(cls, name, bases, dict_used, **config_kwargs)
+        )
         new_cls.__annotations__ = {
             **relationship_annotations,
             **pydantic_annotations,
@@ -607,10 +609,10 @@ class SQLModelMetaclass(ModelMetaclass, DeclarativeMeta):
             # This could be done by reading new_cls.model_config['table'] in FastAPI, but
             # that's very specific about SQLModel, so let's have another config that
             # other future tools based on Pydantic can use.
-            new_cls.model_config["read_from_attributes"] = True
+            new_cls.model_config["read_from_attributes"] = True  # type: ignore[typeddict-unknown-key]
             # For compatibility with older versions
             # TODO: remove this in the future
-            new_cls.model_config["read_with_orm_mode"] = True
+            new_cls.model_config["read_with_orm_mode"] = True  # type: ignore[typeddict-unknown-key]
 
         config_registry = get_config("registry")
         if config_registry is not Undefined:
@@ -792,7 +794,7 @@ def get_column_from_field(field: Any) -> Column:  # type: ignore
     )
     if sa_column_kwargs is not Undefined:
         kwargs.update(cast(dict[Any, Any], sa_column_kwargs))
-    return Column(sa_type, *args, **kwargs)  # type: ignore
+    return Column(sa_type, *args, **kwargs)
 
 
 class_registry = weakref.WeakValueDictionary()  # type: ignore