From 075cbcf1c6ce7d9b77ab45b39794a53689764f74 Mon Sep 17 00:00:00 2001 From: Julian Vanden Broeck Date: Wed, 30 Jul 2025 15:57:07 +0200 Subject: [PATCH] Match return type of SerializationInfo.mode() to mode of model_dump() Pydantic sometimes uses Literal['python', 'json'] | str for the serialization mode. Using a more restrictive type can cause issues (e.g., typing validation errors). This commit adjusts the return type to align with other valid Pydantic serialization modes and prevent such issues. This can be seen as a follow-up to commit: 9b239c174b316de092a9692d67723427ee0c24f7 --- python/pydantic_core/core_schema.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/pydantic_core/core_schema.py b/python/pydantic_core/core_schema.py index d03dded87..957ec85da 100644 --- a/python/pydantic_core/core_schema.py +++ b/python/pydantic_core/core_schema.py @@ -145,7 +145,7 @@ def context(self) -> ContextT: ... @property - def mode(self) -> Literal['python', 'json']: + def mode(self) -> Literal['python', 'json'] | str: """The serialization mode set during serialization.""" ...