diff --git a/fastapi/encoders.py b/fastapi/encoders.py index 451ea0760..0ad548b94 100644 --- a/fastapi/encoders.py +++ b/fastapi/encoders.py @@ -241,6 +241,7 @@ def jsonable_encoder( sqlalchemy_safe=sqlalchemy_safe, ) if dataclasses.is_dataclass(obj): + assert not isinstance(obj, type) obj_dict = dataclasses.asdict(obj) return jsonable_encoder( obj_dict, diff --git a/fastapi/routing.py b/fastapi/routing.py index 54c75a027..5418ad982 100644 --- a/fastapi/routing.py +++ b/fastapi/routing.py @@ -120,6 +120,7 @@ def _prepare_response_content( for k, v in res.items() } elif dataclasses.is_dataclass(res): + assert not isinstance(res, type) return dataclasses.asdict(res) return res diff --git a/requirements-tests.txt b/requirements-tests.txt index 7c1fd12f7..e87a42162 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -2,7 +2,7 @@ -r requirements-docs-tests.txt pytest >=7.1.3,<9.0.0 coverage[toml] >= 6.5.0,< 8.0 -mypy ==1.8.0 +mypy ==1.14.1 dirty-equals ==0.9.0 sqlmodel==0.0.24 flask >=1.1.2,<4.0.0